How to mass mail? - php

I have a browser based gaming server, and it wasn't properly configured. In three days 420 people joined and all left because of mysql crashing and slow load time.
I upgraded the mysql and configured the server to run on low memory. Now It's super fast and crash proof. However all the players are already gone.
Good news is that I have a database full of 420 emails. I could tell them to come back and reward them.
Can anyone show me an example of a php-mysql mass email script?

you will have to iterate through a function that runs the same mailer against select all user emails...
i mean truth be told you will be lucky if an ISP doenst flag you down or if your hosting provider doesnt throttle you.
i would actually recommend doing this slower than faster. try doing one every minut so within a 6 hour cycle they all get rolled out.
you can use a pause in a script or run a persistant cron job.

Both of these solutions will keep you from getting blacklisted for a few pennies a month
Set up a mailchimp account for this few emails it should be free:
http://mailchimp.com/pricing/free/
import your mailing list into mailchimp and then split the users into multi campaigns and send mailers out to one of the campaigns track success and then adjust and start one of the other campaigns.
OR
use sendgrid's SMTP service.
http://sendgrid.com/pricing.html
using sendgrid you just configure your mailing script to connect via smtp (PHP Mailer can do this easy). $0.10 per thousand emails sent...

You shouldn't have trouble doing so on an offshore VPS those this are practically mail bombs.
Just use the mail() command in php.

Related

Sending huge amount of email from SMTP

I have an issue. I have situation where I need to send around 3000 emails per request using SMTP. However, only 30-40 reaches destination.
Do you have any idea what can be a problem and how to solve it. as server side script I am using PHP.
How the big e-mail service providers (Constant Contact, WhatCounts, etc.) do mass e-mails is to put the "campaign" in a queue and send it at a later time. They have dedicated, high-performance delivery software for looking through the queue for new campaigns to send and then send them out at rates exceeding 50,000 messages per minute. Anything you might do in PHP won't even compare.
If you are trying to send from your local computer, that won't work. DNSRBL lookups will identify your computer as being on a "DUN" (Dial-Up Network) and will block the message. Most PHP scripts also have a timeout of 30 seconds in a web server environment but running via cron a PHP script can run as long as it needs to.
You shouldn't send mass e-mails from your main e-mail server either. That's a nice, fast way to get on global blacklists so that you can't send regular e-mail to common hosts (e.g. Hotmail, GMail, etc). The big e-mail service providers have dedicated staff whose job it is to remove themselves from global blacklists. That's a full time job. You are better off paying for the service (don't forget to set up SPF records correctly if you do go this route).
Warnings and advice aside, to answer the question, use a cron job for your PHP script and put the e-mails to be sent out in a queue.
If your looking to inboxing as many emails as possible and you are not sending spam, and prefer to use your own smtp, check them out.

Is php mail() a good option for mass mailing?

I am creating a system, where a list of thousands of emails will be sent periodically, I know that the mail() function in PHP is quite heavy, specially if calling it too many times simultaneously.
Roughly the way my system works , is that I create queue of emails in MySQL and send them in batches of 25 using mail(), removing from the table the top 25 sent. And I wait 2 seconds between each set of 25.
Is this too much effort for the server or I can push it a bit further?
Lets say 50 per second? Or there is a better way of sending many emails in less time without sacrificing Server performance.
I have a dedicated server without any mail() call limit.
There are other factors to consider besides performance, but the short answer is: there are better options. Amazon SES and MailChimp are the two I know about have heard positive feedback on.
Look at j08691's answer regarding the performance, but other issues with using mail() for this purpose include:
Scalability (you will hit a wall that no SMTP server can handle eventually, and you're already thinking about it)
Integrity - You are much more likely to get flagged as spammy when rolling your own mass mailer, especially using mail as it uses the local sendmail by design.
Cost/Benefit and ROI - the reliable mass-mailers get it right and for a competitive rate. At some point you are paying yourself less per hour to maintain your mail server when it crashes, getting off of black lists, writing the email layout by hand, general upkeep, etc etc than you would paying for the mass mailer service.
Overall, the big issue is that you have to do all the work yourself and you're likely to get flagged as SPAM for the benefit of not paying for a service that will be able to send hundreds of emails a second versus a hundred a minute when PHP isn't busy doing everything else it handles for your web app.
Personal anecdote (not an endorsement for SES, just mass-mailers) : We had a client that sent 100k+ emails per campaign, with 1 - 3 campaigns per day minimum. They started complaining that the clients were getting emails about "daily deals" 2 days late. It wasn't because the Mailer library was slow (even this app avoided using plain mail), it was that it couldn't be sure to send all of the emails for every campaign before the email was irrelevant. We switched them over to SES (with some optimizing on our end, but not much), and they could clear a campaign in under an hour.
From the PHP manual:
Note:
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.
Try using PHPMailer. i used it to send about 100 mails everyday without any problem

Sending emails through PHP mail is slow

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.
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.
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:
You don't worry about bandwidth, infrastructure and maintenance.
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?
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.
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.
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.

PHP based web application and mass mailing

I have developed a web application where students across the country come and register for some academic purpose. The users are expected to be around 100k within next year.
I need to send all of these people periodic mails. The web app is developed using codeigniter. The php script can run for 3000 seconds. But still the app is unable to send mails to more that 100 users.
The machine I run is in cloud and has got 256MB ram. I used the free -m command to check the memory usage but that doesnt seem to be a problem. Everything works fine for 10-20 mails.
What would be the best solutions? Is there any way I can transfer this job to some other app/program/shell script ?
If you cannot use some external service for your emails I would just setup a cronjob that sends a couple of emails every n seconds. Its pretty cumbersome to send a lot of emails with php as you have discovered. But the cronjob solution works everytime as far as I know.
So you have a list of emails/addresses and a cronjob that iterates that list and sends the emails.
Sure you can send the emails yourself from a server, but that is only half the battle.
If you are sending bulk emails, as opposed to the transactional type, it's best to use a third party service that is already whitelisted on mail servers. The primary reason being, you might get blacklisted by the major mail servers as a spammer. If this happens, you will have to work with them individually to get removed from the blacklists.
Also if you are operating in the United States you should be familiar with CAN-SPAM: http://business.ftc.gov/documents/bus61-can-spam-act-Compliance-Guide-for-Business
MailChimp is a viable candidate for this. Serving mail is a time-consuming task, and sending it up to 100k email addresses will be an arduous task for your server.
They provide an very capable PHP API.
https://developer.mailchimp.com/
It is very appropriate to get this out of your web server threads and into something that runs standalone. Typically for stuff like this, I have tables in the DB where the appropriate information is written to from the web site, so when I am ready to e-mail, something on the backend can assemble the e-mails and send them out. If you are sending out 100,000 e-mails, you are going to want something multithreaded.
It might be good in this case to use one of the many off-the-shelf tools for this, rather than reinventing the wheel. We use an old version of Campaign Enterprise here, and I am able to throw queries at it which I can use to pull data from my web DB directly, over ODBC. That may or may not work well for you, considering you are in the cloud.
Edit: You can also write a PHP script to do this and call PHP from the shell. Perhaps you can get around your timeout limit this way? (This is assuming you are referring to some service-level timeout. If you are talking about the regular PHP timeout, this can worked around with set_time_limit().)
You might be able to do with using pcntl_fork or creating a daemon process.
Fork: By using the fork process you could batch the emails into groups and send them out. each batch could be in it's own fork child process
Daemon: By using a Daemon you could create a batch of emails and send them to be processed by the daemon. a daemon could run multiple batches at once.

Shared Hosting mail limits workaround

so i have a couple of sites on paid shared hosting, my host limits the mail to 300 per hour.
One of my sites has more than 500 subscribers.
My question is how can i send the newsletter to all my subscribers? is there a way or a script that i can use to send the first 300 users the email and after an hour to send the rest...?
i've also considered making a gmail account to send the newsletters via smtp. Do you guys know the limit of free gmail smtp?
You shouldn't circumvent the restrictions placed by your host. I would suggest you pace your sends, and record your last-sent-id, picking up from there in your next hour. That, or you can place sufficiently sleep-time between sends to allow the entire thing to go out at a rate of about 300/hr.
Thank You for all your Reply guys... it really helped me find a solution for this inconvenience. I personally can't afford VPS hosting nor pay extra for an external for a mail server...
Considering Jonathan Solution and William's Comments i ended up developing a small php application based on XML to send different batch to 250 recipients each with a GAP of 65 minutes.
So the way it works, by default it only enables the first batch link to be clicked and send the newsletters to the first batch of users and recording the exact time this was sent in a XML file.
Then using the XML file info the next link registers that the batch before it was sent and starts a count down of 65 minutes with the time on the XML as reference.
So a Script will not be running for hours and the browser could be safely close since all the info required is in the XML file.
This may sound Simple but is a complex and efficient app that dynamically adapts to growth (new subscribers) as it queries the master Table on a database using the sql LIMIT clause to make the different batches. So it doesn't required maintenance.
If anyone is interested on the source code feel free to contact me # admin#thechozenfew.net
Google Mail does have limits, see:
Sending limits In an effort to fight
spam and prevent abuse, Google will
temporarily disable your account if
you send messages to more than 500
recipients or if you send a large
number of undeliverable messages. If
you use a POP or IMAP client
(Microsoft Outlook or Apple Mail,
e.g.), you may only send a message to
100 people at a time. Your account
should be re-enabled within 24 hours.
Source: http://mail.google.com/support/bin/answer.py?hl=en&answer=22839
To get around the problem, you could create a queue table in your db with a list of all the users you're sending the newsletter to. Then send e-mails out in bulks (500 example). Remove the e-mails from the queue table as they're sent out. You could use a cron (if on linux and host allows) to run a PHP script every hour that sends e-mails based off the queue.
I'd seek a place just to park your MX (not sure of Google's limits, but that could be a start). Its very common for mailing list managers to queue mails to fit within sending limits. I.e. a cron job queries a database, picks up 250 emails to send and sends them out.
The problem lies when you have 10,000 subscribers and need to send non-automated emails from the same MX. I.e., if your limit is consumed getting out a newsletter, what happens to your ability to reply to your own e-mail?
A lot of companies offer MX only hosting, I'd go with one of them and move the whole business of sending the list over there. Or, just get yourself a VPS (its going to be about the same monthly price).

Categories