PHPMailer Gmail 登录失败,尽管在 "access to less secure apps" 上将端口设置为 465 并使用 "DisplayUnlockCaptcha"
PHPMailer Gmail Sign In Fails, despite setting Port to 465 tuning on "access to less secure apps" and using "DisplayUnlockCaptcha"
我正在尝试获取我的邮件系统 运行。它在我的本地机器上工作得很好,但现在在服务器上邮件似乎失败了。
我成功地收到了一封来自 gmail 的邮件。它说他们已经阻止了登录,我说,好的,那是我,然后再试一次,但这次我什至没有收到错误消息。
更新:我做了更多的研究,发现 SMTP connect() 失败,这是代码
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'mywebsite.service@gmail.com';
$mail->Password = 'mypassword';
// $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
// $mail->Port = 465;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('mywebsite.service@gmail.com', 'MyWebsite Team');
$mail->AddReplyTo( 'mywebsite.service@gmail.com', 'Contact MyWebsite Service' );
$mail->addAddress($email, $name);
$mail->isHTML(true);
$mail->Subject = "Membership, Please Verify Your Account";
$mail->Body = "Content";
if(!$mail->Send()) {
echo "Error sending: " . $mail->ErrorInfo;
}
如您所见,我已将端口设置为 456。我还在我的帐户中打开了 "access to less secure apps" 并使用了 "DisplayUnlockCaptcha",如下所述:
尽管如此,它仍然不起作用..
更新:
我已经尝试了端口 456 和端口 587 都给我 SMTP connect() 失败错误..
一定有什么方法可以找出为什么这不起作用?
此组合将不起作用,因为它在通常需要隐式 TLS 的端口上请求显式 TLS:
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 465;
与the docs on this say一样,STARTTLS模式将无法在465端口上工作。要么更改为SMTPS模式,要么更改端口,即执行以下操作之一:
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
或
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
我正在尝试获取我的邮件系统 运行。它在我的本地机器上工作得很好,但现在在服务器上邮件似乎失败了。
我成功地收到了一封来自 gmail 的邮件。它说他们已经阻止了登录,我说,好的,那是我,然后再试一次,但这次我什至没有收到错误消息。
更新:我做了更多的研究,发现 SMTP connect() 失败,这是代码
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'mywebsite.service@gmail.com';
$mail->Password = 'mypassword';
// $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
// $mail->Port = 465;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('mywebsite.service@gmail.com', 'MyWebsite Team');
$mail->AddReplyTo( 'mywebsite.service@gmail.com', 'Contact MyWebsite Service' );
$mail->addAddress($email, $name);
$mail->isHTML(true);
$mail->Subject = "Membership, Please Verify Your Account";
$mail->Body = "Content";
if(!$mail->Send()) {
echo "Error sending: " . $mail->ErrorInfo;
}
如您所见,我已将端口设置为 456。我还在我的帐户中打开了 "access to less secure apps" 并使用了 "DisplayUnlockCaptcha",如下所述:
尽管如此,它仍然不起作用..
更新: 我已经尝试了端口 456 和端口 587 都给我 SMTP connect() 失败错误..
一定有什么方法可以找出为什么这不起作用?
此组合将不起作用,因为它在通常需要隐式 TLS 的端口上请求显式 TLS:
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 465;
与the docs on this say一样,STARTTLS模式将无法在465端口上工作。要么更改为SMTPS模式,要么更改端口,即执行以下操作之一:
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
或
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;