I've searched every where for a solution for this problem, and I found many tips, but without success. I'm using PHPMailer to use external smtp (gmail or sendpulse). I've tried all possible ports, ideas, ... this is the code that I use:
$<?php
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 6;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Username = "sender@gmail.com";
$mail->Password = "password";
$mail->setFrom('sender@gmail.com', 'fsender lsender');
$mail->addAddress('receiver@gmail.com', 'freceiver lreceiver');
$mail->Subject = 'PHPMailer SMTP test';
$mail->msgHTML(file_get_contents('mail.txt'), dirname(__FILE__));
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Debug:
Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()<br>
Connection: opened<br>
SMTP -> get_lines(): $data is ""<br>
SMTP -> get_lines(): $str is "220-myaccount.arvixeshared.com ESMTP Exim 4.87 #1 Sun, 19 Mar 2017 00:57:26 -0400 "<br>
SMTP -> get_lines(): $data is "220-myaccount.arvixeshared.com ESMTP Exim 4.87 #1 Sun, 19 Mar 2017 00:57:26 -0400 "<br>
SMTP -> get_lines(): $str is "220-We do not authorize the use of this system to transport unsolicited, "<br>
SMTP -> get_lines(): $data is "220-myaccount.arvixeshared.com ESMTP Exim 4.87 #1 Sun, 19 Mar 2017 00:57:26 -0400 220-We do not authorize the use of this system to transport unsolicited, "<br>
SMTP -> get_lines(): $str is "220 and/or bulk e-mail."<br>
SERVER -> CLIENT: 220-myaccount.arvixeshared.com ESMTP Exim 4.87 #1 Sun, 19 Mar 2017 00:57:26 -0400 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.<br>
CLIENT -> SERVER: EHLO myaccount.arvixeshared.com<br>
SMTP -> get_lines(): $data is ""<br>
SMTP -> get_lines(): $str is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]"<br>
SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]"<br>
SMTP -> get_lines(): $str is "250-SIZE 52428800"<br>
SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]250-SIZE 52428800"<br>
SMTP -> get_lines(): $str is "250-8BITMIME"<br>
SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]250-SIZE 52428800250-8BITMIME"<br>
SMTP -> get_lines(): $str is "250-PIPELINING"<br>
SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]250-SIZE 52428800250-8BITMIME250-PIPELINING"<br>
SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN"<br>
SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN"<br>
SMTP -> get_lines(): $str is "250-STARTTLS"<br>
SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS"<br>
SMTP -> get_lines(): $str is "250 HELP"<br>
SERVER -> CLIENT: 250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP<br>
CLIENT -> SERVER: STARTTLS<br>
SMTP -> get_lines(): $data is ""<br>
SMTP -> get_lines(): $str is "220 TLS go ahead"<br>
SERVER -> CLIENT: 220 TLS go ahead<br>
CLIENT -> SERVER: EHLO myaccount.arvixeshared.com<br>
SMTP -> get_lines(): $data is ""<br>
SMTP -> get_lines(): $str is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]"<br>
SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]"<br>
SMTP -> get_lines(): $str is "250-SIZE 52428800"<br>
SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]250-SIZE 52428800"<br>
SMTP -> get_lines(): $str is "250-8BITMIME"<br>
SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]250-SIZE 52428800250-8BITMIME"<br>
SMTP -> get_lines(): $str is "250-PIPELINING"<br>
SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]250-SIZE 52428800250-8BITMIME250-PIPELINING"<br>
SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN"<br>
SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN"<br>
SMTP -> get_lines(): $str is "250 HELP"<br>
SERVER -> CLIENT: 250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [xx.xx.xx.x]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250 HELP<br>
Auth method requested: UNKNOWN<br>
Auth methods available on the server: PLAIN,LOGIN<br>
Auth method selected: LOGIN<br>
CLIENT -> SERVER: AUTH LOGIN<br>
SMTP -> get_lines(): $data is ""<br>
SMTP -> get_lines(): $str is "334 XXXxxxxxxXXx"<br>
SERVER -> CLIENT: 334 XXXxxxxxxXXx<br>
CLIENT -> SERVER: XXxxxxXxXXxxXXXxXXxxXXxxXxXxxX==<br>
SMTP -> get_lines(): $data is ""<br>
SMTP -> get_lines(): $str is "334 XXXxxxxxxxXx"<br>
SERVER -> CLIENT: 334 XXXxxxxxxxXx<br>
CLIENT -> SERVER: YW5pczE5OTY=<br>
SMTP -> get_lines(): $data is ""<br>
SMTP -> get_lines(): $str is "535 Incorrect authentication data"<br>
SERVER -> CLIENT: 535 Incorrect authentication data<br>
SMTP ERROR: Password command failed: 535 Incorrect authentication data<br>
SMTP Error: Could not authenticate.<br>
CLIENT -> SERVER: QUIT<br>
SMTP -> get_lines(): $data is ""<br>
SMTP -> get_lines(): $str is "221 myaccount.arvixeshared.com closing connection"<br>
SERVER -> CLIENT: 221 myaccount.arvixeshared.com closing connection<br>
Connection: closed<br>
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting<br>
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I'm sure that password is correct, I tried this code in another account and works fine. I contacted my host but without a solution, what I've noticed is that is SERVER -> CLIENT & CLENT -> SERVER are the same (localhost):
SERVER -> CLIENT: 220-myaccount.arvixeshared.com ESMTP Exim 4.87 #1 Sun, 19 Mar 2017 00:57:26 -0400 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.<br>
CLIENT -> SERVER: EHLO myaccount.arvixeshared.com<br>
Where in the account where the code works SERVER -> CLIENT (smtp.gmail.com) & CLIENT -> SERVER (localhost):
SERVER -> CLIENT: 220 smtp.gmail.com ESMTP x29xx4280503xxx.16 - gsmtp<br>
CLIENT -> SERVER: EHLO myaccount.hawkhost.com<br>
Can someone help me to solve this issue, thanks.
Update: activating certificate verification and using php 7.0
username@domain.com [~/path/e]# /usr/local/php70/bin/php -f gmail.php
2017-03-19 12:58:06 Connection: opening to smtp.gmail.com:587, timeout=300, options=array (
)
2017-03-19 12:58:06 Connection: opened
2017-03-19 12:58:06 SMTP -> get_lines(): $data is ""
2017-03-19 12:58:06 SMTP -> get_lines(): $str is "220-myaccount.arvixeshared.com ESMTP Exim 4.87 #1 Sun, 19 Mar 2017 08:58:06 -0400
"
2017-03-19 12:58:06 SMTP -> get_lines(): $data is "220-myaccount.arvixeshared.com ESMTP Exim 4.87 #1 Sun, 19 Mar 2017 08:58:06 -0400
"
2017-03-19 12:58:06 SMTP -> get_lines(): $str is "220-We do not authorize the use of this system to transport unsolicited,
"
2017-03-19 12:58:06 SMTP -> get_lines(): $data is "220-myaccount.arvixeshared.com ESMTP Exim 4.87 #1 Sun, 19 Mar 2017 08:58:06 -0400
220-We do not authorize the use of this system to transport unsolicited,
"
2017-03-19 12:58:06 SMTP -> get_lines(): $str is "220 and/or bulk e-mail.
"
2017-03-19 12:58:06 SERVER -> CLIENT: 220-myaccount.arvixeshared.com ESMTP Exim 4.87 #1 Sun, 19 Mar 2017 08:58:06 -0400
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
2017-03-19 12:58:06 CLIENT -> SERVER: EHLO myaccount.arvixeshared.com
2017-03-19 12:58:06 SMTP -> get_lines(): $data is ""
2017-03-19 12:58:06 SMTP -> get_lines(): $str is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [23.91.70.2]
"
2017-03-19 12:58:06 SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [23.91.70.2]
"
2017-03-19 12:58:06 SMTP -> get_lines(): $str is "250-SIZE 52428800
"
2017-03-19 12:58:06 SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [23.91.70.2]
250-SIZE 52428800
"
2017-03-19 12:58:06 SMTP -> get_lines(): $str is "250-8BITMIME
"
2017-03-19 12:58:06 SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [23.91.70.2]
250-SIZE 52428800
250-8BITMIME
"
2017-03-19 12:58:06 SMTP -> get_lines(): $str is "250-PIPELINING
"
2017-03-19 12:58:06 SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [23.91.70.2]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
"
2017-03-19 12:58:06 SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN
"
2017-03-19 12:58:06 SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [23.91.70.2]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
"
2017-03-19 12:58:06 SMTP -> get_lines(): $str is "250-STARTTLS
"
2017-03-19 12:58:06 SMTP -> get_lines(): $data is "250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [23.91.70.2]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
"
2017-03-19 12:58:06 SMTP -> get_lines(): $str is "250 HELP
"
2017-03-19 12:58:06 SERVER -> CLIENT: 250-myaccount.arvixeshared.com Hello myaccount.arvixeshared.com [23.91.70.2]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2017-03-19 12:58:06 CLIENT -> SERVER: STARTTLS
2017-03-19 12:58:06 SMTP -> get_lines(): $data is ""
2017-03-19 12:58:06 SMTP -> get_lines(): $str is "220 TLS go ahead
"
2017-03-19 12:58:06 SERVER -> CLIENT: 220 TLS go ahead
2017-03-19 12:58:06 Connection failed. Error #2: stream_socket_enable_crypto(): Peer certificate CN=`*.arvixeshared.com' did not match expected CN=`smtp.gmail.com' [/home/username/path/p/class.smtp.php line 368]
2017-03-19 12:58:06 SMTP Error: Could not connect to SMTP host.
2017-03-19 12:58:06 CLIENT -> SERVER: QUIT
2017-03-19 12:58:06 SMTP -> get_lines(): $data is ""
2017-03-19 12:58:06 SMTP -> get_lines(): $str is "221 myaccount.arvixeshared.com closing connection
"
2017-03-19 12:58:06 SERVER -> CLIENT: 221 myaccount.arvixeshared.com closing connection
2017-03-19 12:58:06 Connection: closed
2017-03-19 12:58:06 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
It looks like your ISP is intercepting and redirecting your SMTP traffic to their own server. You are asking to connect to smtp.gmail.com
, but it is connecting to myaccount.arvixieshared.com
, where of course your credentials do not work.
This is covered in the troubleshooting guide that the error message links to.
It should be failing to connect because the TLS certificates do not match, so you are either using an old PHP version or you have disabled certificate verification, neither of which are a good idea.