Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

php - SMTP connect() failed phpmailer

<?php

require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer();

$mail->SMTPDebug = 1;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.mail.yahoo.com';  // Specify main and backup SMTP servers
$mail->SMTPSecure = "ssl";
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'myemail';                 // SMTP username
$mail->Password = 'mypass';                           // SMTP password
//  $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to

$mail->From = '[email protected]';
$mail->FromName = 'abc';
$mail->addAddress('[email protected]');               // Name is optional


//$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
//  $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if (! $mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

I have tried gmail also but it keeps giving me error SMTP connect() failed.

here is the error

    2015-05-16 07:28:09    CLIENT -> SERVER: EHLO localhost
2015-05-16 07:28:09    CLIENT -> SERVER: AUTH LOGIN
2015-05-16 07:28:10    CLIENT -> SERVER: bWF0ZWVuX3VsX2hhcUB5YWhvby5jb20=
2015-05-16 07:28:10    CLIENT -> SERVER: c2hhaGlkYWZyaWRpMW1hcmNoMTk5MQ==
2015-05-16 07:28:11    SMTP ERROR: Password command failed: 501 Syntax error in arguments
2015-05-16 07:28:11    SMTP Error: Could not authenticate.
2015-05-16 07:28:11    CLIENT -> SERVER: QUIT
2015-05-16 07:28:11    SMTP connect() failed.

https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Message could not be sent.

Mailer Error: SMTP connect() failed. 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should really read what the troubleshooting guide says - that's why the link to it is included in the error output. Set SMTPDebug = 2 so you can see what the server says and it will probably tell you what's wrong.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...