Forum Moderators: phranque

Message Too Old, No Replies

email script question (php mysql)

how to use sendmail fast

         

rjames

1:41 am on Jun 19, 2005 (gmt 0)

10+ Year Member



Hi,

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.

globalissa

9:36 am on Jun 19, 2005 (gmt 0)

10+ Year Member



I run a commercial php script (i wrote it) which can send about 500 email notes with the same content to 500 different addresses in under 15 seconds. The speed in part depends on the server hardware so your mileage may vary. The only substantive difference from your description is that the script injects the .csv recipient list into the bcc field, the 'to' field is newsletter@domain.com or whatever. So if you emulate the sending of data via the bcc list then there is only one interation of the note and the server seems to like that better. Again, your mileage may vary with your serving conditions.

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.

rjames

1:48 pm on Jun 19, 2005 (gmt 0)

10+ Year Member



Thanks Globalissa for your reply,

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.

globalissa

6:40 pm on Jun 19, 2005 (gmt 0)

10+ Year Member



Well yes you need to be careful about SPAM. We only use our software with an opt in subscriber list and use the recipient list with care in distributing infrequent company newsletters with actual real news.

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.

rocknbil

4:26 pm on Jun 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The speed issue is not one of mysql. I have a client with a 400,000+ subscriber base and we run his mailers on a cron job. The process takes several hours.

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.

rjames

4:52 pm on Jun 20, 2005 (gmt 0)

10+ Year Member



Thanks to all of you for your replies :)

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? :(