gpt4 book ai didi

某些服务器的 PHPMailer 超时

转载 作者:行者123 更新时间:2023-12-05 04:10:29 30 4
gpt4 key购买 nike

从昨天开始,我拼命尝试使用最新版本的 PHPMailer 运行一个非常简单的电子邮件脚本。

最荒谬的是,同一个脚本在两台服务器上不起作用,但在另一台服务器上却起作用。

这是我的尝试(来自 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

我认为这取决于服务器的配置。我必须查看哪个参数?

提前致谢

最佳答案

无需使用: $mail->isSMTP();

Comment This ... $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

关于某些服务器的 PHPMailer 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44430890/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com