通讯表:
id | email | unsubscribe_link
$emails = NewsletterTable::getInstance()->findAll();
$count = count($emails);
$message = $this->getMailer()->compose();
$message->setSubject($params['subject']);
$message->setTo($params['to']));
$message->setFrom($params['from']);
for($i=1;$i<$count;$i++){
$message->addBcc($emails[$i]->email);
}
$html = $this->getPartial('mymodule/myTemplateHtml',$params);
$message->setBody($html, 'text/html');
$text = $this->getPartial('mymodule/myTemplateTxt',$params);
$message->addPart($text, 'text/plain');
$this->getMailer()->send($message);
我必须添加的内容还发送unsubscribe_link(唯一)吗?有可能吗?
答案 0 :(得分:0)
我相信你正在使用Doctrine。我不是如何用学说来做这个的专家,但是就像黑客一样,你可以做到这一点:
$emails = NewsletterTable::getInstance()->findAll();
$count = count($emails);
$message = $this->getMailer()->compose();
$message->setSubject($params['subject']);
$message->setTo($params['to']));
$message->setFrom($params['from']);
$bccEmails = array();
for($i=1;$i<$count;$i++){
$bccEmails[$emails[$i]] = true;
}
foreach ($bccEmails as $emailAddr => $dummy) {
$message->addBcc($emailAddr);
}
这里的想法是创建一个电子邮件地址字典,并且重复不会影响它,因为字典不能有重复的条目。然后,循环遍历字典的键并添加它们。