I have a working mailer script which has already started sending out mails. We need to send an email message to approximately 5,000 email addresses. I have a few problems though.
1.) It’s sending out really slow. I’m guessing it’s the embedding? The image is 300+kb big, is it supposed to slow the sending down like that? The mail is sending like 3 emails per minute. And it’s going to take a lot of time if we want to send the email to 5000 recipients. The code is something like this:
$mail->AddEmbeddedImage("rocks.png", "my-attach", "rocks.png");
$mail->Body = 'Embedded Image: <img src="cid:my-attach">
2.) We have registered for an smtp which will not limit us to 100 emails per day. It’s something like pay as you go and it keeps track of the messages sent. When I checked the log, there were duplicated messages. There were some recipients which were sent twice, the weird thing is it just tries to send the message twice and then moves to the next email addresses. The problem about that is that it consumes our limit from the smtp service and also adds too many queues in the mail which makes the sending even longer. My send code is something like:
if(isset($fromaddress)){
do{
$mail->AddAddress($row['email']);
$mail->Send();
$mail->ClearAddresses();
}
while ($row = mysql_fetch_array ($result));
}
And my query is something like :
SELECT * from email where id > 200
You may be wondering about my query. I was in need of having to send the mails from where it left off from timing out due to connection problems so I made a id column and I assign the number as the id of the last email address the mail was sent to. I don’t know if that was wise but that was what I had at the moment. Any suggestions?
Depending on how PHPMailer is built, yes, it may very well slow it down so much. The reason is pretty simple: if you’re mailing as an attachment, the mail call has to know the exact byte size of the mail. It does this by preparing it, which includes reading the image in its entirety. This is a pretty small delay on one email, but if it has to do it 5000 times… Consider queueing and a worker approach.
Add a field to your database, call it
mailSent, type BIT. Every time you send one, set it to 1 for the appropriate row. To select emails,SELECT * FROM mails WHERE mailSent='0' LIMIT 100.