[英]using swiftmailer to send bulk email
I'm using swiftmailer to send emails to users when someone registers on my site. 当有人在我的网站上注册时,我正在使用swiftmailer向用户发送电子邮件。 When i want to send out an email to them members i used the same function but just did a while loop of all my members to send an email to all of them.
当我想向他们的成员发送电子邮件时,我使用了相同的功能,但只是对所有成员进行了一段时间的循环,以向他们的所有人发送电子邮件。
The problem im having is this times out at around 120 seconds when its only 10-20% the way through my members table. 我所遇到的问题是,当它仅通过我的成员表的时间的10-20%时,它会在120秒左右超时。 Whats the fastest way round fixing this?
解决此问题的最快方法是什么? Can i add a sleep or???
我可以补充睡眠吗???
The code is 该代码是
<?php
include ('functions.php');
connect();
require_once 'lib/swift_required.php';
$result = mysql_query("SELECT member_id, email, firstname FROM members")
or die ("Error - Something went wrong.");
$i = 1;
while($row = mysql_fetch_array($result)){
echo nl2br("memberid = $row[member_id]");
$useremail = $row['email'];
$user_name = $row['firstname'];
$transport = Swift_SmtpTransport::newInstance('my smtp server', 25);
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance()
->setSubject('my subject')
->setFrom(array('noreply@mydomain.com' => 'mydomain'))
->setTo(array("$useremail" =>" $user_name"))
->setBody(
'<html>' .
'<head></head>' .
'<body>' .
my email body
'</body>' .
'</html>',
'text/html'
);
if ($mailer->send($message)){
mail("registrations@mydomain.com", "ok", "email sent to '$useremail'", "Sent ok");
}
$i++;
}
You should use CRON jobs (linux) or scheduled tasks (windows) to run the php script of sending email every X seconds. 您应该使用CRON作业(Linux)或计划任务(Windows)运行每X秒发送一次电子邮件的php脚本。
Every PHP process has its max execution time, you can raise it, but that will not solve you problem when user list will get even bigger. 每个PHP进程都有其最大执行时间,您可以提高它的执行时间,但是当用户列表变得更大时,这并不能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.