我正在尝试向多个收件人发送电子邮件,但出现以下错误
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));
知道如何解决该问题吗?
答案 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));