Forum Moderators: phranque
I have a php script which fetches records from a mysql database and sends short email messages to the subscriber's email address. Basically it iterates through all the records found for a particular query and for each record found, it sends an email message using the sendmail command of php.
The problem is that this process takes very long (up to 2 minutes for about 100 records. Is there a way achieve this in a different way which is faster?
Any help would be appreciated.
For high volume sends you may want to move to a dedicated mail processor software, you didn't say the total number of notes you're sending ... there's no real substitute for good serving hardware and software.
Currently Im only processing about 200 email addresses. However, I expect this number to grow into about a thousand or more.
I read somewhere that if I inject all of the recepients emails into the bcc field, their mail clients will most likely tag the email as spam.
As for mail clients, it would be poor programming style to reject a note due to use of the bcc field wouldn't it? Such an approach would be an uncharacteristic departure from software system design principles.
The problem is the mail server, and it's capacity to manage huge loads. That is what is time consuming.
But I think I've already addressed your question: when your list gets large, set up a mailer and save it to disk, then send it via a timed cron job at a low server load time, like 2 or 3 AM.
Something else you will find, a cron job can manage much more than one sent immediately via the web. At "some point," a large mailing sent from a web-based interface just dies after a certain point. Been working with system admins on this issue for a while now and don't have an answer yet.
It's also server-specific. I have one client with a 4,000+ subscriber base, his send-it-now mailers (from his web interface) work FINE. And some of those are with attachments. I have another that dies after 1200-1500, but if we run that command line or via cron it works fine.
But you're a long way off from having to worry about it. Depending on your server ,a mysql-driven DB, through perl or PHP, should be fine up to 5K or so. After that you may have to pump up your server.
Maybe you guys can help me if I explain my situation a little better:
Our business is to alert our subscribers instantly (within 1-2 minutes) with, for example a news headline. The subscribers have opted to receive these alerts on their email addresses as well as mobile phone sms addresses (in an email format ie: 9999999999@cingularME.com). I am currently using a web interface with php script which does the job fine, but I guess our hosting providor's email servers are a bit slower than normal and the list of about 100 emails take up to 2-3 mintutes to process. Theres nothing wrong with the script as far as I know:
-------------------------------------
$headers = 'From: email@example.com' . "\r\n" .
'Reply-To: email@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mysql_select_db($database_authenticate, $authenticate);
$result = mysql_query("SELECT email, mobile FROM users WHERE sub = $sub");
if(mysql_num_rows($result) > 0)
{
$count = 0;
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC))
{
$to = $row['email'] . ', ';
$to .= $row['mobile'];
mail($to, $subject, $message, $headers);
$count++;
}
echo "myResult=$count Emails Sent.";
}
else
{
echo "myResult=Email Submissions Failed.";
}
------------------------------------------
Again, Is there any way to speed things up? :(