Issues

ZF-30: add a clearRecipients() method to the Zend_Mail (TRAC#14)

Issue Type: Improvement Created: 2006-06-19T22:55:35.000+0000 Last Updated: 2007-07-05T14:43:06.000+0000 Status: Resolved Fix version(s): Reporter: Zend Framework (zend_framework) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Mail

Related issues: Attachments:

Description

The second suggestion is to add a clearRecipients() method to the Zend_Mail class to optimize the process when sending the same email to several receipients.

My criteria are : no use of the BCC, and I do not want users to see which other users has received the email.

Here is how I do it right now :

<pre class="highlight">
require_once('Zend/Mail.php');
require_once 'Zend/Mail/Transport/Smtp.php';                                                   
       
$tr = new Zend_Mail_Transport_Smtp('myMailServer');
$tr->connect();
       
foreach ($emails as $value) {
    $mail = new Zend_Mail();
    $mail->setFrom($from);
    $mail->setBodyText($message);
    $mail->setSubject('this is a test');                   
    $mail->addTo($value);
    $mail->send();
}
       
$tr->disconnect();

Here is my suggestion :

<pre class="highlight">
require_once('Zend/Mail.php');
require_once 'Zend/Mail/Transport/Smtp.php';                                                   
       
$tr = new Zend_Mail_Transport_Smtp('myMailServer');
$tr->connect();
$mail = new Zend_Mail();
$mail->setFrom($from);
$mail->setBodyText($message);
$mail->setSubject('this is a test');
       
foreach ($emails as $value) {
    $mail->clearRecipients();                      
    $mail->addTo($value);
    $mail->send();
}

$tr->disconnect();

Comments

Posted by Zend Framework (zend_framework) on 2006-06-19T22:55:50.000+0000

Another feature creep likely to be requested: mail merge

Mail merge usually involves similar activities found in template instantiation, except for email the instantiation may be once per email in a list, instead of once per page view for templates used to produce web pages. Consider a common, but simple case, where the beginning of an email includes a greeting with the recipient's name, but the remainder of the email remains identical.

Posted by Matthew Weier O'Phinney (matthew) on 2006-07-07T21:46:29.000+0000

We have discussed this request internally, and decided not to add the feature at this time in anticipation of a proper mail merge/queue module in a future release.

In the meantime, a very easy workaround exists for doing this. First, create the mail object with all information except the recipients list:

$mail = new Zend_Mail(); $mail->setFrom('matthew@zend.com, "Matthew Weier O'Phinney"); $mail->setBodyText('This is the message body');

Then, loop over your recipients, clone the mail object, add recipients to the clone, and send:

foreach ($recpients as $to) { $copy = clone $mail; $copy->addTo($to); $copy->send(); unset($copy); }

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts