0

我正在尝试通过 nette mailer 向选定的用户发送电子邮件,但它总是以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(),但它不会发送邮件。

4

1 回答 1

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);
    }
}   
于 2018-01-27T23:23:51.697 回答