2010-01-07 19 views
0

我需要能够发送电子邮件到存储在数据库(其通讯不是垃圾邮件:P) 联系人。我可以使用mail()和循环来做到这一点,但 我读过这不是一个好主意,因为可能有几百个联系人。使用邮件()在php中的多个联系人

什么是最好的方式去做这件事?任何意见或指针在 正确的方向将不胜感激!

谢谢。

回答

1

邮件()将非常缓慢,有数百个联系人。我建议swiftmailer在http://www.swiftmailer.org。下面是从thier网站发送邮件很多的例子:

require_once 'lib/swift_required.php'; 

//Create the Transport 
$transport = Swift_SmtpTransport::newInstance('localhost', 25); 

//Create the Mailer using your created Transport 
$mailer = Swift_Mailer::newInstance($transport); 

//Create a message 
$message = Swift_Message::newInstance('Wonderful Subject') 
    ->setFrom(array('[email protected]' => 'John Doe')) 
    ->setTo(array('[email protected]', '[email protected]' => 'A name')) 
    ->setBody('Here is the message itself') 
    ; 

//Send the message 
$numSent = $mailer->batchSend($message); 

而且你可以用你的SMTP连接/帐号发送,或者邮件发送。

相关问题