我想發送大量電子郵件,我使用phpmailer類發送電子郵件,他們每個5.2秒發送!這是我的代碼,爲什麼需要這麼長時間?phpmailer採取5秒..但PHP郵件()採取少於1
<?php
//============
require '../includes/PHPMailer-master/PHPMailerAutoload.php';
$time_start = microtime(true);
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Set who the message is to be sent from
$mail->setFrom('[email protected]', 'site');
$mail->CharSet = 'UTF-8';
//Set an alternative reply-to address
$mail->addReplyTo('[email protected]', 'site');
//Set who the message is to be sent to
$mail->addAddress('[email protected]', 'Name');
//Set the subject line
$mail->Subject = 'subject ';
$mail->msgHTML('test');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "Process Time 3: {$time} <br/>";
// Process Time: 1.0000340938568
?>
目前你的時間還包括了'$ mail'的初始化時間等。嘗試在「發送」之前先花時間。 'phpmailer'生成所有頭文件並進行檢查。你有沒有檢查你的服務器的負載? – Cheery 2014-11-06 03:15:30
我已經嘗試把$ time_start = microtime(true);在if語句之前,它仍然說5秒。你是什麼意思檢查服務器的負載? – Jake 2014-11-06 03:17:02
我正在使用谷歌應用程序的業務..我只是使用函數連接到我的Gmail帳戶來傳遞郵件,現在它需要2秒...我認爲谷歌應用程序的業務可能是干擾或什麼? :S – Jake 2014-11-06 03:18:37