【发布时间】:2014-07-28 10:29:14
【问题描述】:
我正在使用此代码使用我的服务器向我的列表发送电子邮件。 一段时间后,由于我的电子邮件列表很大,脚本会超时。
这个问题有解决办法吗?
我不想让服务器超载的其他事情。有没有我可以添加到脚本中的代码来加载每封电子邮件,每行之间有一个时间?
这是我正在使用的 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
?>
【问题讨论】:
-
脚本是否在命令行中运行?