tags:

views:

399

answers:

6

i have an application on my site where people can sign up to receive newsletters, and then someone in a paid group can write and send one immediately to everybody who signed up...

...meaning that i need an efficient way to loop through my database of subscribers and mail them copies of the email using php.

clearly, there is the mail() function....i could put that in a loop...is there a better way?

+3  A: 

PEAR's mail queue?

The Mail_Queue class puts mails in a temporary container, waiting to be fed to the MTA (Mail Transport Agent), and sends them later (e.g. a certain amount of mails every few minutes) by crontab or in other way.

Jonathan Sampson
yeah ive heard about that too actually...i tried installing pear and using it but had a little bit of trouble (my site travels between subdomain names, and having a stationary library gets confusing for me)...is it hard to use and figure out though in general?
johnnietheblack
A: 

Try phplist (Homepage) if you need a full featured newsletter and mailinglist manager

theomega
+1  A: 

I'd suggest finding a way to loop through, and remembering who you mailed already, because if it becomes a large list of people, you script might end and you'd have to reload it.

I have done it once using AJAX, gave me a great way to track where I was in the sending proces. Counted how many people to mail, put the id's in an array, had javascript loop and make seperate calls to a php-mail-page...

-edit- You can have a script in php, with a simple while loop, but then you should add a check in the DB to see if a mail was already sent to one person. If the script exceeds memory usage, just reload the page, and it will only sent to the ones that haven't received it yet...

Jasper
cool im down for that....you mean with just the mail() function?
johnnietheblack
send one mail per recipient instead of just bcc it?
OIS
yeah, makes them feel special. Gives you the ability to adress them personally in the mail itself, too. Plus, the mail is less likely to be tagged as spam... or so I have been told
Jasper
+3  A: 

You could use the BCC header option and send one email with a Blind Carbon Copy list of all the subscribers. So build the BCC string in the loop and send one email using mail()

Snippet from the PHP manual...

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

Replace 'Bcc: [email protected]' with $mySubscribersList

PaulBM
i feel you on this, would it leave ANY trace of other people? because i have their security to worry about...
johnnietheblack
BCC is fine for that, it's what it's designed for. Each person appears to get a separate email, without anyone elses details in the header. Unlike CC.
PaulBM
+1  A: 

Following on @paulbm's answer, why not create an alias on your server that points to all current email addresses? A short procmail script can prevent anyone other than one authorized sender using the alias.

It'd make mailing's easy, and rebuilding the list with new/changed email address would be pretty simple, too.

warren
A: 

This is exactly the same problem I am presently trying to find an answer for. A simple seeminly simple task that is not so simple. My situation is as follows:

I have a website which I own. It is hosted in our office on a WAMP server (Windows, Apache, MySQL, PHP). We are now needing to automatically send out bulk emails. Our ISP is 1and1.com; all emails from here go out thru them via SMTP.

My Question: Say our site is a real estate site where people can list their property for sale. The scenario is as follows: Say 400 Members are interested in buying a house on Main Street. If a new listing is posted by a Member on Main Street, the site needs to send out 400 emails, one to each of the pre-acknowledged interested recipients. This event may happen as often as once every ½ hour.

We had tried to use the PHP mail() function to handle this. As you know, the mail() function works great in sending out 1 or 2 emails. Trying to send out 400 in a loop will not work reliably. I can stuff all the periodic email info into MySQL via PHP, no problem But need help automatically sending it out.

At this point I am ready to pull my hair out trying to solve to write a PHP script to accomplish this task. If you have an idea please let me know. If you see this request several months downs the line, hit me up, I will probably have an answer and script for you. site = www.prospectexpo.net

All the best, DJ

David J.