I just started using phpmailer to send out emails using smtp. All was working fine until i was told to develop a system for sending out a batch of emails (currently upto 1000).
problem is when i'm looping through (each email is personalised) it gets a couple and then slows right down, until its virtually at a standstill. i only get about 10-15 done before it seems to stop.
here is what i have:
can anyone help me out? Any help is appreciated
//enquiries/bookings have been assigned whip out some emails
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp.fasthosts.co.uk"; // SMTP servers
$mail->Subject = "Thank you for your recent enquiry";
while ($row = $db->GetRow($db->result))
$enqID = $row -> EnqID ;
$contact = $row -> Name ;
$email = $row -> Email ;
$site = $row -> Site ;
echo "<br>Name:" . $users[$i][name] . " email: " . $users[$i][email] . " tel: " . $users[$i][tel];
echo "<br> Assigned: " . $enqID . " Contact: " . $contact . " Email: " . $email . " Site: " . $site . "<br>It was Assigned and Email Sent<br>";
// query to asssign the enquiry to the selected user
mysql_query("INSERT INTO Assignments (EnqID, Name) VALUES ($enqID, $users[$i][name])") ;
// query to update the unassigned status of the enquiry to assigned
mysql_query(" UPDATE Enquiries SET State = 'Assigned' WHERE EnqID = " . $enqID ) ;
$mail->From = $users[$i][email];
$mail->FromName = $users[$i][name];
$message = " <p>Hi " . $contact . ": </p>
<p>Thank you for your recent enquiry with " . $site . ".</p>
<p>Your enquiry has been passed onto " . $users[$i][name] . " who will be handling your query.</p>
<p>We will try to reply to your query as soon as possible, however, if you require any further help in the meantime you can contact " . $users[$i][name] . " in the following ways:</p>
<p>Email: " .$users[$i][email] . "<br />
Telephone: " . $users[$i][tel]. "</p>
<p>Thank you<br />
<p>THE " . strtoupper($site) . " TEAM</p> " ;
$mail->Body = $message ;
$mail->AltBody = $message ;
Last edited by Sid3335; 06-02-2006 at 07:58 AM.
Using PHP via a webserver to send mutliple emails is notoriously prone to timing out. For spammers, the typical solution is to send the message to multiple recipients at once, typically by using a long list of Bcc recipients. Obviously this is not possible since in your case each message is customized for each recipient. Also, you are doing two database queries per email, adding additional processing.
Frankly, I suspect your best solution would be to look at developing a non-web-based script for this that can be run via the command line or perhaps as a cron job. However, this may eliminate PHP as an option if it's installed as a web module and not in CLI mode.
I would make sure you make a connection to the db inside your while loop. I've done this before and what happens is my connection is lost to my db since the connection was only for x seconds.
This may help.
isn't it pretty inneficient to connect for every message, considering i could have thousands eventually (probably not, but....).
Isn't there any programs like phpmailer that can handle batch emailing?
any other alternatives?
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)