最荒谬的是两个服务器上的相同脚本不起作用,但另一个服务器上的脚本不起作用。
这是我的尝试(来自PHPMailer示例):
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 3;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.live.com";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "xxxx@xxxx.com";
$mail->Password = "xxxxx";
$mail->setFrom('from@example.com', 'First Last');
$mail->addReplyTo('replyto@example.com', 'First Last');
$mail->addAddress('whoto@example.com', 'John Doe');
$mail->Subject = 'PHPMailer SMTP test';
$mail->Body = 'Test';
$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!";
}
输出调试:
2017-06-08 08:43:55 Connection: opening to smtp.live.com:587, timeout=300, options=array ()
2017-06-08 08:44:58 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.live.com:587 (Connection timed out) [/home/public_html/work/PHPMailer/class.smtp.php line 292]
2017-06-08 08:44:58 SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
我认为这取决于服务器的配置。我需要查看哪个参数?
提前致谢
答案 0 :(得分:0)
无需使用 $mail->isSMTP();
评论此......
$mail->isSMTP();
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require '../PHPMailerAutoload.php';
require_once('../class.phpmailer.php');
$mail = new PHPMailer;
//$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "smtp.live.com";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "xxxx@xxxx.com";
$mail->Password = "xxxxx";
$mail->setFrom('from@example.com', 'First Last');
$mail->addReplyTo('replyto@example.com', 'First Last');
$mail->addAddress('whoto@example.com', 'John Doe');
$mail->Subject = 'PHPMailer SMTP test';
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$body = file_get_contents('test.html');
$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
$mail->Timeout = 60; // set the timeout (seconds)
$mail->SMTPKeepAlive = true; // don't close the connection between messages