我不完全理解这一切是如何工作的,但我收到了这个错误:
致命错误:第 213 行 /Users/andrew/Sites/myApp/library/Zend/Mail/Transport/Smtp.php 中允许的 8388608 字节内存大小已用尽(试图分配 261858 字节)
我在运行 MAMP 的 Mac 上本地运行此代码。不确定这是否与它有关。这是我的代码,基本上:
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'username', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
foreach ($subscribers as $subscriber) {
$message = new Zend_Mail('utf-8');
$message->setFrom('my@mailinglist.com', 'Mailing List')
->addTo($subscriber->email)
->setSubject($subject)
->setBodyText($body);
$attachment = $message->createAttachment(file_get_contents($filepath));
$attachment->type = 'application/pdf';
$attachment->filename = $filename;
$message->send($smtpConnection);
}
但是,订阅者越多,这个数字就越高,这个修复只能帮助这么久:
ini_set("memory_limit","12M");
我需要弄清楚如何向数百人发送带有附件的电子邮件。这是我想出的其他东西,但只设置密件抄送而不是收件人地址似乎有点笨拙:
$message = new Zend_Mail('utf-8');
$message->setFrom('my@mailinglist.com', 'Mailing list')
->setSubject($subject)
->setBodyText($body);
$attachment = $message->createAttachment(file_get_contents($filepath));
$attachment->type = 'application/pdf';
$attachment->filename = $filename;
foreach ($subscribers as $subscriber) {
$message->addBcc($subscriber->email);
}
$message->send($smtpConnection);
但是,即使这样做,我也需要指定“memory_limit”。你能指出我正确的方向吗?有什么我没有做的吗?