PHPmailer-GMail smtp连接错误
我已经更改了“启用google mail中不太安全的应用程序选项”,但我的gmail应用程序仍然会出现这个错误PHPmailer-GMail smtp连接错误,smtp,gmail,phpmailer,Smtp,Gmail,Phpmailer,我已经更改了“启用google mail中不太安全的应用程序选项”,但我的gmail应用程序仍然会出现这个错误 require 'inc/PHPMailerAutoload.php'; $mail = new PHPMailer; $mail = new PHPMailer; $mail->IsSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp.gma
require 'inc/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->Port = 587; // Set the SMTP port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '*al********@gmail.com'; // SMTP username
$mail->Password = '****at****'; // SMTP password
$mail->SMTPSecure = 'tls';
$mail->From = '*al********@gmail.com';
$mail->FromName = '******i';
$mail->AddAddress('andaeiii@aol.com', 'Ande C.'); // Add a recipient
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
require'inc/phpmailerautoad.php';
$mail=新的PHPMailer;
$mail=新的PHPMailer;
$mail->IsSMTP();//将邮件程序设置为使用SMTP
$mail->Host='smtp.gmail.com';//指定主服务器和备份服务器
$mail->Port=587;//设置SMTP端口
$mail->SMTPAuth=true;//启用SMTP身份验证
$mail->Username='*al*********@gmail.com';//SMTP用户名
$mail->Password='*****在****';//SMTP密码
$mail->SMTPSecure='tls';
$mail->From='*al************@gmail.com';
$mail->FromName='*******i';
$mail->AddAddress('andaeiii@aol.com“,”Ande C.);//添加收件人
$mail->IsHTML(正确);//将电子邮件格式设置为HTML
$mail->Subject='主题在这里';
$mail->Body='这是HTML邮件的正文,用粗体显示强>';
$mail->AltBody='这是非HTML邮件客户端的纯文本正文';
如果(!$mail->Send()){
echo“无法发送消息”;
回显“邮件错误:”。$mail->ErrorInfo;
出口
}
回音“消息已发送”;
当我运行代码时,它会给我这个错误。。。
“无法发送邮件。邮件程序错误:SMTP连接()失败。”-我做得不对。。。还有没有更好的方法,或者我可以使用任何更好的SMTP服务器。。我需要建议
谢谢。需要“vendor/autoload.php”;
require "vendor/autoload.php";
//This solution is for version 6.0.3 of PHPMailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mailer = new PHPMailer(true);
try {
$mailer->isSMTP();
$mailer->SMTPOptions = [
'ssl'=> [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
];
$mailer->Host = 'smtp.gmail.com';
$mailer->SMTPAuth = true;
$mailer->Username = 'mail@gmail.com';
$mailer->Password = '1234567';
$mailer->SMTPSecure = 'tls';
$mailer->Port = 587;
$mailer->CharSet = 'UTF-8';
$mailer->setFrom('mail@gmail.com');
$mailer->addAddress('example@gmail.com', 'Andres Guzmán');
$mailer->isHTML(true);
$mailer->Subject = 'Subject';
$mailer->Body = '<b>Body <b>GRACIAS!</b>';
$mailer->send();
$mailer->ClearAllRecipients();
echo "Mensaje enviado";
} catch (Exception $e) {
echo "Falla en el envío del mensaje. INFO: " . $mailer->ErrorInfo;
}
//此解决方案适用于PHPMailer的6.0.3版
使用PHPMailer\PHPMailer\PHPMailer;
使用PHPMailer\PHPMailer\Exception;
$mailer=新的PHPMailer(true);
试一试{
$mailer->isSMTP();
$mailer->SMTPOptions=[
“ssl”=>[
“验证对等方”=>false,
'verify_peer_name'=>false,
“允许自签名”=>true
]
];
$mailer->Host='smtp.gmail.com';
$mailer->SMTPAuth=true;
$mailer->Username=mail@gmail.com';
$mailer->Password='1234567';
$mailer->SMTPSecure='tls';
$mailer->Port=587;
$mailer->CharSet='UTF-8';
$mailer->setFrom($mailer)mail@gmail.com');
$mailer->addAddress('example@gmail.com","安德烈斯古兹曼",;
$mailer->isHTML(true);
$mailer->Subject='Subject';
$mailer->Body='Body GRACIAS!';
$mailer->send();
$mailer->ClearAllRecipients();
呼应“mensajeenviado”;
}捕获(例外$e){
echo“Falla en el envío del mensaje.INFO:”.$mailer->ErrorInfo;
}
您能补充一些解释吗?你改变了什么?你为什么要改变它?