使用PHP自帶的mail()
函數不是最佳解決方案。使用swiftmailer作爲SMTP服務時的代碼
例:使用SWIFTMAILER http://swiftmailer.org/這將作爲SMTP服務使用
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
->setUsername('your username')
->setPassword('your password')
;
/*
You could alternatively use a different transport such as Sendmail or Mail:
// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
// Mail
$transport = Swift_MailTransport::newInstance();
*/
// 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
$result = $mailer->send($message);
不使用電子郵件()爲羣發郵件,即使是這樣說的郵件頁面上。 **「值得注意的是,mail()函數並不適用於循環中的大量電子郵件,該函數打開並關閉每個電子郵件的SMTP套接字,效率不高。** – 2013-03-08 02:50:20
郵件不太可能是被主機排隊等候的可能性更大,只有主持人可以證實這一點,特別是如果你不知道你在做什麼,請特別注意發送大量電子郵件,特別是在共享主機上。 – 2013-03-08 02:51:51
郵件功能只有在接受郵件發送時纔會返回true,但是它不知道發生了什麼後會發生什麼,就像文檔狀態一樣,「重要的是要注意,僅僅因爲郵件被接受發送,它並不意味着郵件將實際到達預定目的地。「 – j08691 2013-03-08 02:52:00