Best way to loop smtpmailer email php loop - php

I run a website where I would like to start sending out an email newsletter to the registered users that opted in. Currently, there are about 700 users. I use a gmail account with smtpmailer to currently send all my notifications and it works well. However, when I ran my loop script to send out the personalized newsletter, the webpage with the loop eventually errors out after getting through maybe 100 users.
I didn't think this was really that heavy of a load. Should I be following a better practice for this?
My code process is essentially as follows
Connect to server
set_time_limit(0);
While loop for all users who are subscribed
Build custom message
Send Email
End Loop
Thanks

This is not what your Gmail account is for. Gmail intentionally puts blocks in place to prevent this or at least de-rail your attempts.
There are many free for small account SMTP providers out there with various restrictions.
http://www.SendGrid.com Send up to 400 emails a day (12,000 emails a month)
http://www.MailChimp.com Send 12,000 emails a month to a list of up to 2,000 subscribers
Those are two of the big ones but there are plenty of smaller outfits as well.

Gmail allows you to send only 50 mails per hour.

Related

PHP timed script execution

I am not quite sure how to put my question into words, but this is what I am trying to build. I want to send email using PHPMailer through my gmail account. Now, Gmail has a limit of 500 emails in one day. Another thing to consider is, when you send a bulk email at once, there is a chance that my email is sent back to me, as my bulk email is considered to be a spam. I have around 200 in my contact list. So a limit of 500 is not a problem. Now my question is, is there any native PHP function that will only execute the send function of PHPMailer in a certain amount of time duration? What I want to do is, I want to send 10 emails from my contact list every 30mins.. So if I have 200 in my contact list, there is an interval of 30 mins in every 10 contacts until I send the email to everyone. I have no problems creating the email script using PHPMailer. I just need to know if there is a way in PHP to 'time' the execution of my functions. I would appreciate any kinds of help. Thank you!
I think you should really look for third party solutions. Sending bulk emails via Gmail or any other provider will create problems for you.
I am using MailGun (with 200 mails you can use FREE version) for years and it does the job.
Don't forget to check mailgun for PHP.

Mass email to subscribers upon WordPress post update

I need to send individual emails to 1500+ subscribers from a WordPress template page. They are not WordPress users but their details are stored in a non WordPress table.
Upon post update, I need to fetch their email addresses from the table and send individual emails to them. The email contains a unique link to unsubscribe.
I have everything working. The only thing is that when the post is updated, it keeps loading and loading as it is sending emails and eventually times out.
Can anyone please advise if there is a better solution to update the post but schedule emails or send emails in chunks of 50s?
As already mentioned in the comments there are some possibilities you can go with - letting WordPress send all those emails on save_post is certainly not a good Idea.
Here are three possible ways you can solve it:
1) Instead of wp_mail() you may want to implement a PHP library for sending many emails fast at once for instance PHPMailer (https://github.com/PHPMailer/PHPMailer).
Advantage: You do not need an external service and no cronjob.
Disadvantage: If the number of subscribers is growing to high this will fail, too.
2) Use an internal cronjob for WP and send chuncks of 50. There are many tutorials out there how WordPress Cronjobs work (https://codex.wordpress.org/Function_Reference/wp_cron)
Advantages: No external service required and almost no limitation in the number of subscribers.
Disadvantages: It will take some time until the WordPress cronjob has finished. It will slow down your site especially if you have many updates.
3) Use an external service like Mailchimp. Just have a look into their API and trigger the email sending.
Advantages: Many additional options. You do not have to implement any sending logic.
Disadvantages: Eventually costs money. Requires Integration of their API. You have to keep subscriber list synchronous.
There are a couple of WordPress plug-ins that do mass mailing. As an example, Mass Email To users. I am going to assume you've looked at them already. I have not used any of them.
What I used to use for an email list of 12,000 subscribers is use PHPList. It has an open source free version which allows you to send 300 messages a month and unlimited subscribers. It allows you to have subscribe/unsubscribe functions with the list and manage your subscribers without adding 1500 accounts to WordPress.
https://www.phplist.com
One of the issues to be aware of is that many ISPs have a 500 message per hour limitation per domain. This means that a list of 1500 people will take at least four hours to send. Why four hours? If you send 500 per hour, you might trip a daemon that blocks your website for using too many resources. Plus you can't receive any emails, since the cap is for every email. But if you dial down your send rate to 400, you should be fine. Even without a restriction, chances are it's going to take a while to send out a message to 1500 subscribers.
I moved onto a email provider like Mailchimp because at 450 emails per hour, it was taking 26+ hours to send an email and mailing list managers tend to be finicky. This gives you all your solutions on one server, which is nice when managing projects.
Good luck.

How to realize a Newsletter system with Rss news feed?

I have a news portal with everyday news. My need is to send through newsletter the daily news to subscribers.
I've already realized a PHP/MySQL custom newsletter system that performs the following tasks:
fetches the daily news
fetches the list of users who want the newsletter
everynight through a cronjob I launch a script that performs the above every 5 minutes sending the newsletter to 10 recipients at a time each cycle
Problems:
I have to estimate how long this cronjob needs to run in order to complete the full list of users (5' x 10 emails) = 120Email/hours = TotalUsers/emailperhours = number of hours the cronjob needs to run
I overcome this problem because I don't have so much users until now and I can still manage to make the cronjob run enough to send all mails, but for the future?
All email receievers are saved double opt-in, means I'm quite sure of their existence, but it happens how you can imagine that I'll have anyway many Mail delivery for other reasons:
here I need help because I dunno how to catch there Mail delivery through PHP and update MySQL tables in order to suspend these unnnecessary sendings.
Alternatives:
I know that there are many providers who offer Newsletter systems but this works fine every time u go and compile your static email body. Here I need a dynamic email body to be generated every day with fresh news and then send it to recipients.
Still here I need some advice.
You might find it worthwhile using a service like SendGrid - they have an API that handles dynamic content. I haven't tested it out that aspect myself, but for the small price they charge it might be worth saving you the headache.

Creating a Mailing Script for Newsletters

I am currently using PHP mailer. I would like to create a mailer script where I can add an arbitrary (anywhere from 10-1000) number of fixed e-mails and type in a message in a textarea and the mailer will mail each person the e-mail individually rather than all at once. I would like to avoid users opening an e-mail that appears to be sent to 1000 other e-mail addresses and make it more personal (i.e. sent from e-mail address x to y, as opposed to, sent from e-mail address x to a,b,c,...) This will simply be an administrative extension for admins to easily mail out newletters to all subscribers.
I was wondering what would be the easiest way to implement this? I would rather stay away from cron jobs, if it is possible to implement this without it.
I appreciate any advice.
Many thanks in advance!

What's the best way to send email to a large list where each email is to be personalized with information from a database and other sources?

I run a daily deals aggregator. I'd like to send daily emails to users who sign up for them. The site itself is PHP/MySQL. What should I use to send emails? Each email will be specific to each user depending on the kind of deals that user wants to received. What do sites like Quora or other daily deal sites use to send emails?
I think you can use loops to loop through the emails that are stored in an array where the keys of the array are the respective user ids, and then send emails accordingly. You can use the foreach loop.
You could create a table in your database to temporarily store the addresses that have not yet received a mail and create a cronjob that sends 200 email per 30 minutes or so. Like this you can avoid clicking some button and wait for hours until your script is done.
Remove every address that has received the mail until your table is empty. Use another cronjob that runs every week or month (cycle to send newsletter) that fills the temporary table with your recipient addresses.

Categories