0

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

hateful
  • 141
  • 2
  • 13
  • Use the gmail example provided with PHPMailer. It's much quicker to just do that than fix all the mistakes in your script. – Synchro May 03 '16 at 20:42
  • I tried but failed @Synchro – hateful May 03 '16 at 20:47
  • Really, [use this](https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps), do what the links in the error message and [the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting) say to do. – Synchro May 03 '16 at 22:08
  • 1
    Possible duplicate of [Gmail SMTP debug: error "please log in via your web browser"](http://stackoverflow.com/questions/20337040/gmail-smtp-debug-error-please-log-in-via-your-web-browser) – Synchro May 03 '16 at 22:09

1 Answers1

0

Have you read Gmail XOAUTH2 Using Google API Client. Does it pertain to you?

Have you tried ping smtp.gmail.com and make sure you get a response from the server hosting your script?

Can also try port 587 instead.

Kind of just spit balling here based off their troubleshooting guide because I cannot test your set up.

kenhkelly
  • 113
  • 1
  • 8