【问题标题】:PHP Script to send email with no timeout无超时发送电子邮件的 PHP 脚本
【发布时间】: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

?>

【问题讨论】:

  • 脚本是否在命令行中运行?

标签: php email timeout


【解决方案1】:

使用

// sleep for 10 seconds
sleep(10);

邮件触发后。

【讨论】:

    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 2011-09-16
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 2011-04-28
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多