laravel 邮件发送 学习记录
最初根据《Laravel 教程 - Web 开发实战入门 ( Laravel 5.5 ) 》上的说法鼓捣出了邮件发送的基本格式
/**
* Notes: 邮件发送
* User: xxx
* Date: 2018/8/15 0015
* Time: 下午 5:22
*/
public function EmailUser ()
{
// return view('emails.confirm');
$user = User::find(1);
$view = 'emails.confirm';
$data = compact('user');
$from = 'aaa@qq.com';
$name = '雷';
$to = $user->email;
$subject = "感谢注册 Sample 应用!请确认你的邮箱。";
Mail::send($view, $data, function ($message) use ($from, $name, $to, $subject) {
$message->from($from, $name)->to($to)->subject($subject);
});
}
}
出发了异常
(1/1) Swift_TransportException
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
"
Swift_TransportException
预期的响应代码250但得到代码“530”,消息“530 5.7.1需要认证
“
百度之后发现,是因为配置文件没有配置
config/mail.php
'host' => env('MAIL_HOST', 'smtp.mailgun.org')
可以看出,他是从.env文件读取的数据,
.env文件添加配置
MAIL_DRIVER=smtp
MAIL_HOST=smtp.163.com
MAIL_PORT=2525
aaa@qq.com
MAIL_PASSWORD=xxxxxxxx
MAIL_ENCRYPTION=null
MAIL_FROM_NAME=leisogn
再次尝试
小圈圈转了六七秒再次报错
Swift_TransportException
Connection could not be established with host smtp.163.com [����Ŀ����������ܾ��������ӡ�
#10061]
Swift_TransportException
无法与主机smtp.163.com建立连接[ Ŀ ܾ ӡ
#10061]
无奈再次百度
https://blog.csdn.net/daqi1983/article/details/73369440
。。。端口问题
改成25
再次尝试
Expected response code 250 but got code "553", with message "553 Mail from must equal authorized user
"
预期的响应代码250,但得到代码“553”,消息“553邮件来自必须等于授权用户
“
又一次报错,无奈,度娘告诉你一起,再次百度。ヽ( ̄▽ ̄)ノ
找到答案 这是因为有些邮件服务器要求from和username必须一致,163邮箱就是这样。
配置里面的MAIL_USERNAME 需要和 发送时的$from 一样