简体   繁体   中英

PHPmailer SMTP connect() failed

I'm getting this when trying to send an email.

Connection: opening to smtp.163.com:25, t=300, opt=array ()
Connection: opened
SERVER -> CLIENT: 220 163.com Anti-spam GT for Coremail System (163com[20141201])
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-mail250-PIPELINING250-AUTH LOGIN PLAIN250-AUTH=LOGIN PLAIN250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2Ur83fsGUCa0xDrUUUUj250-STARTTLS250 8BITMIME
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334 dXNlcm5hbWU6
CLIENT -> SERVER: xxx
SERVER -> CLIENT: 334 UGFzc3dvcmQ6
CLIENT -> SERVER: xxx=
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 Bye
Connection: closed<br>
SMTP connect() failed.
Mailer Error: SMTP connect() failed.

Code :

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = "smtp.mydomain.com";
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = "user@mydomain.com";
$mail->Password = "xxxxxxxx";

$mail->setFrom('user@xxx.com', 'user');
$mail->addAddress('user@xxx.com', 'user');
$mail->Subject = 'PHPMailer SMTP test';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';

if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

If you are hosting with service providers like godaddy, it wont allow you to use SMTP authentication.Kindly check through. If not, you need to check your port address. Try with google smtp in your localhost first.

The issue is using a RFC ignorant mail software. Right here, the server is prompting the client for the username:

SERVER -&gt; CLIENT: 334 dXNlcm5hbWU6

Except it's doing it wrong. It's supposed to send a 334 code followed by the base64 encoded value of: Username: , which is VXNlcm5hbWU6 .

Instead, it's sending the base64 encoded value of username: , which is dXNlcm5hbWU6 . Note the lower cased u . Thus, PHPMailer never sees an appropriate SMTP AUTH prompt and the authentication fails.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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