Cannot understand PHPMailer debug log - php

I am trying to use PHPMailer,
I have enabled opensll and it loads
I use XAMPP and PHPStorm
SERVER -> CLIENT: 220 smtp.gmail.com ESMTP z88sm9679wrb.26 - gsmtp
CLIENT -> SERVER: EHLO PhpStorm 2016.1.2
SERVER -> CLIENT: 501-5.5.4 HELO/EHLO argument "PhpStorm 2016.1.2" invalid, closing connection.501 5.5.4 https://support.google.com/mail/?p=helo z88sm9679wrb.26 - gsmtp
SMTP ERROR: EHLO command failed: 501-5.5.4 HELO/EHLO argument "PhpStorm 2016.1.2" invalid, closing connection.501 5.5.4 https://support.google.com/mail/?p=helo z88sm9679wrb.26 - gsmtp
CLIENT -> SERVER: HELO PhpStorm 2016.1.2
SERVER -> CLIENT:
SMTP ERROR: HELO command failed:
SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not connect to SMTP host.
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Here is my code
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587; //ssl : 465 --- tls:587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "te.professionnel#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "*****";
//Set who the message is to be sent from
$mail->setFrom('te.professionnel#gmail.com', 'Abou May');
//Set an alternative reply-to address
//$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('abou.may#gmail.com', 'Abou May');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I have read lots of documentation, bu I cannot figure out the reason of this error.
Can someone givz me an example code?
What is wrong ?
I read all the section on troubleshooting
"SMTP Error: Could not connect to SMTP host."
This may also appear as SMTP connect() failed or Called Mail() without being connected in debug output. This is often reported as a PHPMailer problem, but it's almost always down to local DNS failure, firewall blocking (for example as GoDaddy does) or other issue on your local network. It means that PHPMailer is unable to contact the SMTP server you have specified in the Host property, but doesn't say exactly why. It can also be caused by not having the openssl extension loaded (See encryption notes below).

I also encounter this problem before.This is not the problem of PhpMailer.But in fact,this is cause by Gmail smtp is denied the connection,therefore you cant connect.
In order for you to solve this problem,you need to
Configure an OAuth2 app in Google Developer Console.
Step is here
If you still cant manage to solve it,I recommend you to use Postmark as your mail server,it is a lot easier to set up the connection.
Here is the guide for the setup of Postmark.For me is a lot easier.Hope it helps.

This is nothing to do with gmail or oauth.
The problem is this line:
CLIENT -> SERVER: EHLO PhpStorm 2016.1.2
When PHPMailer's SMTP client says hello to a server like this, by default it passes the name returned by the internal method serverHostname(). Normally this returns something like localhost.localdomain, or mymac.local (i.e. a real host name), but if that's not available, it tries to figure out what to use - and one of the things it falls back to is the $_SERVER['SERVER_NAME'] super global, which in this case contains PhpStorm 2016.1.2 (I'd guess because you're testing using PHPStorm's built-in web server?), which is not a valid host name, hence the error. This isn't a good move on PHPStorm's part and is probably worth reporting as a bug.
Fortunately you can override automatic determination of the client hostname using the Helo property, which exists precisely for occasions like this. Just do this:
$mail->Helo = 'my.host.name';
substituting either whatever your real host name is, or by calling some other function which gives a usable result.

Related

Error: SMTP Error: Could not authenticate [duplicate]

I created an account on Gmail (becase the previous one was giving me the same problem) so that my application could send emails using google smtp server.
I'm using the PHPMailer library and asked it to show any log errors.
I always get a message similar to this. It vary a little, sometimes it is shorter and sometimes longer, depending on my configuration
2015-08-01 05:07:01 CLIENT -> SERVER: EHLO www.lavile.com
2015-08-01 05:07:01 CLIENT -> SERVER: AUTH LOGIN
2015-08-01 05:07:01 CLIENT -> SERVER: Y29udGF0by5sYXZpbGVAZ21haWwuY29t
2015-08-01 05:07:01 CLIENT -> SERVER: WXlhdUgxMnM= 2015-08-01 05:07:01 SMTP ERROR: Password command failed: 534-5.7.9 Please log in with your web browser and then try again. Learn more at 534 5.7.9 https://support.google.com/mail/answer/78754 b16sm3352387qga.48 - gsmtp
2015-08-01 05:07:01 SMTP Error: Could not authenticate.
2015-08-01 05:07:01 CLIENT -> SERVER: QUIT
2015-08-01 05:07:01 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting string(82) "SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting"
This is my script
$mail->Username = "myusername#gmail.com";
$mail->Password = "mypassword";
$mail->IsSMTP(); // enable SMTP
$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->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->SetFrom($mail->Username, 'Contato Lavile');
$mail->addAddress($mail->Username, "Contato Lavile");
$mail->Subject = 'Novo contato no site Lavile';
$mail->Body = $text;
$mail->IsHTML(true);
$mail->AltBody = $text;
Also GMAIL is sending automatic emails to myself alerting me that a new login attempt was blocked. I even changed some settings on my gmail to make it work but everything failed
Any idead? Do you know what could be happening?
I would recommend to actually read the error message:
... 534-5.7.9 Please log in with your web browser and then try again. Learn more at 534 5.7.9 https://support.google.com/mail/answer/78754 b16sm3352387qga.48 - gsmtp
When reading this site you will find something about supporting client which provide only less secure methods of authorization. Your client is one of these so follow the link to learn how to enable support for these application in gmail.
You can send email without own smtp server:
1) get recipient mx hostname from dns
2) send email to port 25
Not saying this is necessarily what happened to the topic opener but I had exactly this same error today. And the reason I got it was because I created a new e-mail address and you first need to log in to Gmail via the browser once before you can use smtp.
After logging in to the Gmail web client via the browser and going over the initial flow I was able to send via the smtp endpoint.
$mail->Host = "smtp.gmail.com"; should be something like:
$mail->Host = "mail.yourdomain.com";//replace your domain name

PHPmailer - AOL smtp connection errors

Does anyone know the correct setting for using PHPMailer with AOL. The code below worked with outlook.com but aol.com keeps refusing it. The code is as follows;
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.aol.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxxxxxxxxxxxxxxxxx#aol.com'; // SMTP username
$mail->Password = 'yyyyyyyyyyyyyyyyyyyyyy'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('xxxxxxxxxxxxxxxxxxx#aol.com', 'Barry AOL');
$mail->addAddress('xxxxxxxxxxxxxxxxxxx#gmail.com', 'Barry gmail'); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject - sent from AOL.com ';
$mail->Body = 'This is the HTML message body <b>in bold!</b> - sent from AOL.com ';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients - sent from AOL.com ';
$mail->send();
echo 'Message has been sent from AOL.com ';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
I'm getting the following error messages from PHPMailer and aol.com;
2018-04-22 21:44:56 SERVER -> CLIENT: 521 5.2.1 : AOL will not accept delivery of this message.
2018-04-22 21:44:56 SMTP ERROR: DATA END command failed: 521 5.2.1 : AOL will not accept delivery of this message.
SMTP Error: data not accepted.
Message could not be sent. Mailer Error: SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: : AOL will not accept delivery of this message. SMTP code: 521 Additional SMTP info: 5.2.12018-04-22 21:44:56 CLIENT -> SERVER: QUIT
2018-04-22 21:44:56 SERVER -> CLIENT:
2018-04-22 21:44:56 SMTP ERROR: QUIT command failed:
I'm assuming I must have gotten the server, port and SMTPSecure settings wrong but can't figure what they should be. By the way, with the proper changes to server, port and SMTPSecure the code works for outlook.com.
This is running on MS Windows 10 desktop with Apache/2.4.27 (Win64) and PHP Version 7.0.9.
This article has the official SMTP server to use (unhelpfully hidden under the "POP3 & IMAP" section), and you appear to be using the correct details.
It may be a spam-filtering filtering problem; try setting $mail->XMailer = ' '; (there's a space in those quotes) to suppress the identification of PHPMailer.
This error seems to be very subjective on AOL's side - there are a zillion search results if you search for that error message, and you can see others sharing their frustration here and here
Otherwise I'd recommend contacting AOL postmaster support.
Try taking the word 'AOL' out of the display-name portion of your From address. Since most clients only show the display-name when listing mail, AOL doesn't like names that look like they might be from official AOL addresses.

SMTP Mail Error on both server and localhost

I have an email account with zoho.com that is configured and running. On GoDaddy, I am hosting my site and have configured my mail such that any mail sent via the website is received at zoho mail. This setup worked fine till last week. Now I am getting errors and I have no idea what triggers them.
I get the following error on GoDaddy server when I try to send a mail to any account:
SMTP -> ERROR: Failed to connect to server: Connection refused (111)
SMTP Error: Could not connect to SMTP host.
AND the following error on localhost for the same script:
SMTP -> ERROR: Failed to connect to server: A connection attempt
failed because the connected party did not properly respond after a
period of time, or established connection failed because connected
host has failed to respond. (10060)
I have tried the following to correct the errors (on both localhost and GoDaddy) by:
Changed port number to 25,465 and 587
Changed smtp server from smtp.zoho.com to relay-hosting.secureserver.net
Changed ssl to tls and vice versa
Removed the SMTPSecure Parameter altogether
Increased timeout variable to 1000
Verified that the mail accounts exist and are up and running
Verified that mail accounts have valid passwords and usernames.
A working demo can be found here.I have echoed the errors out as well as the message to be sent just for the purpose of this question.
Edit 1 I commented out "$mail->Host="smtp.zoho.com" and got the following error:
SMTP -> FROM SERVER: SMTP -> FROM SERVER: SMTP -> ERROR: EHLO not
accepted from server: SMTP -> FROM SERVER: SMTP -> ERROR: HELO not
accepted from server: SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedSMTP Error:
Could not authenticate.
Does this mean that GoDaddy is not authenticating the credentials?
Edit 2: My settings on zoho mail are:
Incoming server: poppro.zoho.com, Port: 995, SSL (POP)
Incoming server: imappro.zoho.com, Port: 993, SSL (IMAP) Outgoing
server: smtp.zoho.com, Port: 465, SSL (POP and IMAP)
Try Using Following Code:
<?php
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$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
try {
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
#require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 3;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.zoho.com';
// use
// $mail->Host = gethostbyname('smtp.zoho.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
//$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "care#subillion.com";
//Password to use for SMTP authentication
$mail->Password = "care#subillion";
//Set who the message is to be sent from
$mail->setFrom('care#subillion.com', 'care#subillion.com');
//Set an alternative reply-to address
#$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->AddAddress($touser, $username);
$mail->Subject = $subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($msg);
echo $msg;
//$mail->AddAttachment('img/logo-dark.png');
$mail->Send();
// echo "Message Sent OK</p>\n";
} catch (Exception $e) {
// echo $e->getMessage(); //Boring error messages from anything else!
}
?>
EDIT: if still not working then you must have proper configuration settings as below(as example):
Non-SSL Settings
(NOT Recommended)
Username: jon#domain.com
Password: Use the email account’s password.
Incoming Server: mail.domain.com
IMAP Port: 143
POP3 Port: 110
Outgoing Server: mail.domian.com
SMTP Port: 25
Authentication is required for IMAP, POP3, and SMTP.

Can't send email with php using gmail - Authorising error

I'm new to PHP and trying to build a website with registration form. Users should receive an email with a confirmation link (since I have a free hosting server I am trying to use gmail server). The thing is I'm struggling with the email php code. I am trying to use PHPMailer functions as follows:
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require 'PHPMailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "MYEMAIL#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "MYPASSWORD";
//Set who the message is to be sent from
$mail->setFrom('example#example.com', 'Name S');
//Set an alternative reply-to address
$mail->addReplyTo('example#example.com', 'Name S');
//Set who the message is to be sent to
$mail->addAddress('email#gmail.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML("HELLo");
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
I tried both ports 587 and 465. Also tried both ssl and tls. Every time I try to run the code I get the following error:
SERVER -> CLIENT: 220 smtp.gmail.com ESMTP gw4sm17090153wjc.45 - gsmtp
CLIENT -> SERVER: EHLO spec.dr-manny.co.uk SERVER -> CLIENT:
250-smtp.gmail.com at your service, [185.27.134.36]250-SIZE
35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN
OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250
SMTPUTF8 CLIENT -> SERVER: AUTH LOGIN SERVER -> CLIENT: 334
VXNlcm5hbWU6 CLIENT -> SERVER: bWFubnlzYWVkaUBnbWFpbC5jb20= SERVER ->
CLIENT: 334 UGFzc3dvcmQ6 CLIENT -> SERVER: a2luZ29uZW1vaDk5 SERVER ->
CLIENT: 534-5.7.14
Please log in via your web browser
and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14
https://support.google.com/mail/answer/78754 gw4sm17090153wjc.45 -
gsmtp SMTP ERROR: Password command failed: 534-5.7.14
Please log in via your web browser
and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14
https://support.google.com/mail/answer/78754 gw4sm17090153wjc.45 -
gsmtp SMTP Error: Could not authenticate. CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 closing connection gw4sm17090153wjc.45 -
gsmtp SMTP connect() failed.
Error: SMTP connect() failed.
Also, I got an email from Gmail with the subject "Someone has your password". I opened the email and found this "
Hi Manny,
Someone just used your password to try to sign in to your Google Account MYEMAIL#gmail.com, using an application such as an email client or mobile device."
I received this email about 15 mins after I ran the php page.
I turned off "2-step verification" and turned off "allow less secure apps". Nothing seems to help. Anyone please could help me?
I had the same issue last year: the code (VB.Net) was OK, so where the credentials. The problem was that gmail didn't like that some app in a web server far away (my hosting) where trying o use your same username.
I fixed it (in two different occasions) by:
Logging in gmail once from that server (using remote desktop).
Logging in here https://accounts.google.com/DisplayUnlockCaptcha from my pc to "unlock" remote connections.
After that test your code again.

How to send contact form data via e-mail (or other options)

I'm wondering what options are available to send an e-mail to my e-mail account when someone fills out my contact form. My setup is on AWS with an instance of Microsoft 2012 Server running.
I have IIS, PHP5.6 and have a local SMTP server running and working (I've successfully sent test e-mails on my local environment). It seems no matter what I attempt to try and send my contact form data via e-mail, it fails.
I've tried using Pear and PHPMailer, both always throw errors. I've tried troubleshooting these errors for the past 8 hours via the documentation and scouring websites (including Stack Overflow). I'm stuck and don't know what to attempt next. Is there something I'm missing like another option? This is my first time setting up my own server and it's been a huge hassle (although I think it will pay off in the end once I understand everything more). If PHPMailer is what I need to be using I can paste in my code, I've been working of the gmail example.
The current error I have with PHPMailer:
2016-01-01 01:45:32 CLIENT -> SERVER: EHLO www.xeno-studios.com
2016-01-01 01:45:32 CLIENT -> SERVER: STARTTLS 2016-01-01
01:45:32 SMTP Error: Could not connect to SMTP host. 2016-01-01
01:45:32 CLIENT -> SERVER: QUIT 2016-01-01 01:45:32 SMTP ERROR: QUIT
command failed: 2016-01-01 01:45:32 SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer
Error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
//example.php
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
//$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = gethostbyname('smtp.gmail.com');
$mail->Port = 587; // or 587
$mail->IsHTML(true);
$mail->Username = "myemail#gmail.com";
$mail->Password = "gmailpass";
$mail->SetFrom("myemail#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("recipient#gmail.com");
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
This must have been failing because of the Google smtp server. Apparently they have been changing the way people get authenticated which could be part of the reason I was getting errors. I ended up looking into AWS SES for my mail server setup and used those credentials in my PHPMailer function. It was rather easy to setup and worked like a charm.

Categories