我试图通过nette邮件程序向选定的用户发送电子邮件,但总的来说只有InvalidStateException
。
public function contactsEditorFormSucceeded($form, $values)
{
try {
$recipients = $values->recipients;
$mail = new Message;
$mail->setFrom($values->email)
->setSubject($values->subject)
->setBody($values->message);
foreach ($recipients as $recipient) {
$mail->addTo($recipient);
}
$mailer = new SendmailMailer;
$mailer->send($mail);
$this->flashMessage('Done.', self::MSG_SUCCESS);
$this->redirect('this');
} catch (InvalidStateException $ex) {
$this->flashMessage('Error', self::MSG_ERROR);
}
}
我使用foreach来获取多个addTo()
,但它不会发送邮件。
答案 0 :(得分:0)
邮件不能包含多个收件人。有必要创建一个循环并创建关于有多少收件人
的消息public function contactsEditorFormSucceeded($form, $values)
{
try {
$recipients = $values->recipients;
foreach ($recipients as $recipient) {
$mail = new Message;
$mail->setFrom($values->email)
->setSubject($values->subject)
->setBody($values->message)
->addTo($recipient);
$mailer = new SendmailMailer;
$mailer->send($mail);
}
$this->flashMessage('Done.', self::MSG_SUCCESS);
$this->redirect('this');
} catch (InvalidStateException $ex) {
$this->flashMessage('Error', self::MSG_ERROR);
}
}