此功能用于将电子邮件发送给用户,并且在邮件中,我们通过幼虫中的.env文件获取SMTP的用户名密码
private function pushEmailNotifications($users,$title,$msg,$type)
{
foreach ($users as $value) {
$template='emails.admin_email';
$data = array('title' => $title,'type' => $type,'msg' => $msg);
try {
Mail::queue($template, $data, function ($message) use ($value,$title) {
$message->from('mymailid@gmail.com', 'myapp');
$message->to($value)->subject($title);
});
}
catch (Exception $e) {
if (count(Mail::failures()) > 0) {
$failures[] = $value;
}
}
}
return "success";
}
这是.env文件中的代码:
MAIL_DRIVER = smtp
MAIL_HOST = smtp.gmail.com
MAIL_PORT = 587
MAIL_USERNAME = mymailid@gmail.com
MAIL_PASSWORD = 12345
MAIL_ENCRYPTION = tsl
答案 0 :(得分:0)
首先,我看到您的MAIL_ENCRYPTION应该为'tls',这是错误的,请先尝试一下,然后看看会发生什么情况
答案 1 :(得分:0)
尝试使用此电子邮件发送其余所有邮件。
Mail::raw($message_body, function ($message) use ($to,$subject){
$message->to($to);
$message->subject("$subject");
});