目前我正在尝试使用 PHPMailer 发送带有文件附件的电子邮件。不幸的是,每个脚本执行大约需要 60 秒来发送一条消息。这是我的代码:
$time_start = microtime(true);
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
//$body = file_get_contents('contents.html');
//$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$address = "xxx@gmail.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "PHPMailer Test Subject via Sendmail, basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML("html body");
$mail->AddAttachment("abc.txt"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
echo 'Total Execution Time:'.$execution_time.' Sec';
执行时间不是很依赖文件大小,但是 60 s 的脚本执行时间对我来说有点太多了。我怎样才能解决这个问题?