这不是向两个收件人发送相同的电子邮件,而是两个带有一个或两个共同元素的不同电子邮件。我已经完成了各种操作,但无论我尝试过什么,只发送了第一封电子邮件。这是代码:
// cancellation confirmation emails
// common subject for both emails
$subject= "Dinner Reservation CANCELLATION";
require_once '../vendor/swiftmailer/swiftmailer/lib/swift_required.php';
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
// email to president
$body = "<br>" . $mbr_name . " has cancelled their dinner reservation for the " . $meeting_date . " meeting.<br>They held a reservation for " . $attending . ".";
$message = Swift_Message::newInstance($subject)
->setTo(array($pres_email => $pres_name))
->setFrom(array('noreply@some.org' => 'Cancellation'))
->setBcc('webmaster@some.org')
->setBody($body, 'text/html');
$result = $mailer->send($message);
// email to member
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$body = "<br>This is to confirm the dinner reservation for member " . $mbr_name . " has been CANCELLED for the " . $meeting_date . " meeting.<br><br>To make a new reservation log in to www.some.org and proceed as usual.";
$message = Swift_Message::newInstance($subject . " confirmation." )
->setTo(array($mbr_email => $mbr_name))
->setFrom(array('noreply@some.org' => 'Some Org Dinner Cancellation'))
->setBody($body, 'text/html');
$result = $mailer->send($message);
答案 0 :(得分:0)
也许尝试这样的事情......
$info = array(
'message_president' => "<br>" . $mbr_name . " has cancelled their dinner reservation for the " . $meeting_date . " meeting.<br>They held a reservation for " . $attending . ".",
'message_member' => "<br>This is to confirm the dinner reservation for member " . $mbr_name . " has been CANCELLED for the " . $meeting_date . " meeting.<br><br>To make a new reservation log in to www.some.org and proceed as usual."
);
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
//Create the message for the President
$message = Swift_Message::newInstance()
->setSubject("Dinner Reservation CANCELLATION")
->setTo(array($pres_email => $pres_name))
->setFrom(array('noreply@some.org' => 'Cancellation'))
->setBcc('webmaster@some.org')
->setBody($info['message_president'],'text/html');
if ($mailer->send($message1){
$message1_result = true;
}
//Create the message for the Member
$message2 = Swift_Message::newInstance()
->setSubject("Dinner Reservation CANCELLATION")
->setTo(array($mbr_email => $mbr_name))
->setFrom(array('noreply@some.org' => 'Some Org Dinner Cancellation'))
->setBody($info['message_member'],'text/html');
if ($mailer->send($message2){
$message2_result = true;
}
<强> ADDED 强>
您可能还想通过swiftmailer
查看装饰器插件http://swiftmailer.org/docs/plugins.html#decorator-plugin
第二次添加
我读到你可能会在定义传输的多封电子邮件方面取得更大的成功,虽然我对此一无所知......但这里有两个例子,第二个将一致的结果设置为使用smpt。
$transport = Swift_MailTransport::newInstance('/usr/sbin/sendmail -bs');
$transport = Swift_SmtpTransport::newInstance('smpt.server.tld', 25);