I don't totally understand how all this works, but I'm getting this error:
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 261858 bytes) in /Users/andrew/Sites/myApp/library/Zend/Mail/Transport/Smtp.php on line 213
I'm running this code locally on my Mac running MAMP. Not sure if that has anything to do with it. This is my code, basically:
$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('[email protected]', '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);
}
However, the more subscribers there are, the higher this number ends up getting, and this fix will only help for so long:
ini_set("memory_limit","12M");
I need to figure out how to send an email with an attachment to a couple hundred people. Here's something else I've come up with but it seems a little hacky to only set the bcc and not the to address:
$message = new Zend_Mail('utf-8');
$message->setFrom('[email protected]', '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);
However, even doing this, I need to specify the "memory_limit". Can you please point me in the right direction with this? Is there something I'm not doing?