Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

Instead of the MailChimp API (which is designed for sending email campaigns to lists of people) I'd recommend the MailChimp-made Mandrill API. It's an API for sending one-off and transactional emails like you've described. Using Mandrill would have the advantage of reliable deliverability (as you mentioned) and give you data on who's opening and clicking your emails.

In this case you would have a script similar to @Neograph734 but instead of using PHP's mail() function you'd use the Mandrill API.

@Neograph734 is also correct, you can do this with straight PHP too.

The MailChimp API has the features you need. One way to do it would be to create Interest Groups particular to each country. Using Groups alone will let you send an email to the whole list, and customise the content by the group that each user is subscribed to. Used in conjunction to Segments, you can write to just the members of an interest group.

The MailChimp API can appear complex, but it is modelling an inherently complex problem. The API is carefully designed to have just the functionality needed.

You might also be able to compromise by using your program to generate lists which you then manually import into MailChimp and send the emails from the web UI. It depends on how large the list is and how often you will be emailing.

MailChimp is the way to go if you want rock-solid emailing and tracking. Just takes some time to learn.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top