2009-10-28 15 views
5

के साथ ईमेल भेजें मैं वर्तमान में SwiftMailer का उपयोग कर रहा हूं ताकि कई उपयोगकर्ताओं को ईमेल भेज सकें (50 तक)। मैंने इसे स्थापित किया है और ठीक से काम कर रहा है, हालांकि, मुझे पूरा यकीन नहीं है कि प्राप्तकर्ताओं को मेरे MySQL डेटाबेस से कैसे खींचें और उन्हें भेजने के लिए पुन: प्रयास करें।बैच स्विफ्टमेलर

<?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); 

आप ऊपर देख सकते हैं, setTo में, मैं डेटाबेस में मेरी उन से पुनरावृति करना चाहते हैं:

यहाँ मैं वर्तमान में क्या है। कुछ की तरह:

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

documentation कहता है:

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.

लेकिन, मुझे यकीन नहीं है: 1: कैसे इस स्क्रिप्ट में मेरे datebase से चयन करें और करने के लिए: 2 : अगर मुझे अपने मामले में addTo() विधि का उपयोग करने की आवश्यकता होगी। इसे ठीक से कैसे सेट करें इस पर कोई सुझाव?

धन्यवाद!

<?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(); 
?> 

मुझे आशा है कि आप क्या चाहते है:

उत्तर

6

मैं काफी यकीन है कि मैं आपके सवाल का अधिकार मिल गया है, लेकिन यहां नहीं कर रहा हूँ यह करने का एक तरीका है।

+1

बैचसेन्ड स्विफ्टमेलर के नवीनतम संस्करण में हटा दिया गया है। ईमेल के बैच भेजने के लिए वर्तमान दस्तावेज़ के लिए http://swiftmailer.org/docs/sending.html#sending-emails-in-batch देखें। – DrCord