PHPMailer failed send to GMAIL

时间:2016-05-03 20:09:40

标签: php linux phpmailer

Battling PHPMailer for sending emails, not if my server configuration this wrong or my settings either mail or if my code is wrong. Here is the code I use

$nombre = $_POST['name'];
$email = $_POST['email'];
$mensaje = $_POST['mensaje'];
require 'vendor/PHPmailer/PHPMailerAutoload.php';

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

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

$body .= "<b>Hola</b>";

try {
     //$mail->Host       = "mail.gmail.com"; // SMTP server
      $mail->SMTPDebug  = 1;                     // 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   = "test@mydomain.com";  // GMAIL username
      $mail->Password   = "12345678";            // GMAIL password
      $mail->AddAddress($email, 'abc');
      $mail->SetFrom('nhernandez@fullmecanic.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";
} catch (phpmailerException $e) {
      echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
      echo $e->getMessage(); //Boring error messages from anything else!
}

Config php.ini

[mail function]
SMTP = localhost
smtp_port = 25
extension=php_openssl.dll

Also configure my gmail account for non-secure everything I found in forums and it does not work and I get this application:

2016-05-03 19:58:37 CLIENT -> SERVER: EHLO mydomain.com 2016-05-03 19:58:37 CLIENT -> SERVER: AUTH LOGIN 2016-05-03 19:58:37    CLIENT -> SERVER: bmhlcm5hbmRlekBmdWxsbWVjYW5pYy5jbA== 2016-05-03 19:58:37  CLIENT -> SERVER: ODEzODI5My4u 2016-05-03 19:58:38  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 j80sm38623ywg.48 - gsmtp 2016-05-03 19:58:38 SMTP Error: Could not authenticate. 2016-05-03 19:58:38 CLIENT -> SERVER: QUIT 2016-05-03 19:58:38  SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message Sent OK

If you look carefully, I after sending an email, print "Message Sent OK" and this appears, but also appears authentication error

1 个答案:

答案 0 :(得分:0)

您是否阅读过Gmail XOAUTH2 Using Google API Client。它与你有关系吗?

您是否尝试过ping smtp.gmail.com并确保从托管脚本的服务器获得响应?

也可以尝试端口587。

根据他们的troubleshooting guide,这只是吐痰,因为我无法测试你的设置。