Collected Solutions.... PHP Bulk Email - Best Practices?
Results 1 to 4 of 4

Thread: Collected Solutions.... PHP Bulk Email - Best Practices?

  1. #1
    Senior Member
    Join Date
    Apr 2003
    Location
    Flanders Fields
    Posts
    5,833

    Collected Solutions.... PHP Bulk Email - Best Practices?

    Back to the Top
    HOW DO I SEND BULK EMAIL WITH PHP?

    This seems to be a common request around here and I didn't find enough info in the 37 posts relating to bulk email. I thought I would start a thread to point out the pitfalls and try to provide solutions. I hope you'll over look any shortcomings because I'm just trying to make an informative thread and get answers. These are the pitfalls I've found:

    1 - MAIL() DOESN'T WORK
    mail() is a basic way to send email using PHP. If it doesn't work on your server then you need to configure PHP properly. Talk to your sysadmin or read here or tell your sysadmin to read the php documentation:
    http://php.net/mail

    If your sysadmin is mean or some network situation prevents you from using the php mail() command, you will need some code to let you send mail some other way. An excellent tool which connects to an SMTP server just like your mail client is PHPMailer:
    http://phpmailer.sourceforge.net/

    QUESTION: Can anyone recommend a class like PHPMailer which supports queuing of large numbers of emails? I think PHPList does but it's totally overkill if you're just trying to queue up some emails within an existing site.


    2 - EMAIL IS BOUNCING
    Assuming the email gets sent from my server it is inevitable that some will bounce. In that case, an email server (usually the desination server) will generate a bounce message or Delivery Status Notification which gets sent to the email listed in the RETURN-PATH header of your mail message. You should probably also set FROM. How do you do this? It usually depends on how you sent the mail in the first place. Check the docs on your mail-sending method. If you're hankering for a more technical read, you can read RFC 3461.

    QUESTION: How does one process the bounces? Obviously you need to be able to check the email account where all the bounces go and correlate messages there with addresses in your send list. [NEED MORE INFO]


    3 - EMAIL DISAPPEARS
    Some mail you send never arrives. No errors, no trace. In this case you need to make sure your server is actually sending it by checking the mail logs (ask your sys admin). If it is in fact sent by your server then it may be getting SPAM FILTERED. This is a tough situation and should be solved on a case by case basis. Two very helpful things you can do are to make sure the email address in your RETURN-PATH and FROM headers in your messages match the domain returned from a reverse lookup of your mail server's IP address. If this is impossible, check into setting up a Sender Policy Framework. If that doesn't help, call the domains that are blocking your email ask them why.

    QUESTION: Other suggestions? Did I miss anything?


    4 - TOO MANY EMAILS, SCRIPT IS TIMING OUT
    PHP scripts usually have a time limit. This can be a definite problem if you have a lot of emails to send. Depending on your PHP setup, you might just be able to add this line to the top of your email-sending script:
    PHP Code:
    set_time_limit(0); 
    HOWEVER, if your server is in safe mode, that won't work. Talk to your sys admin - s/he might change the PHP ini file and put a longer value.


    5 - SCRIPT *STILL* TIMING OUT
    If you can't get your mean old sys admin to change the value or if you have more emails to send than can be sent in a day, then you have a significant problem that requires pretty special treatment like a faster email server, a faster connection for your server, or something fairly drastic. Try putting a *detailed* post in the coding forum.
    Last edited by Weedpacket; 03-30-2007 at 08:00 AM.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

  2. #2
    Senior Member
    Join Date
    Apr 2003
    Location
    Flanders Fields
    Posts
    5,833
    oh...and

    6 - MY SCRIPT IS HACKED! HELP I'M AN OPEN RELAY!
    This has happened to me once and was due to the fact that bots/hackers had found my script and were bypassing my form and posting directly to my form handling script. Generally this was accomplished on my sites by injecting CC or BCC email headers into a form where a user entered a return email address. I was able to prevent this in most cases by screening the form input data for line breaks in the email address.

    I would highly recommend the use of PHPMailer or some other class in this case to prevent these sorts of things because the developers are on guard against such things.
    Last edited by sneakyimp; 02-07-2007 at 11:33 PM.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

  3. #3
    Member
    Join Date
    Aug 2007
    Location
    Scottsdale, AZ
    Posts
    71
    Quote Originally Posted by sneakyimp View Post
    Back to the Top

    5 - SCRIPT *STILL* TIMING OUT
    If you can't get your mean old sys admin to change the value or if you have more emails to send than can be sent in a day, then you have a significant problem that requires pretty special treatment like a faster email server, a faster connection for your server, or something fairly drastic. Try putting a *detailed* post in the coding forum.
    One way to get around this kind of issue is to setup a que of some sort. I had to setup a script that sends out 200 emails at a time. After the script is done with the first 200 emails, it calls itself and processes the next 200 and so forth until it sends all emails in the que.

  4. #4
    Senior Member
    Join Date
    Apr 2003
    Location
    Flanders Fields
    Posts
    5,833
    Lately I've run across issues where PHPMailer doesn't work. PEAR mail appears to have more thorough SMTP implementation.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •