473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Avoiding timeout while mass mailing

I have to send out 2500 e-mails to student survey recipients. The
e-mails will appear to come from the specific departments that they
belong to. I'm utilizing PHPmailer in the scripts I wrote to
accomplish this. I've written several pages to edit emails utilizing
placeholders so each individual email can be personalized for the
recipient, and selection page to choose recipients from the database.
The code I've written works just fine for small batches, but I'm unable
to test the mass mail as I don't have a suitable test list of email
addresses. I've adjusted the max_execution_time in the php.ini to 300
seconds, which should probably be long enough to send them all. I'll
start off sending in small batches, but eventually will want to just
send them out all at once for future mailings. Can you look at the
code below and suggest any other timeout issues that might appear?
Thanks all.

require("class.phpmailer.php");
require("dbconn.php");

session_start();

$mail = new PHPMailer();

$mail->Subject = $_SESSION['subject'];
$mail->Host = "smtp.*******.edu";
$mail->Mailer = "smtp";
$mail->AddBCC($_SESSION['bcc'],"SURVEY BCC");
$mail->SMTPKeepAlive = true;

$enabled_only = true;
$rs = getRecips($conn, $enabled_only); //Record set contains recipient
data

$i=0;

foreach ($rs as $row) {
$mail->From = $row['DEPT_CONTACT_EMAIL'];
$mail->FromName = $row['DEPT_CONTACT'];
$mail->AddReplyTo($row['DEPT_CONTACT_EMAIL'],$row['DEPT_CONTACT']);

// HTML body
$body = processHtmlBody($_SESSION['body'], $row, true);
// Plain text body (for mail clients that cannot read HTML)

$text_body = processTextBody($_SESSION['body'], $row, true);

$mail->Body = $body;
$mail->AltBody = $text_body;
$fullname = $row['FIRST_NAME']." ".$row['LAST_NAME'];
$mail->AddAddress($row['EMAIL'], $fullname);
if(!$mail->Send()) {
$_SESSION['send_result'][$i] = "Mail error sending to " .
$row['EMAIL'] . "<br />\nError Message: ".$mail->ErrorInfo."<br />\n";
}
else {
$_SESSION['send_result'][$i] = "Mail sent to ".$row['EMAIL']."
from department: ".$row['DEPT_NAME']."<br />\n";
}
$i++;
// Clear all addresses and reply-tos for next loop
$mail->ClearAddresses();
$mail->ClearReplyTos();

}
$mail->SmtpClose();
clearRecips($conn);

header("location: http://localhost:8080/phpmailer/mailresult.php");

Mar 28 '06 #1
8 13687
Try adding set_time_limit(0); to the top of your script. This sets the
execution timelimit for this script to be infinite. Alternativly, you
could rewrite the script to send the email in batches to squeeze under
the normal timelimit restrictions.

-Jake

Mar 28 '06 #2
I've considered breaking it up into batches, but right now am relying
on the redirect and session variable to show send results and errors.
Maybe I should drop that information into a log file instead? If I
batched it, would that require some user input to continue the process,
or could it be set up to just load an intermediate page which redirects
back to the sending page if more emails are in the queue?

Jake wrote:
Try adding set_time_limit(0); to the top of your script. This sets the
execution timelimit for this script to be infinite. Alternativly, you
could rewrite the script to send the email in batches to squeeze under
the normal timelimit restrictions.

-Jake


Mar 28 '06 #3
What about writing a script such way that it send like 1000 mail and
sleep for 1 sec and start again

Mar 31 '06 #4
What about writing a script such way that it send like 1000 mail and
sleep for 1 sec and start again

Mar 31 '06 #5
Satya wrote:
What about writing a script such way that it send like 1000 mail and
sleep for 1 sec and start again


sleep() doesn't reset the timeout clock, so this doesn't work. In fact, since
you're sleeping during part of your total allowed time, you'll get even less done.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 31 '06 #6

Jerry Stuckle wrote:
Satya wrote:
What about writing a script such way that it send like 1000 mail and
sleep for 1 sec and start again


sleep() doesn't reset the timeout clock, so this doesn't work. In fact, since
you're sleeping during part of your total allowed time, you'll get even less done.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


So I went with the suggestion to use set_time_limit(0) at the top of
the script. That works just fine. I can send 2500 e-mails plus bcc
each one to a separate account in 4-6 minutes. To insure that there is
some record of what has been sent if the program were to crash, I open
a log file before the main loop, and record a success or error message
in the if (! $mail->send() ) { } else { } clause. It works great!

I've also managed to embed images in the mails as well, so if you are
looking for a mass mailer, I highly recommend the open source PHPmailer
class.

Apr 4 '06 #7
hi i'm new to this forum and have a problem i own a small business and wish to xpand but i'm havin problems sending bulk emails can any one please help me
May 4 '06 #8
hi i'm new to this forum and have a problem i own a small business and wish to xpand but i'm havin problems sending bulk emails can any one please help me
May 4 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sharif Tanvir Karim | last post by:
How would I emal say, 10 email addresses, using mail()? -- Sharif Tanvir Karim http://www.onlyonxbox.net
6
by: Jeffrey Silverman | last post by:
Hi, all. Sorry, first off, for the kidna weird selection of crossposted groups, but this question touches on aspects of discussion in each of the groups. So I have a group of around 500 email...
3
by: somaboy mx | last post by:
I'm putting together a mass mailing application for sending out newsletters from a site admin area (no spam). I'm wondering how I can automate the removal of bounced addresses in this...
4
by: Aplus | last post by:
Hi, I am web admin for a school's website and now and again I have to send emails to those who have signed the guestbook and have consented to this. Now I have a distribution list within outlook...
2
by: Espen | last post by:
Hi, I just took over maintaining an ASP codebase for sending out newsletters by mail, as well as basic subscriber maintenance. Thing is working ok today, with ~200 subscribers, but there are...
4
by: Manoj K | last post by:
Environment:- Framework 1.1 DB: SQL Server 2000 (SQL Provider) OS: Windows 2000 Language: VB.NET I'm trying to do mass inserts/updates. Using Transactions. The table hierarchy contains 3...
3
by: Gil \(Asp.net Developer\) | last post by:
1
by: johnny | last post by:
hi all, I would like to understand which are the best ways to send bulk mailings like for newsletters and so on ( not spamming, always to receivers who opt-in ). I am not looking for code for...
3
by: cordial_camaraderie | last post by:
I need to send 30,000 emails to our NewsLetter Subscriber, I tried to use our hosting Site and for the worst part We we banned and our site was stopped. I am using PHP script, mail() function to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.