2009-10-28 8 views
5

Şu anda SwiftMailer numaralı telefonu kullanıyorum, birden fazla kullanıcıya e-posta göndermek için (50 taneye kadar). Kurduğum ve düzgün çalıştığım halde, alıcıları MySQL veritabanımdan nasıl çekeceğimi ve bunları göndermeyi nasıl yapacağımı tam olarak bilmiyorum.Batch e-posta gönder SwiftMailer ile e-posta gönder

<?php 
require_once 'swift/lib/swift_required.php'; 
$mailer = Swift_Mailer::newInstance(
Swift_SmtpTransport::newInstance('smtp.connection.com', 25) 
->setUsername('myUserName') 
->setPassword('myPassword') 
); 

$mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(9)); 

$message = Swift_Message::newInstance() 

    ->setSubject('Let\'s get together today.') 

    ->setFrom(array('[email protected]' => 'From Me')) 

    ->setTo(array('[email protected]' => 'Tom Jones', '[email protected]' => 'Jane Smith', '[email protected]' => 'John Doe', '[email protected]' => 'Bill Watson',)) 

    ->setBody('Here is the message itself') 
    ->addPart('<b>Test message being sent!!</b>', 'text/html') 
    ; 

    $numSent = $mailer->batchSend($message, $failures); 

    printf("Sent %d messages\n", $numSent); 

, yukarıdaki görebilirsiniz setto içinde, ben veritabanında kullanıcılarımdan yineleme istiyorum gibi: İşte

Şu anda ne var. Bir şey gibi:

SELECT first, last, email FROM users WHERE is_active=1

documentation devletler:

Note: Multiple calls to setTo() will not add new recipients – each call overrides the previous calls. If you want to iteratively add recipients, use the addTo() method.

Ama emin değilim: 1: Bu nasıl komut benim datebase seçim ve alıcı: 2 : Durumumda addTo() yöntemini kullanmam gerekirse. Bunu nasıl ayarlayacağınıza dair herhangi bir öneriniz var mı?

Teşekkürler!

<?php 
$message = Swift_Message::newInstance() 
    ->setSubject('Let\'s get together today.') 
    ->setFrom(array('[email protected]' => 'From Me')) 
    ->setBody('Here is the message itself') 
    ->addPart('<b>Test message being sent!!</b>', 'text/html') 
; 

$data = mysql_query('SELECT first, last, email FROM users WHERE is_active=1') or die(mysql_error()); 
while($row = mysql_fetch_assoc($data)) 
{ 
    $message->addTo($row['email'], $row['first'] . ' ' . $row['last']); 
} 

$message->batchSend(); 
?> 

Ben sen öyle istiyorsun umut: Ben burada doğru soru var, ama oldukça emin değilim

cevap

6

bunu yapmanın bir yoludur.

+1

batchSend, SwiftMailer uygulamasının son sürümünde kaldırılmıştır. E-posta gruplarını göndermek için mevcut belgeler için http://swiftmailer.org/docs/sending.html#sending-emails-in-batch adresine bakın. – DrCord