Sending emails through PHP mail is slow

php
12,777

Solution 1

Check your /etc/hosts file.

If you have an entry for your external IP address that points to your local hostname for example:

75.23.123.21 my-server-hostname

Change it to:

127.0.0.1 my-server-hostname

Then try running the PHP mail() function again.

Solution 2

I'm going to say if you have 1 million subscribers you need to reach, perhaps it's better that you not do yourself. Instead, why not use a service like Mailchimp who's primary focus is on delivering email.

Think about the advantages:

  1. You don't worry about bandwidth, infrastructure and maintenance.

  2. You get comprehensive analytics on how your email campaigns are performing and the health of your list - you say you have a million emails but how many of them bounce back? How many are opened? what is the open rate per country?, how many are marked as spam etc?

  3. Depending on what your business is, you can A/B test your campaigns and optimize reads/clicks/conversions.

You will obviously pay extra for this service which is separate from your current hosting costs, but with Mailchimp you pay for what you use. Also if you can reach a million humans, you probably figured out how to monetize it (if not, you really should). So using a 3rd party service might pay for itself.

Mailchimp is one of many services out there (I mention it because I use it and very happy with it). You might want to check out SendGrid, Campaign Monitor and Aweber and weigh your pros and cons.

Probably not the answer you were expecting, but this is just my $0.02.

P.S: Mailchimp also gives you an API so you can seamlessly integrate your app with their services.

Solution 3

From the PHP Manual

It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.

For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.

Solution 4

I'm far from an expert, but the mail() function uses a lot more CPU and memory than normal web functions but having 1 million users may already have a significant load (CPU and IO) on your server already. This may impact the speed of sending out emails, especially if you're on an older Xeon.

From what I know, dual quad Xeons are relatively new and sending those emails shouldn't take anywhere near as long as it is.

From what I've read, a lower end single cpu dedicated server should be able to send out about 500-700 emails per minute... but that is a system dedicated to only sending emails. On a mid range server like I suspect you have I'd expect it to be able to send the emails in hours, not months.

It may be a configuration or a load issue which could be on many different levels.

Share:
12,777

Related videos on Youtube

John
Author by

John

Updated on June 04, 2022

Comments

  • John
    John over 1 year

    I have a large board with 1 million+ members and I'm experiencing great lag between the sending of emails to each member. At the current rate it would literally take me 3 months to send emails to all 1 million members.

    My machine (dedicated):

    • dual quad xeon
    • 32 gigs of ram
    • Centos 5.4
    • vBulletin

    I've tried configuring it a number of ways and it is still slow.

    The resolution is done locally, so I don't think that's the issue. Any suggestions?


    vBulletin shows as it sends out the emails (500 at a time) so I know the script isn't timing out or a memory issue. To complete a page of 500, it takes 10 minutes. I am using PHP's mail() function, which is the only other option I have other than SMTP. With previous servers I have not configured myself, it had always been fast. Now trying it with sendmail (PHP's mail function) it is so slow.

    • zerkms
      zerkms over 12 years
      @PhpMyCoder: what are you talking about?
    • Frank Farmer
      Frank Farmer over 12 years
      Are you connecting to a remote server to send mail? This may have nothing to do with your local box, and everything to do with the remote end.
    • Bailey Parker
      Bailey Parker over 12 years
      @zerkms Yup. I've seen it before. That was a think before you post moment for me.