473,883 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_t ime 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.*******.e du";
$mail->Mailer = "smtp";
$mail->AddBCC($_SESSI ON['bcc'],"SURVEY BCC");
$mail->SMTPKeepAliv e = 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_E MAIL'];
$mail->FromName = $row['DEPT_CONTACT'];
$mail->AddReplyTo($ro w['DEPT_CONTACT_E MAIL'],$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($ro w['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($co nn);

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

Mar 28 '06 #1
8 13774
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*******@attgl obal.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*******@attgl obal.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
twanglee
2 New Member
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
twanglee
2 New Member
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
3803
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
4180
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 addresses to which I would like to send a mass email occasionally. The group will never be much larger than 500 email addresses and will occasionally be about half that size. I have written a simple HTML interface and PHP backend to process the...
3
3139
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 application. The ideal situation would be that returning mail triggers a script that removes the address of said message's recipient from the list. I'm thinking about a script that checks the pop3 server of the reply-to address and parses the inbox to...
4
3867
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 but whenever I try to send these emails I receive different errors e.g. 'too many recipients' Does using CDONTs to dynamically send emails eliminate this problem? Are you aware of any cheap programs out there that will meet my needs? I would also...
2
1599
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 plans on selling this 'solution' to clients with substantially higher demands; at least in the low 1000's.. Would you consider asp suitable for this purpose? Would be a
4
12643
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 levels (TL1, TL2, and TL3): Here is what I'm trying to accomplish:
3
1716
by: Gil \(Asp.net Developer\) | last post by:
1
3118
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 now , I have found some very interesting classes and I also have my own scripts, I just want to know all the options available and why one is better of another .
3
2666
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 send Mail Please suggest me how to send these personalised newsletter... through PHP
0
10757
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10860
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10420
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9583
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7975
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5804
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6002
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4620
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3239
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.