SMTP错误:从我的服务器发送邮件时密码命令失败

时间:2021-11-06 18:11:55

I have used phpmailer() concept to send mail to users from my shared server using php script, but I'm not able to send even though everything is right in my script according to phpmailer code.

我已经使用phpmailer()概念使用php脚本从共享服务器向用户发送邮件,但是我不能按照phpmailer代码发送脚本中的所有内容。

My code like this:

我的代码是这样的:

  $message = " This is testing message from my server";

  $mail = new PHPMailer(); // create a new object
  $mail->IsSMTP(); // enable SMTP
  $mail->Host = "smtp.gmail.com";
  $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
  $mail->SMTPAuth = true; // authentication enabled
  $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
  $mail->Port = 465; // or 587
  $mail->IsHTML(true);
  $mail->Username = "moorthi.mrk10@gmail.com"; // My gmail username
  $mail->Password = "************"; // My Gmail Password
  $mail->SetFrom("moorthi.mrk10@gmail.com");
  $mail->Subject = "Test Mail from my Server";
  $mail->Body = $message;
  $mail->AddAddress($email);
   if($mail->Send())
      {
    print json_encode("SUCCESS");
}
else
{
    echo "Mailer Error: " . $mail->ErrorInfo;

}

Note: I have used " GMail " as my SMTP server and SMTPSecure is " ssl " and port is "465" and username & passwords are my GMail username & password

注意:我使用了“GMail”作为SMTP服务器,SMTPSecure是“ssl”,端口是“465”,用户名和密码是我的GMail用户名和密码

I used VPS shared server and I kept my php script on that server.

我使用VPS共享服务器,并将php脚本保存在该服务器上。

I think there is no problem in my php script and I don't know why it doesn't work.

我认为我的php脚本没有问题,我不知道为什么它不能工作。

I got the ERROR like this.

我得到了这样的误差。

  2014-02-21 12:30:11   CLIENT -> SERVER: EHLO jkcorporates.com
  2014-02-21 12:30:11   CLIENT -> SERVER: AUTH LOGIN
  2014-02-21 12:30:11   CLIENT -> SERVER: bW9vcnRoaS5tcmsxMEBnbWFpbC5jb20=
  2014-02-21 12:30:11   CLIENT -> SERVER: OTk0MTI0MTE0MA==
  2014-02-21 12:30:11   SMTP ERROR: Password command failed: 534-5.7.14 
  534-5.7.14 i-_eumA> Please log in via your web browser and then try again.
  534 5.7.14 54 k76sm17979938yho.18 - gsmtp
  2014-02-21 12:30:11   CLIENT -> SERVER: QUIT
  " The ERROR is  "  SMTP connect() failed.

Please give some solution for that.
Thanks in Advance.

请给出一些解决办法。提前谢谢。

Remember: I use Shared Server Name 'VPS.mydomain.com' and I want to use GMail as my SMTP server to send mail to users.

记住:我使用共享服务器名“VPS.mydomain.com”,我想使用GMail作为SMTP服务器向用户发送邮件。

8 个解决方案

#1


127  

A bit late, but perhaps someone will find it useful.

有点晚了,但也许有人会觉得它有用。

Links that fix the problem (you must be logged into google account):

修复问题的链接(您必须登录到谷歌帐户):

https://security.google.com/settings/security/activity?hl=en&pli=1

https://security.google.com/settings/security/activity?hl=en&pli=1

https://www.google.com/settings/u/1/security/lesssecureapps

https://www.google.com/settings/u/1/security/lesssecureapps

https://accounts.google.com/b/0/DisplayUnlockCaptcha

https://accounts.google.com/b/0/DisplayUnlockCaptcha

Some explanation of what happens:

对发生的事情有一些解释:

This problem can be caused by either 'less secure' applications trying to use the email account (this is according to google help, not sure how they judge what is secure and what is not) OR if you are trying to login several time in a row OR if you change countries (for example use VPN, move code to different server or actually try to login from different part of the world).

这个问题可能是由于要么更不安全的应用程序试图使用电子邮件帐户(这是根据谷歌的帮助,不知道他们如何判断什么是安全的,什么是不)或如果你想连续登录几次或如果你改变国家(例如使用VPN,代码移动到不同的服务器或者尝试登录不同的世界的一部分)。

To resolve I had to: (first time)

为了解决问题,我不得不:(第一次)

  • login to my account via web
  • 通过网络登录到我的账户
  • view recent attempts to use the account and accept suspicious access: THIS LINK
  • 查看最近使用该帐户的尝试并接受可疑访问:此链接
  • disable the feature of blocking suspicious apps/technologies: THIS LINK
  • 禁用阻止可疑应用程序/技术的特性:此链接

This worked the first time, but few hours later, probably because I was doing a lot of testing the problem reappeared and was not fixable using the above method. In addition I had to clear the captcha (the funny picture, which asks you to rewrite a word or a sentence when logging into any account nowadays too many times) :

这是第一次,但几个小时后,可能因为我做了很多测试,重新出现了问题,并不能用上面的方法固定。此外,我还必须清除验证码(有趣的图片,它要求你在登录任何账号时重写一个单词或句子):

  • after login to my account I went HERE
  • 登录到我的账户后,我来到了这里
  • Clicked continue
  • 点击继续

Hope this helps.

希望这个有帮助。

#2


20  

Use this:

用这个:

https://www.google.com/settings/u/1/security/lesssecureapps
https://accounts.google.com/b/0/DisplayUnlockCaptcha
https://security.google.com/settings/security/activity?hl=en&pli=1

this link allow acces to google account

此链接允许acces到谷歌帐户

UPDATE 19-05-2017:

更新19-05-2017:

These url you must to visit from the IP address that will be send email

您必须从将发送电子邮件的IP地址访问这些url。

#3


6  

Solved the problem - PHPMailer - SMTP ERROR: Password command failed when send mail from my server

解决了PHPMailer - SMTP错误:从服务器发送邮件时密码命令失败

    require_once('class.phpmailer.php');
    include("class.smtp.php"); 
    $nameField = $_POST['name'];
    $emailField = $_POST['email'];
    $messageField = $_POST['message'];
    $phoneField = $_POST['contactno'];
    $cityField = $_POST['city'];

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

$mail->IsSMTP(); // telling the class to use SMTP

$body .= $nameField;

try {
     //$mail->Host       = "mail.gmail.com"; // SMTP server
      $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
      $mail->SMTPAuth   = true;                  // enable SMTP authentication
      $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
      $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
      $mail->Port       = 465;   // set the SMTP port for the GMAIL server
      $mail->SMTPKeepAlive = true;
      $mail->Mailer = "smtp";
      $mail->Username   = "xxxxx@gmail.com";  // GMAIL username
      $mail->Password   = "********";            // GMAIL password
      $mail->AddAddress('sendto@gmail.com', 'abc');
      $mail->SetFrom('xxxxxx@gmail.com', 'def');
      $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
      $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
      $mail->MsgHTML($body);
      $mail->Send();
      echo "Message Sent OK</p>\n";
      header("location: ../test.html");
} catch (phpmailerException $e) {
      echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
      echo $e->getMessage(); //Boring error messages from anything else!
}

Important:

重要的是:

Go to google Setting and do 'less secure' applications enables. It will work. It Worked for Me.

转到谷歌设置并执行“不安全”应用程序启用。它将工作。它为我工作。

#4


6  

As others already suggested, you can enable the "less secure" applications or you can simply switch from ssl to tls:

正如其他人已经建议的那样,您可以启用“不太安全”的应用程序,或者您可以简单地从ssl切换到tls:

$mailer->Host = 'tls://smtp.gmail.com';
$mailer->SMTPAuth = true;
$mailer->Username = "xxx@gmail.com";
$mailer->Password = "***";
$mailer->SMTPSecure = 'tls';
$mailer->Port = 587;

When using tls there's no need to grant access for less secure applications, just make sure, IMAP is enabled.

当使用tls时,不需要为不太安全的应用程序授予访问权限,只需确保启用了IMAP。

#5


2  

I face the same problem, and think that I do know why this happens.

我面临着同样的问题,我想我知道为什么会这样。

The gmail account that I use is normally used from India, and the webserver that I use is located in The Netherlands.

我使用的gmail帐户通常来自印度,我使用的webserver位于荷兰。

Google notifies that there was a login attempt from am unusualy location and requires to login from that location via a web browser.

谷歌通知说有一个从一个不同寻常的位置登录的尝试,需要通过web浏览器从那个位置登录。

Furthermore I had to accept suspicious access to the gmail account via https://security.google.com/settings/security/activity

此外,我还必须通过https://security.google.com/settings/security/activity接受对gmail帐户的可疑访问。

But in the end my problem is not yet solved, because I have to login to gmail from a location in The Netherlands.

但最终我的问题还没有解决,因为我必须从荷兰的一个地点登录gmail。

I hope this will help you a little! (sorry, I do not read email replies on this email address)

我希望这能对你有所帮助!(对不起,我没有在此电子邮件地址上看到回复)

#6


1  

If you are G Suit user it can be solved by Administrator

如果您是G Suit用户,可以由管理员解决

  1. Go to your Admin panel
  2. 进入你的管理面板
  3. Type in top search bar «Security» (Select Security with Shield icon)
  4. 输入*搜索栏«安全»(使用盾牌图标选择安全)
  5. Open Basic settings
  6. 开放的基本设置
  7. Goto Less secure apps section
  8. 不那么安全的应用
  9. Press: Go to settings for less secure apps ››
  10. 出版社:去设置不太安全的应用›

And now select one of Radio Button a) Disable access to less secure apps for all users (Recommended) b) Allow users to manage their access to less secure apps c) Enforce access to less secure apps for all users (Not Recommended)

现在,选择一个单选按钮a)禁用对所有用户(推荐)b的不安全应用程序的访问权限,允许用户管理他们的访问权限,以减少对所有用户的安全应用程序的访问权限(不推荐)

Usually It does not working because of a)! And will start working immediately with c) option. b) – option will need more configuration for each user in GSuit

通常它不能工作,因为a)!并将立即开始工作与c)选项。b) -选项将需要对GSuit中的每个用户进行更多的配置

Hope it helps

希望它能帮助

#7


0  

This error is due to more security features of gmail..

这个错误是由于gmail的更多安全特性造成的。

Once this error is generated...Please login to your gmail account..there you can find security alert from GOOGLE..follow the mail...check on click for less secure option..Then try again phpmailer..

一旦产生这个错误……请登录您的gmail帐户。在这里您可以从谷歌找到安全警报。按照邮件…检查点击少安全选项。然后再试一次phpmailer . .

#8


0  

For those who are still unable to get it working, try the following in addition to the method provided by @CallMeBob.

对于那些仍然无法使其正常工作的人,请尝试以下方法以及@CallMeBob提供的方法。

PHP.ini

  1. Go to C:\xampp\php , edit php.ini file with notepad.
  2. 转到C:\xampp\php编辑php。ini文件用记事本。
  3. Press CTRL+F on your keyboard, input sendmail_path on the search bar and click Find Next twice.
  4. 在你的键盘上按下CTRL+F,在搜索栏上输入sendmail_path,然后点击“查找”两次。
  5. Right now, you should be at the [mail munction] section.
  6. 现在,你应该在[邮件功能]部门。

Remove the semicolon for this line: sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Add a semicolon for this line: sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

删除这一行的分号:sendmail_path = "\"C:\xampp\sendmail\sendmail \sendmail = "\" sendmail "。为这行添加分号:sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

SendMail.ini

  • Go to C:\xampp\sendmail, edit sendmail.ini file with notepad
  • 去C:\xampp\sendmail,编辑sendmail。ini文件用记事本
  • Change the following:
  • 改变如下:
  • smtp_server=smtp.gmail.com
  • smtp_server = smtp.gmail.com
  • smtp_port=465
  • smtp_port = 465
  • auth_username=your-gmail-username@gmail.com
  • auth_username = your-gmail-username@gmail.com
  • auth_password=your-gmail-password
  • auth_password = your-gmail-password
  • force_sender=your-gmail-username@gmail.com
  • force_sender = your-gmail-username@gmail.com


Note:
** smtp_port must tally with your those written in your php code.
** Remember to change your-gmail-username and your-gmail-password to whichever account you are using.
**

注意:** smtp_port必须符合您在php代码中编写的那些。**记得将你的“gmail”用户名和“gmail”密码更改为你使用的任何一个账户。* *


Hope this helps! :)

希望这可以帮助!:)

#1


127  

A bit late, but perhaps someone will find it useful.

有点晚了,但也许有人会觉得它有用。

Links that fix the problem (you must be logged into google account):

修复问题的链接(您必须登录到谷歌帐户):

https://security.google.com/settings/security/activity?hl=en&pli=1

https://security.google.com/settings/security/activity?hl=en&pli=1

https://www.google.com/settings/u/1/security/lesssecureapps

https://www.google.com/settings/u/1/security/lesssecureapps

https://accounts.google.com/b/0/DisplayUnlockCaptcha

https://accounts.google.com/b/0/DisplayUnlockCaptcha

Some explanation of what happens:

对发生的事情有一些解释:

This problem can be caused by either 'less secure' applications trying to use the email account (this is according to google help, not sure how they judge what is secure and what is not) OR if you are trying to login several time in a row OR if you change countries (for example use VPN, move code to different server or actually try to login from different part of the world).

这个问题可能是由于要么更不安全的应用程序试图使用电子邮件帐户(这是根据谷歌的帮助,不知道他们如何判断什么是安全的,什么是不)或如果你想连续登录几次或如果你改变国家(例如使用VPN,代码移动到不同的服务器或者尝试登录不同的世界的一部分)。

To resolve I had to: (first time)

为了解决问题,我不得不:(第一次)

  • login to my account via web
  • 通过网络登录到我的账户
  • view recent attempts to use the account and accept suspicious access: THIS LINK
  • 查看最近使用该帐户的尝试并接受可疑访问:此链接
  • disable the feature of blocking suspicious apps/technologies: THIS LINK
  • 禁用阻止可疑应用程序/技术的特性:此链接

This worked the first time, but few hours later, probably because I was doing a lot of testing the problem reappeared and was not fixable using the above method. In addition I had to clear the captcha (the funny picture, which asks you to rewrite a word or a sentence when logging into any account nowadays too many times) :

这是第一次,但几个小时后,可能因为我做了很多测试,重新出现了问题,并不能用上面的方法固定。此外,我还必须清除验证码(有趣的图片,它要求你在登录任何账号时重写一个单词或句子):

  • after login to my account I went HERE
  • 登录到我的账户后,我来到了这里
  • Clicked continue
  • 点击继续

Hope this helps.

希望这个有帮助。

#2


20  

Use this:

用这个:

https://www.google.com/settings/u/1/security/lesssecureapps
https://accounts.google.com/b/0/DisplayUnlockCaptcha
https://security.google.com/settings/security/activity?hl=en&pli=1

this link allow acces to google account

此链接允许acces到谷歌帐户

UPDATE 19-05-2017:

更新19-05-2017:

These url you must to visit from the IP address that will be send email

您必须从将发送电子邮件的IP地址访问这些url。

#3


6  

Solved the problem - PHPMailer - SMTP ERROR: Password command failed when send mail from my server

解决了PHPMailer - SMTP错误:从服务器发送邮件时密码命令失败

    require_once('class.phpmailer.php');
    include("class.smtp.php"); 
    $nameField = $_POST['name'];
    $emailField = $_POST['email'];
    $messageField = $_POST['message'];
    $phoneField = $_POST['contactno'];
    $cityField = $_POST['city'];

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

$mail->IsSMTP(); // telling the class to use SMTP

$body .= $nameField;

try {
     //$mail->Host       = "mail.gmail.com"; // SMTP server
      $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
      $mail->SMTPAuth   = true;                  // enable SMTP authentication
      $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
      $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
      $mail->Port       = 465;   // set the SMTP port for the GMAIL server
      $mail->SMTPKeepAlive = true;
      $mail->Mailer = "smtp";
      $mail->Username   = "xxxxx@gmail.com";  // GMAIL username
      $mail->Password   = "********";            // GMAIL password
      $mail->AddAddress('sendto@gmail.com', 'abc');
      $mail->SetFrom('xxxxxx@gmail.com', 'def');
      $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
      $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
      $mail->MsgHTML($body);
      $mail->Send();
      echo "Message Sent OK</p>\n";
      header("location: ../test.html");
} catch (phpmailerException $e) {
      echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
      echo $e->getMessage(); //Boring error messages from anything else!
}

Important:

重要的是:

Go to google Setting and do 'less secure' applications enables. It will work. It Worked for Me.

转到谷歌设置并执行“不安全”应用程序启用。它将工作。它为我工作。

#4


6  

As others already suggested, you can enable the "less secure" applications or you can simply switch from ssl to tls:

正如其他人已经建议的那样,您可以启用“不太安全”的应用程序,或者您可以简单地从ssl切换到tls:

$mailer->Host = 'tls://smtp.gmail.com';
$mailer->SMTPAuth = true;
$mailer->Username = "xxx@gmail.com";
$mailer->Password = "***";
$mailer->SMTPSecure = 'tls';
$mailer->Port = 587;

When using tls there's no need to grant access for less secure applications, just make sure, IMAP is enabled.

当使用tls时,不需要为不太安全的应用程序授予访问权限,只需确保启用了IMAP。

#5


2  

I face the same problem, and think that I do know why this happens.

我面临着同样的问题,我想我知道为什么会这样。

The gmail account that I use is normally used from India, and the webserver that I use is located in The Netherlands.

我使用的gmail帐户通常来自印度,我使用的webserver位于荷兰。

Google notifies that there was a login attempt from am unusualy location and requires to login from that location via a web browser.

谷歌通知说有一个从一个不同寻常的位置登录的尝试,需要通过web浏览器从那个位置登录。

Furthermore I had to accept suspicious access to the gmail account via https://security.google.com/settings/security/activity

此外,我还必须通过https://security.google.com/settings/security/activity接受对gmail帐户的可疑访问。

But in the end my problem is not yet solved, because I have to login to gmail from a location in The Netherlands.

但最终我的问题还没有解决,因为我必须从荷兰的一个地点登录gmail。

I hope this will help you a little! (sorry, I do not read email replies on this email address)

我希望这能对你有所帮助!(对不起,我没有在此电子邮件地址上看到回复)

#6


1  

If you are G Suit user it can be solved by Administrator

如果您是G Suit用户,可以由管理员解决

  1. Go to your Admin panel
  2. 进入你的管理面板
  3. Type in top search bar «Security» (Select Security with Shield icon)
  4. 输入*搜索栏«安全»(使用盾牌图标选择安全)
  5. Open Basic settings
  6. 开放的基本设置
  7. Goto Less secure apps section
  8. 不那么安全的应用
  9. Press: Go to settings for less secure apps ››
  10. 出版社:去设置不太安全的应用›

And now select one of Radio Button a) Disable access to less secure apps for all users (Recommended) b) Allow users to manage their access to less secure apps c) Enforce access to less secure apps for all users (Not Recommended)

现在,选择一个单选按钮a)禁用对所有用户(推荐)b的不安全应用程序的访问权限,允许用户管理他们的访问权限,以减少对所有用户的安全应用程序的访问权限(不推荐)

Usually It does not working because of a)! And will start working immediately with c) option. b) – option will need more configuration for each user in GSuit

通常它不能工作,因为a)!并将立即开始工作与c)选项。b) -选项将需要对GSuit中的每个用户进行更多的配置

Hope it helps

希望它能帮助

#7


0  

This error is due to more security features of gmail..

这个错误是由于gmail的更多安全特性造成的。

Once this error is generated...Please login to your gmail account..there you can find security alert from GOOGLE..follow the mail...check on click for less secure option..Then try again phpmailer..

一旦产生这个错误……请登录您的gmail帐户。在这里您可以从谷歌找到安全警报。按照邮件…检查点击少安全选项。然后再试一次phpmailer . .

#8


0  

For those who are still unable to get it working, try the following in addition to the method provided by @CallMeBob.

对于那些仍然无法使其正常工作的人,请尝试以下方法以及@CallMeBob提供的方法。

PHP.ini

  1. Go to C:\xampp\php , edit php.ini file with notepad.
  2. 转到C:\xampp\php编辑php。ini文件用记事本。
  3. Press CTRL+F on your keyboard, input sendmail_path on the search bar and click Find Next twice.
  4. 在你的键盘上按下CTRL+F,在搜索栏上输入sendmail_path,然后点击“查找”两次。
  5. Right now, you should be at the [mail munction] section.
  6. 现在,你应该在[邮件功能]部门。

Remove the semicolon for this line: sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Add a semicolon for this line: sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

删除这一行的分号:sendmail_path = "\"C:\xampp\sendmail\sendmail \sendmail = "\" sendmail "。为这行添加分号:sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

SendMail.ini

  • Go to C:\xampp\sendmail, edit sendmail.ini file with notepad
  • 去C:\xampp\sendmail,编辑sendmail。ini文件用记事本
  • Change the following:
  • 改变如下:
  • smtp_server=smtp.gmail.com
  • smtp_server = smtp.gmail.com
  • smtp_port=465
  • smtp_port = 465
  • auth_username=your-gmail-username@gmail.com
  • auth_username = your-gmail-username@gmail.com
  • auth_password=your-gmail-password
  • auth_password = your-gmail-password
  • force_sender=your-gmail-username@gmail.com
  • force_sender = your-gmail-username@gmail.com


Note:
** smtp_port must tally with your those written in your php code.
** Remember to change your-gmail-username and your-gmail-password to whichever account you are using.
**

注意:** smtp_port必须符合您在php代码中编写的那些。**记得将你的“gmail”用户名和“gmail”密码更改为你使用的任何一个账户。* *


Hope this helps! :)

希望这可以帮助!:)