Note that there are some explanatory texts on larger screens.

plurals
  1. POZend Framework: Fatal error when trying to use Zend Mail Transport to send multiple emails with attachments
    primarykey
    data
    text
    <p>I don't totally understand how all this works, but I'm getting this error:</p> <p>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</p> <p>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:</p> <pre><code>$config = array('ssl' =&gt; 'tls', 'port' =&gt; 587, 'auth' =&gt; 'login', 'username' =&gt; 'username', 'password' =&gt; 'password'); $smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config); foreach ($subscribers as $subscriber) { $message = new Zend_Mail('utf-8'); $message-&gt;setFrom('my@mailinglist.com', 'Mailing List') -&gt;addTo($subscriber-&gt;email) -&gt;setSubject($subject) -&gt;setBodyText($body); $attachment = $message-&gt;createAttachment(file_get_contents($filepath)); $attachment-&gt;type = 'application/pdf'; $attachment-&gt;filename = $filename; $message-&gt;send($smtpConnection); } </code></pre> <p>However, the more subscribers there are, the higher this number ends up getting, and this fix will only help for so long:</p> <pre><code>ini_set("memory_limit","12M"); </code></pre> <p>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:</p> <pre><code>$message = new Zend_Mail('utf-8'); $message-&gt;setFrom('my@mailinglist.com', 'Mailing list') -&gt;setSubject($subject) -&gt;setBodyText($body); $attachment = $message-&gt;createAttachment(file_get_contents($filepath)); $attachment-&gt;type = 'application/pdf'; $attachment-&gt;filename = $filename; foreach ($subscribers as $subscriber) { $message-&gt;addBcc($subscriber-&gt;email); } $message-&gt;send($smtpConnection); </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload