php PHPMailer 中的“SMTP 错误:无法进行身份验证”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3949824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"SMTP Error: Could not authenticate" in PHPMailer
提问by Alejandro Echeverri
I'm using PHPMailer in a Simple Script For Send Email's Through Gmail, and I'm getting an "Unknown Error" (At least for me!):
我在通过 Gmail 发送电子邮件的简单脚本中使用 PHPMailer,但出现“未知错误”(至少对我而言!):
SMTP Error: Could not authenticate. Error: SMTP Error: Could not authenticate.
SMTP server error: 5.7.1 Username and Password not accepted. Learn more at 535 5.7.1 http://mail.google.com/support/bin/answer.py?answer=14257p38sm2467302ybk.16
SMTP 错误:无法验证。错误:SMTP 错误:无法验证。
SMTP 服务器错误:5.7.1 用户名和密码不被接受。在 535 5.7.1 http://mail.google.com/support/bin/answer.py?answer=14257p38sm2467302ybk.16了解详情
I've read about Configure OpenSSL For SSL/TLS Connections, and I did it. Apache And PHP Are properly-Configured (With OpenSSL extension Running in PHP and mod_ssl running in Apache 2.2.16).
我已经阅读了为 SSL/TLS 连接配置 OpenSSL,并且我做到了。Apache 和 PHP 配置正确(OpenSSL 扩展在 PHP 中运行,mod_ssl 在 Apache 2.2.16 中运行)。
This is The PHP Script:
这是 PHP 脚本:
<?php
require_once ("PHPMailer\class.phpmailer.php");
$Correo = new PHPMailer();
$Correo->IsSMTP();
$Correo->SMTPAuth = true;
$Correo->SMTPSecure = "tls";
$Correo->Host = "smtp.gmail.com";
$Correo->Port = 587;
$Correo->UserName = "[email protected]";
$Correo->Password = "gmailpassword";
$Correo->SetFrom('[email protected]','De Yo');
$Correo->FromName = "From";
$Correo->AddAddress("[email protected]");
$Correo->Subject = "Prueba con PHPMailer";
$Correo->Body = "<H3>Bienvenido! Esto Funciona!</H3>";
$Correo->IsHTML (true);
if (!$Correo->Send())
{
echo "Error: $Correo->ErrorInfo";
}
else
{
echo "Message Sent!";
}
?>
The Username and Password are OK, And I tried in Thunderbird, without any problem. I've also Used SSL Authentication and Port 465, getting the same Error.
用户名和密码没问题,我在 Thunderbird 上试过,没有任何问题。我还使用了 SSL 身份验证和端口 465,得到相同的错误。
采纳答案by malletjo
Try this instead :
试试这个:
$Correo->Username= "[email protected]";
$Correo->用户名= "[email protected]";
I tested it and its working perfectly without no other change
我测试了它并且它完美地工作,没有其他变化
回答by cwd
I encountered this problem. To get it working, I had to go to myaccount.google.com-> "Sign-in & security" -> "Apps with account access", and turn "Allow less secure apps" to "ON" (near the bottom of the page).
我遇到了这个问题。为了让它工作,我必须去myaccount.google.com->“登录和安全”->“具有帐户访问权限的应用程序”,然后将“允许不太安全的应用程序”设置为“打开”(靠近底部这一页)。
回答by IRvanFauziE
this is GMail issue
这是 GMail 问题
read this Google Help (https://support.google.com/mail/answer/14257?p=client_login&rd=1)
阅读此 Google 帮助 ( https://support.google.com/mail/answer/14257?p=client_login&rd=1)
- Open your web browser and sign in to Gmail at http://mail.google.com/mail. If you see a word verification request, type the letters in the distorted picture and finish signing in.
- Close your browser and try accessing your messages in your email client again.
- If you're still having problems, visit http://www.google.com/accounts/DisplayUnlockCaptchaand sign in with your Gmail username and password. If necessary, enter the letters in the distorted picture.
- Click Continue.
- Restart your mail client and try accessing messages in your email client again.
- 打开您的网络浏览器并通过http://mail.google.com/mail登录 Gmail 。如果您看到字词验证请求,请键入扭曲图片中的字母并完成登录。
- 关闭您的浏览器并再次尝试在您的电子邮件客户端中访问您的消息。
- 如果仍有问题,请访问http://www.google.com/accounts/DisplayUnlockCaptcha并使用您的 Gmail 用户名和密码登录。如有必要,请在扭曲的图片中输入字母。
- 单击继续。
- 重新启动您的邮件客户端并再次尝试访问您的电子邮件客户端中的消息。
回答by Bubba
I received the same error and in mycase it was the password. My password has special characters for and if you supply the password without escaping the special characters the error will continue to show. E.g $mail->Password = " por$ch3";
is valid but will not work using the code above . The solution should be as follows: $mail->Password = "por\$ch3";
Note the Backslash I placed before the dollar character within my password. That should work if you have a password using special characters
我收到了同样的错误,在我的情况下是密码。我的密码有特殊字符,如果您提供密码而不转义特殊字符,错误将继续显示。例如$mail->Password = " por$ch3";
是有效的,但不能使用上面的代码工作。解决方案应如下所示:$mail->Password = "por\$ch3";
注意我在密码中的美元字符之前放置的反斜杠。如果您有使用特殊字符的密码,那应该可行
回答by svandragt
I received this error because of percentage signs in the password.
由于密码中的百分比符号,我收到此错误。
回答by Rikin Adhyapak
For me I had a special characters in my password field, and I put it like $mail->Password = " por$ch3" which work for gmail smpt server but not for other; so I just changed double quotes to single quotes and it works for me. $mail->Password = ' por$ch3';
对我来说,我的密码字段中有一个特殊字符,我把它写成 $mail->Password = " por$ch3" ,它适用于 gmail smpt 服务器,但不适用于其他;所以我只是将双引号更改为单引号,它对我有用。$mail->密码 = 'por$ch3';
回答by Red
I experienced the same error when configuring the WP-Mail-SMTP
plugin in Wordpress.
WP-Mail-SMTP
在 Wordpress 中配置插件时,我遇到了同样的错误。
The problem would persist even when I have 'triple checked' the settings and login credentials, and am able to log in manually using a browser.
即使我对设置和登录凭据进行了“三重检查”,并且能够使用浏览器手动登录,问题仍然存在。
There's a list of steps you can take to fix this.
您可以采取一系列步骤来解决此问题。
- Create a new password for the Gmail account you want to use
- Enable less secure apps in Google Security settings
- Use the
Display Unlock Captcha
pageto give your app or website permission to sign in to Gmail. ClickContinue
or follow the instructions. - Sign in using the app or website. The smtp settings that work for me are 1) SMTP Host: smtp.gmail.com 2) SMTP port: 587 3) Encryption: TLS 4) Authentication: SMTP authentication 5) Username: [email protected] 6) Password: examplesecret
- 为您要使用的 Gmail 帐户创建新密码
- 在Google 安全设置中启用安全性较低的应用
- 使用该
Display Unlock Captcha
页面授予您的应用或网站登录 Gmail 的权限。单击Continue
或按照说明操作。 - 使用应用程序或网站登录。对我有用的 smtp 设置是1) SMTP 主机:smtp.gmail.com 2) SMTP 端口:587 3) 加密:TLS 4) 身份验证:SMTP 身份验证 5) 用户名:[email protected] 6) 密码:examplesecret
回答by Ehsan
I had the same issue and did all the tips including Gmail setting (e.g. less secure apps access) with no luck. But finally when I changed password to something different, for some reason it worked! FYI, the initial password did not have any special characters.
我遇到了同样的问题,并且没有运气就做了所有提示,包括 Gmail 设置(例如不太安全的应用程序访问)。但是最后当我将密码更改为不同的东西时,由于某种原因它起作用了!仅供参考,初始密码没有任何特殊字符。
回答by HymanSparrow
If you still face error in sending email, with the same error message. Try this:
如果您在发送电子邮件时仍然遇到错误,则会出现相同的错误消息。尝试这个:
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
just Before the line:
就在行前:
$send = $mail->Send();
or in other sense, before calling the Send() Function.
或者换句话说,在调用 Send() 函数之前。
Tested and Working.
测试和工作。
回答by anu
I had the same problem with authentication. The fix was to set up 2-step verification and create an application specific password for the device ( error messages for blocking the device will appear in your account settings->"Notifications and alerts" if you problem is the same with mine)
我在身份验证方面遇到了同样的问题。修复方法是设置两步验证并为设备创建应用程序特定密码(阻止设备的错误消息将出现在您的帐户设置->“通知和警报”中,如果您的问题与我的相同)