Laravel邮件不符合RFC 2822,3.6.2

时间:2019-02-18 05:25:10

标签: php laravel

我正在尝试向多个收件人发送电子邮件,但出现以下错误

Address in mailbox given [2@test.com,3@test.com,4@test.com] does not comply with RFC 2822, 3.6.2.

这是我的数据的样子:

array:6 [▼
  "_token" => "xlhKNDnqAuvQpurPpDM2eGseNanUm5P1NBbPA71Z"
  "from" => "test@test.com"
  "mainpeople" => "1@test.com" //to
  "ccpeople" => "2@test.com,3@test.com,4@test.com" //cc
  "subject" => "testing mail"
  "messagenote" => "<p>this is a test mail.<br></p>"
]

代码

$data = array(
  'from' => $request->from,
  'to' => $request->mainpeople,
  'ccpeople' => array($request->ccpeople),
  'subject' => $request->subject,
  'messagenote' => $request->messagenote,
);

Mail::to($data['to'])->cc($data['ccpeople'])->send(new ComposeMail($data));

此外,我尝试循环CC电子邮件,但结果相同:

$data = array(
    'from' => $request->from,
    'to' => $request->mainpeople,
    'ccpeople' => array($request->ccpeople),
    'subject' => $request->subject,
    'messagenote' => $request->messagenote,
);

foreach($data['ccpeople'] as $people){
    $cc = $people;
}

Mail::to($data['to'])->cc($cc)->send(new ComposeMail($data));

知道如何解决该问题吗?

1 个答案:

答案 0 :(得分:2)

您不能直接在字符串上使用array()来将其转换为数组:

您的$data应该保持不变:

$data = array(
  'from' => $request->from,
  'to' => $request->mainpeople,
  'ccpeople' => $request->ccpeople,
  'subject' => $request->subject,
  'messagenote' => $request->messagenote,
);

代替

foreach($data['ccpeople'] as $people){
    $cc = $people;
}

尝试explode(),如下所示:

$cc = explode(',',$data['ccpeople']);

并将其传递给您的邮件功能:

Mail::to($data['to'])->cc($cc)->send(new ComposeMail($data));