2

尽管有许多相同的问题,但没有一个解决方案对我有用。仅当只有一个收件人时才会发送邮件,否则会在下面生成错误。另外,我只发送内部电子邮件,没有外部电子邮件。

任何的想法?

代码:

$to = 'one@example.com, two@example.com, three@example.com';

$transport  = Swift_SmtpTransport::newInstance('192.168.whatever', 25);
$mailer     = Swift_Mailer::newInstance($transport);
$message    = Swift_Message::newInstance('Test')
                ->setFrom(array('myself@example.com'))
                ->setTo(array($to))
                ->setBody('html content goes here', 'text/html');

$result = $mailer->send($message);

echo $result;

错误

Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [one@example.com, two@example.com, three@example.com] does not comply with RFC 2822, 3.6.2.' in C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\Headers\MailboxHeader.php:308 Stack trace: #0 C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\Headers\MailboxHeader.php(238): Swift_Mime_Headers_MailboxHeader->_assertValidAddress('lukas.borecki@l...') #1 C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\Headers\MailboxHeader.php(96): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array) #2 C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\Headers\MailboxHeader.php(60): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array) #3 C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\SimpleHeaderFactory.php(60): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel(Array) #4 C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\SimpleHeaderSet.php(75): Swift_Mime_SimpleHead in C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\Headers\MailboxHeader.php on line 308

看着:

Swift 网站 swift 邮件程序错误 'Swift_RfcComplianceException'.... Google 论坛 等等。

4

2 回答 2

13

尝试

$to = array('one@example.com', 'two@example.com', 'three@example.com');
....
->setTo($to)
于 2013-04-04T12:56:37.227 回答
1

用 swiftmailer 试试这个例子:

参数.yml

目标:[email1,email2,email3]

服务:

您的服务名称:类:您的命名空间参数:["%destinatarios%"]

服务等级:

受保护的$destinatarios;

public function __construct($destinatarios)
{
    $this->destinatarios = $destinatarios;
}

->setCc($this->destinatarios)
于 2016-03-31T08:40:45.200 回答