我刚刚发现,如果我在邮件中传递了非现有电子邮件地址:queue()。电子邮件地址具有有效的格式,即"@"之后名称之后的"@"符号。样本将是" johndoesnotexist@notexistemail.com"。即使" notexistemail.com"根本不存在,该格式是有效的。
这是代码段:
$email_data = array('color' => 'Red');
$email_company = 'johndoesnotexist@notexistemail.com';
$email_name = 'john doe';
Mail::queue('emails.form1', $email_data, function($message) use($email_company, $email_name) {
$message->to($email_company, $email_name)->subject('Hello John');
});
但是,如果我传递了现有的电子邮件地址,则脚本有效。我需要处理这种错误,即记录Laravel.log中的错误。我该如何编码?
,在这种情况下,您可以尝试捕获此问题,然后记录问题的电子邮件地址。这样的东西: -
try {
$email_data = array('color' => 'Red');
$email_company = 'johndoesnotexist@notexistemail.com';
$email_name = 'john doe';
Mail::queue('emails.form1', $email_data, function($message) use($email_company, $email_name) {
$message->to($email_company, $email_name)->subject('Hello John');
});
} catch (Exception $e) {
Log::error('Failed to send email to ' . $email_company);
}