的PHPMailer发送电子邮件,然后挂起(在Windows,XAMPP)
当本地主机上使用的PHPMailer(Windows的XAMPP),电子邮件发送确定,但剧本永远挂起 - 没有刷新。的PHPMailer发送电子邮件,然后挂起(在Windows,XAMPP)
PHP自己的mail()函数工作正常,而PHPMailer的工作正常使用sendmail,所以这只是SMTP模式的问题。
奇怪的是,与Xdebug的步进通过时,
I get "Fatal error: Maximum execution time of 0 seconds exceeded" in the console when I reach __destruct()
虽然我可以一步通过这一点,这让我刷新并在浏览器中反映的错误。而且,一旦我这样做了,我可以刷新浏览器,并且新电子邮件将正常发送,没有错误,也不会挂起。退出调试模式并返回挂起行为。
注:在php.ini: max_execution_time=60
max_input_time=60
require_once "PHPMailerAutoload.php";
$to = "[email protected]";
$to_name = "Me";
$from_name = "fromName";
$from = "[email protected]";
$subject = "This is a test email from php " . strftime("%T", time());
$message = "phpmailer using smtp";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "# censored #";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Hostname = "myhost";
$mail->Username = '# censored #';
$mail->Password = '# censored #!';
$mail->FromName = $from_name;
$mail->From = $from;
$mail->addAddress($to, $to_name);
$mail->Subject = $subject;
$mail->Body = $message;
$result = $mail->send();
echo $result ? 'Sent' : 'Error: ' . $mail->ErrorInfo;
与PHPMailer的开发本地主机服务器上的工作时,我有过类似的问题。经过大量研究,我克服这个问题的方式是手动要求PHPMailer类和SMTP类,例如:
require('../ vendor/phpmailer/phpmailer/class.phpmailer.php'); require(“../ vendor/phpmailer/phpmailer/class.smtp.php”);
作为使用PHPMailerAutoload.php没有完全要求所有类所需要,并投掷例外。您是否有现场服务器进行测试,因为我发现了许多答案,例如“在正常运行和完全部署时工作正常”,但这是一个有风险的选择。
我设法需要手动将文件克服“最大执行时间”。但是,在使用窗口和XAMPP的情况下,悬挂是间歇性的,有时它会立即发送,有时可能需要一段时间才能处理脚本。不知道这是否会奏效,但值得一试。
而且这个我研究了“class.smtp.php”文件中的PHPMailer,发现这个:
$this->edebug('Connection: opened', self::DEBUG_CONNECTION);
// SMTP server can take longer to respond, give longer timeout for first read
// Windows does not have support for this timeout function
if (substr(PHP_OS, 0, 3) != 'WIN') {
$max = ini_get('max_execution_time');
// Don't bother if unlimited
if ($max != 0 && $timeout > $max) {
@set_time_limit($timeout);
}
stream_set_timeout($this->smtp_conn, $timeout, 0);
}
在评论这上面定义它指出:“Windows不支持超时功能”。也许从这种理解中可以帮助你消除可能性?
我试过要求你说的类,没有运气。电子邮件总是立即发送,但脚本之后挂起,与之前一样。此外,单步执行代码时,我发现您发布的代码段被跳过,因为它应该在Windows机器上。 – brotherhutch