swiftmailer电子邮件错误,包含多封电子邮件

时间:2019-05-21 05:18:54

标签: javascript php html firebase swiftmailer

当从Firebase到php接收多封电子邮件(将数据从Firebase传递到HTML然后传递到html到PHP)时,我始终收到致命错误消息

  

致命错误:消息为“ [Person1 @ outlook.com,Person2 @ gmail.com]的邮箱中的地址”的未捕获异常'Swift_RfcComplianceException'不符合RFC 2822,3.6.2

我尝试从firebase收到一封电子邮件,但效果很好,但是出现了多封电子邮件,其中包含我使用相同问题的所有电子邮件

<?php

require '/Vendor/Mail/lib/swift_required.php';

// validation expected data exists if required later
if (!isset($_POST['agent_e'])  {
    died('We are sorry, but there appears to be a problem with the form you submitted.');
}

$email_to = $_POST['agent_e']; // required
$headers .= "MIME-Version: 1.0\r\n";

$mailer   = Swift_Mailer::newInstance($transport);
$message  = Swift_Message::newInstance('')
    ->setSubject($subject)
    ->setFrom(array('mailer@outlook.com' => 'mailer'))
    ->setTo(array($email_to))
    ->setBody('<html>' .
' <body>' .
'  ' . // Embed the file
$messageBody .
'  ' .
' </body>' .
'</html>',
'text/html' // Mark the content-type as HTML
);

// Send the message
$result = $mailer->send($message);

来自数据库示例的电子邮件:

enter image description here

错误:

enter image description here

1 个答案:

答案 0 :(得分:0)

我解决了将Firebase中收到的电子邮件拆分为数组的问题

如下代码:

$email_to = str_replace(' ','',$email_to);
$email_to = (string) $email_to;
$email_to = explode(',',$email_to);