我在 Laravel 中有邮件发送功能
public static function Compose($to,$cc,$bcc,$subject,$body)
{
// return $to;
try
{
$data = [
'body' => $body
];
if(env('APP_ENV') == "local")
{
$email["subject"] = $subject;
$email["to"] = $to;
$email["cc"] = $cc;
$email["bcc"] = $bcc;
Mail::send('email.composeMail', $data, function ($message) use ($email) {
$message
->subject($email["subject"])
->to($email["to"]);
->cc($email["cc"]);
->bcc($email["bcc"]);
});
}
else
{
$email["subject"] = $subject;
$email["to"] = $to;
$email["cc"] = $cc;
$email["bcc"] = $bcc;
Mail::send('email.composeMail', $data, function ($message) use ($email) {
$message
->subject($email["subject"])
->to($email["to"]);
->cc($email["cc"]);
->bcc($email["bcc"]);
});
}
}
catch (\Exception $e)
{
Log::critical('Critical error occurred upon processing the transaction in Email.php -> Email class -> RevertPropertyToInbox method');
throw new CustomErrorHandler($e->getMessage(),Constant::LogLevelCritical);
}
}
在很多情况下,抄送和密送字段是空的。但是邮件没有被发送,并且我收到了错误消息。
在这里,我想直接使用代码而不检查CC或BCC是否为空,我是否遗漏了什么以便我能实现我的计划。