I have this issue. I have made a signup formular (with a simple backend/controlpanel) in PHP. Travellers go to a page, where they sign up (name, phone-number, e-mail, etc.). Then the signup is stored in a MySQL database. Whenever the controlpanel loads, then it gets all the information from the MySQL databse. It's a signup for different sportscamps, that takes place in different countries. So I'm trying to make a 'E-mail the participants that signed up for destination X'-method, which then somehow sends an e-mail to all of the people, who signed up for destination X. I've considered a couple of different ways to do it, but can't figure out, which is easier to make or better.
1) To make a 'SELECT theEmailAddress FROM tablename WHERE 1', that gets all the e-mail addresses. Thereafter make a PHP mail-function, for each of them. Then make a contact-formular looking HTML form, that sends to each of those e-mails. I just thought that this solution seem kinda clumsy, or what?
2) I have made a Mailchimp-account. I was also considering to use Mailchimps API (I haven't used it and it seems kinda complex) to make a button in the controlpanel, so a List is created for each destination. Then the message should be sent from Mailchimp. The massive upside about this way of doing it is, that there wouldn't be a struggle with spam-filters (since Mailchimps emails rarely gets caught in the spam-filter.
3) Some other clever way of doing it, that I haven't thought of yet. I'm open for any kind of suggestion.
Thank you.
The following code will keep sending mails until all rows (that match the criteria) are processed.
$query = mysql_query("SELECT theEmailAddress FROM tablename WHERE 1");
while ($row = mysql_fetch_assoc($query)) {
$to = $row['theEmailAddress'];
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
Most mailservers are however blocking the php mailer, or mark it as spam. So I'd recommend looking into an SMTP mailer class. There are a lot of different types, so you will have to pick one yourself. But then you can connect to a gmail (or other SMTP account) and have your mail sent through there. It makes things more reliable.