PHP脚本发送电子邮件没有超时

时间:2014-06-07 05:11:37

标签: php email timeout

我正在使用此代码使用我的服务器向我的列表发送电子邮件。 一段时间后,由于我的电子邮件列表很大,脚本会超时。

有解决这个问题的方法吗?

其他事情我不想重载服务器。是否有我可以添加到我的脚本中的代码,以便在每行之间加载每封电子邮件?

这是我正在使用的PHP脚本


<?php
$emailaddress = file("email-list.txt"); // load from a flat file, assuming 1 email per line in the file
$emailsubject = "[title] title of my email";
$emailbody = file_get_contents("email-content.html");
$fromaddress = "my@3emailserver.com";
$i = count($emailaddress);
$z = 0;

// here we check how many email address's we have, if its is 0, then we don't start the email function
if ($i != 0)
{// start if

// Lets loop until we reach the count from email address arrar
while ($i != $z)
{// start while

// here we send the email to the varables from above, using the email array incrament
mail($emailaddress[$z], $emailsubject, $emailbody, "From: " .$fromaddress. "\nX-Mailer: PHP 4.x");

// lets echo out that the email was sent
echo $z + 1 . " out of " . $i . " emails sent. (" . $emailaddress[$z] . ")<br>";

// increment the array one, so we get a new email address from the array
++$z;

}// end while

}//end if

else
{//start else

// we echo out that no emails where found in the array and end the script
echo "Warning: No emails in array.";

}// end else

?>

2 个答案:

答案 0 :(得分:-1)

使用

// sleep for 10 seconds
sleep(10);
邮件火灾后

答案 1 :(得分:-2)

默认情况下,在php.ini中, max_execution_time 设置为30秒。 (在你的php.ini中查看)

使用 set_time_limit 功能改变时间(0 = NOLIMIT):

set_time_limit(0);

或使用 ini_set 功能:

ini_set('max_execution_time', 0);