2

I need to send a maximum of about 300 bulk emails every other day and so I'm considering making a PHP application to do that for me using the PHP mail() function.

I need to be able to have variables in the message body corresponding to the addresse's domain name / links on their site and the email is only sent once which is why I'm not using Mailchimp because I don't want an unsubscribe button or anything like that on the email.

Is this feasible using PHP mail() and is there anything I should do to avoid getting blacklisted?

dlofrodloh
  • 1,728
  • 3
  • 23
  • 44
  • 1
    If you're sending bulk emails and you don't have an unsubscribe link you're going to aggravate your users and probably run afoul of a whole heap of laws. Mailchimp doesn't add those to be jerks, they add them because they make sense. – tadman Mar 12 '14 at 23:30
  • It's actually [illegal](http://en.wikipedia.org/wiki/CAN-SPAM_Act_of_2003#Unsubscribe_compliance) to send emails to people regularly without an unsubscribe option. – Marty Mar 12 '14 at 23:31
  • But if I'm only sending them one email (as in my question) then what's the point of having an unsubscribe button? This is for broken link building, I'm notifying the webmaster that they have a broken link on their site and giving them the replacement. I only send this once to the webmaster and they never hear from me again. – dlofrodloh Mar 12 '14 at 23:32
  • @Marty - that would be illegal in the US, but I don't think we know where the OP is based. OP, what country would you be emailing from? – halfer Mar 12 '14 at 23:47
  • The UK. But again, I'm not sending them regularly to people. It's only 1 email notifying the webmaster of broken links on their site and a replacement. I'm currently doing this manually and it's wasting a lot of my time. – dlofrodloh Mar 12 '14 at 23:48
  • I think your first line threw me off with *"every other day"* - ignore me :-) – Marty Mar 12 '14 at 23:52

1 Answers1

1

You can absolutely achieve that using PHP's mail() function.

However, if you plan to use the HTML format for your emails, i highly recommend using one of the prepared libraries around. My favourite is SwiftMailer.

When it comes to blacklisting, your best bet is either one of these:

  • Use a clearly whitelisted proxy
  • Use a different proxy for each email, rotating as many proxies as are available to you
  • Make sure you have varying delays in between the sending of your emails

The latter can be accomplished be either one of these methods:

  • Create a script that just sleeps for certain amount of time between sending the messages

Example

foreach($recipients as $rcp) {
   mail($rcp, 'subject', 'content');
   sleep(rand(1,20));
}

This will send a message from your queue and leave a varying delay of 1 to 20 seconds in between.

If you use a method such as this one, please make sure that your maximum execution time is configured properly, otherwise the script will die after a certain amount of time.

ini_set('max_execution_time', '3600');

This will have your script run for a maximum of one hour.

Your other option:

  • Use a cron job that periodically executes your script

In this case you could write your current recipient to a file and increase that counter on each execution of the script.

I think in your case the previous method would be more suitable.

Please note

Sending bulk or spam can be illegal under certain conditions. As it was discussed in the comments to your question, you should always provide an unsubscribe option (e.g. a link) in your message.

Also note that it is hard to tell which recipient servers use which method in order to identify suspicious clients / client hosts. Using a method such as the one supplied above is no guarantee that the target server won't blacklist you.

SquareCat
  • 5,699
  • 9
  • 41
  • 75
  • Cool, thanks for the info. I'll use the sleep method in the script, good idea. For the record again, this is for broken link building where I'm notifying webmasters of broken links on their site. I only send one email to them and then they never hear from me again, so the unsubscribe link doesn't apply. This is just to save me from sending the emails manually. – dlofrodloh Mar 12 '14 at 23:45