php使用smtp鉴权方式发送邮件 插件PHPMailer
小白
2022-08-10
【原创文章】
php使用smtp鉴权方式发送邮件 插件PHPMailer
一,开启openssl socket扩展
二,安装composer 包 composer require phpmailer/phpmailer
三,代码示例,拿去就能用
use PHPMailer\PHPMailer\PHPMailer;
//发送邮箱
function email_post($uid='888',$to='493911915@qq.com'){
if(!$uid || !$to){
return 0;
}
$mail = new PHPMailer(true);
//使用smtp鉴权方式发送邮件
// $mail->isSMTP();
$mail->Mailer = 'SMTP';
//smtp需要鉴权 这个必须是true
$mail->SMTPAuth = true;
// qq 邮箱的 smtp服务器地址,这里当然也可以写其他的 smtp服务器地址
$mail->Host = 'smtp.exmail.qq.com';
$mail->SMTPSecure = 'ssl';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Port = 465;
//smtp登录的账号 这里填入字符串格式的qq号即可
$mail->Username = 'xbrc@xbrc.com.cn';
// 这个就是之前得到的授权码,一共16位
$mail->Password = '************';
$mail->setFrom('xbrc@xbrc.com.cn', '西北人才网');
// $to 为收件人的邮箱地址,如果想一次性发送向多个邮箱地址,则只需要将下面这个方法多次调用即可
$mail->addAddress($to);
// 该邮件的主题
$mail->Subject = '简历投递';
// 该邮件的正文内容
$mail->Body = '您收到简历投递,请注意查收';
$path = down_resume($uid);//附件如word
$mail->addAttachment($path);
// 使用 send() 方法发送邮件
if(!$mail->send()) {
// file_put_contents("./email/logo.txt","发送失败: ' . $mail->ErrorInfo".'=========>',FILE_APPEND);
return '发送失败: ' . $mail->ErrorInfo;
} else {
return "发送成功";
}
}最新发布
职场:菜鸟->初级->高级->大神
- git 本地分支关联远程分支,合并!
- 守护进程-kill端口-输出日志-查看等!
- pytorch安装(含cuda、cudnn安装教程)!
- linux系统下ubuntu22.04安装Docker方法!
- 视频截取封面 =php-ffmpeg/php-ffmpeg!
- 常用实例2023-5-10!
- 富文本 塞入mysql 报错: General error: 1366 Incorrect string value: ‘\xF0\x9F\x98\x84‘ for column ‘content‘!
- 百度地图拖拽获取地址实例!
- php使用smtp鉴权方式发送邮件 插件PHPMailer!
- 有道翻译接口对接!
最热排行
职场:菜鸟->初级->高级->大神

