toEmail($notifiable);
if ($data && isset($notifiable['email']) && Validate::is($notifiable['email'], "email")) {
try {
$email = new SendEmail;
$result = $email
->to($notifiable['email'], $notifiable['nickname'])
->subject(($data['data'] ? $data['data']['template'] : '邮件通知'))
->message('
' . $data['content'] . '
')
->send();
if ($result) {
// 发送成功
$notification->sendOk('Email');
} else {
// 邮件发送失败
\think\Log::error('邮件消息发送失败:用户:' . $notifiable['id'] . ';类型:' . get_class($notification) . ";发送类型:" . $notification->event . ";错误信息:" . json_encode($email->getError()));
}
} catch (\Exception $e) {
// 因为配置较麻烦,这里捕获异常防止因为缺少字段,导致队列一直执行不成功
format_log_error($e, 'email_notification', '用户:' . $notifiable['id'] . ';类型:' . get_class($notification) . ";发送类型:" . $notification->event);
}
return true;
}
// 没有openid
\think\Log::error('邮件消息发送失败,没有 email,或 email 格式不正确:用户:' . $notifiable['id'] . ';类型:' . get_class($notification) . ";发送类型:" . $notification->event);
}
return true;
}
}