简体   繁体   English

SMTP Gmail服务器PHP邮件程序不起作用

[英]smtp gmail server php mailer not working

I know this question has been asked many a times before. 我知道这个问题已经问过很多次了。 But the solutions didn't seem to help me . 但是这些解决方案似乎并没有帮助我。 So hereby I am posting my code: 因此,我在此发布我的代码:

<?php
require("class.phpmailer.php");
require("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); 
$mail->Host="smtp.gmail.com";
$mail->SMTPDebug=1; 
$mail->SMTPAuth=true;
$mail->SMTPSecure="ssl";
$mail->Port=465;  
$mail->Username ="me@gmail.com";
$mail->Password="mypassword";
$mail->AddAddress("to@yahoo.co.in");
$mail->SetFrom("me@gmail.com", "myname");
$mail->AddReplyTo("someone@gmail.com","someone");
$mail->Subject="Greetings from ME";
$mail->Body="Greeting !! I am glad you received this message";
$mail->WordWrap=50;
if($mail->send())
{
echo "Mail sent successfully";
}
else
{
echo "Sorry mail could not be sent because of error ".$mail->ErrorInfo;
}
?>

The SMTP Debug is: SMTP调试是:

CLIENT -> SERVER: EHLO messengerclick.byethost3.com 2015-07-26 12:49:42 CLIENT -> SERVER: AUTH LOGIN 2015-07-26 12:49:42    
CLIENT -> SERVER: Y2hlcm9ja3oxOUBnbWFpbC5jb20= 2015-07-26 12:49:42  
CLIENT -> SERVER: Y2hldGFucm9ja3MxOQ== 2015-07-26 12:49:43  
SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 sc16sm22415466wjb.28 - gsmtp 2015-07-26 12:49:43 
SMTP Error: Could not authenticate. 2015-07-26 12:49:43 
CLIENT -> SERVER: QUIT 2015-07-26 12:49:43  SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Sorry mail could not be sent because of error SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

I have enabled access for unknown apps on my gmail account. 我已启用对我的Gmail帐户的未知应用程序的访问权限。 I have also clicked on continue on this link http://www.google.com/accounts/DisplayUnlockCaptcha after signing in. I am running this from my byethost account. 登录后,我还单击了继续,然后单击此链接http://www.google.com/accounts/DisplayUnlockCaptcha 。我是通过我的byethost帐户运行此链接的。 It is working fine for smtp.mail.yahoo.com smtp.mail.yahoo.com正常工作

Please help me know what I am doing wrong. 请帮助我知道我在做什么错。

If you're sure your password is correct, you can try these troubleshooting tips: 如果您确定密码正确,则可以尝试以下故障排除提示:

  • If you've turned on 2-Step Verification for your account, you might need to enter an App password. 如果您已为帐户启用“两步验证”,则可能需要输入应用密码。
  • Sign in to your account from the web version of Gmail at https://mail.google.com . 通过https://mail.google.com从Web版本的Gmail登录到您的帐户。 Afterwards try accessing your messages in your mail app again. 然后,尝试再次在邮件应用中访问您的消息。
  • If you're still having problems, visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. 如果仍然有问题,请访问http://www.google.com/accounts/DisplayUnlockCaptcha并使用您的Gmail用户名和密码登录。 If necessary, enter the letters in the distorted picture. 如有必要,请在变形的图片中输入字母。
  • Your mail app might not support the latest security standards. 您的邮件应用程序可能不支持最新的安全标准。 Learn how to allow less secure apps access to your account. 了解如何允许安全性较低的应用访问您的帐户。
  • Make sure your mail app isn't set to check for new email too frequently. 确保您的邮件应用未设置为过于频繁地检查新电子邮件。 If your mail app checks for new messages more than once every 10 minutes, the app's access to your account could be blocked. 如果您的邮件应用程序每隔10分钟检查一次新邮件不止一次,则该应用程序对您帐户的访问可能会被阻止。
  • Try changing your password according to our tips on creating a strong password. 根据我们创建强密码的提示,尝试更改密码。

Source . 来源

Here , you can allow less secure apps. 在这里 ,您可以允许不太安全的应用。 Click on Turn On to allow less secure apps having your username and password. 单击“打开”以允许安全性较低的应用使用您的用户名和密码。

If you are facing similar issue 如果您遇到类似的问题
Try this out: 试试看:

If you had your password last modified before 2014 change your password to stronger one. 如果您在2014年之前最后一次修改密码,请将密码更改为更强的密码。

It worked for me 对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM