下载PHPMailer包
composer require phpmailer/phpmailer
$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
$mail->isSMTP();
$mail->SMTPDebug = 0;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//调试输出格式
$mail->Debugoutput = 'html';
//smtp服务器
$mail->Host = 'SMTP.qq.com';
//端口 - likely to be 25, 465 or 587
$mail->Port = '465';
$mail->SMTPSecure ='ssl';// 使用安全协议 tls,ssl
//用户名
$mail->Username = '******@qq.com';
//密码
$mail->Password = 'kbdstabvwhigbbdg';
//Set who the message is to be sent from
$mail->setFrom('******@qq.com','注册通知');
//回复地址
//$mail->addReplyTo('replyto@example.com', 'First Last');
//接收邮件方
$mail->addAddress('******@qq.com', '您好!'); //要发送的地址和设置地址的昵称
$mail->isHTML(true);// send as HTML
//标题
$mail->Subject = '吃饭吗';
//邮箱正文
$mail->Body = '我爱你';
//添加附件
if (!empty($addAttachment)){
$mail->addAttachment($addAttachment);
}
try {
$mail->send();
Log::info('发送成功');
}catch (\Exception $e){
Log::info('发送失败');
}