php - 我的代码中是否有任何问题“电子邮件无法使用我的 G-suite 帐户电子邮件”与 phpmailer
问题描述
2019-08-01 09:41:35 连接:关闭
SMTP 错误:无法验证。无法发送消息。邮件程序错误:SMTP 错误:无法验证。
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '*******@mydomain.com';
$mail->Password = '******';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
解决方案
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'test2@gmail.com';
$mail->Password = '123456';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->IsHTML(true); // send as HTML
$mail->SMTPKeepAlive = true;
$mail->CharSet = 'utf-8';
$mail->setFrom('test@gmail.com');
//Recipients
$mail->addAddress($email);
$mail->addReplyTo('test@gmail.com');
//Content
$mail->isHTML(true);
$mail->Subject = 'Reset';
$mail->Body = $message;
$mail->send();
$_SESSION['success'] = 'Password reset link sent';
}
catch (Exception $e) {
$_SESSION['error'] = 'Message could not be sent. Mailer Error: '.$mail->ErrorInfo;
}
推荐阅读
- python - 我可以用 django 从 python 函数制作一个二维码吗
- java - 如何使 notify() 与 wait() 一起正常工作
- javascript - 贝宝智能支付按钮动态支付金额
- php - 使用 php 上传多个图像和文本输入
- android - android通过viewpager从片段回调到dialogfragment
- python - 如何在 NetworkX 中找到有向路径?
- java - 如何使用 Spring Webclient 的同步调用处理异常?
- python - ctypes 和访问 com 接口方法
- apache-kafka - Kafka Broker 问题(具有最大大小的副本管理器)
- sql - PostgreSQL 任务:触发计算平均值