简体   繁体   English

PHP脚本发送电子邮件而不会超时

[英]PHP Script to send email with no timeout

I am using this code to send email to my list using my server. 我正在使用此代码通过服务器将电子邮件发送到我的列表。 after a while as my list of email is large, the script get timeout. 过一会儿,因为我的电子邮件列表很大,脚本会超时。

is there a solution to this problem? 有解决这个问题的办法吗?

other thing i don't want to overload the server. 其他我不想让服务器超载。 Is there a code i can add to my script to load each email with a time between each line? 我是否可以在脚本中添加代码,以在每行之间添加时间来加载每封电子邮件?

here is the php script i am using 这是我正在使用的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

?>

use 采用

// sleep for 10 seconds
sleep(10);

after mail fire. 邮件失火后。

By default in php.ini, max_execution_time is set to 30 seconds. 默认情况下,在php.ini中, max_execution_time设置为30秒。 (check this in your php.ini) (在您的php.ini中检查)

Use set_time_limit function to alter that time (0=NOLIMIT): 使用set_time_limit函数更改该时间(0 = NOLIMIT):

set_time_limit(0);

Or use ini_set function: 或使用ini_set函数:

ini_set('max_execution_time', 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM