I'm currently making a promotion plugin for WordPress where I need to send out e-mails to different press e-mails based on a checkbox-list. My hosting provider has a limit of 200 e-mails/hour, but I don't think I will reach that limit. I know that mailing list providers are recommended, but my plugin has some functions (like making promo codes etc.). Everything is now finished with the plugin, and I only need the function for sending.
I have been searching for solutions, and have been looking at timers in PHP to avoid spam detection. I think I will end up with Cron jobs. I have looked into the built in WordPress cron job function, and will try to use this one.
I have never been using cron jobs before, so my questions is: how can I keep track on which e-mail my plugin has sent to? Do I need a temp table where each row is deleted when sent?
Any other suggestions for my solution would be appreciated!
if(mail(//params))
{
//insert this email id in db
}
you can keep track by inserting email id in to db if email sent successfully.
Related
My website built in bespoke n-retail coding based on PHP. Currently, I am having an issue whereby the same newsletter message randomly sent to my registered customers.
Where in the file manager I need to check to find the issue. It must be a bug somewhere.
There are 2 possibility
1. Newsletter is send from admin side
2. Cron job
You need to check both files so u get then bug, also provide more information so we can help you.
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.
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.
I'm coding a team collaboration web app in PHP, and I have a few events that users get notified about through email and/or SMS. The current way I'm doing it is as follows:
Every user has his notification settings in the database as boolean variables.
Say users would be notified when someone comments on the team's page. When the function that posts a comment is called, the same function would contain extra code that checks "who wants to be notified about this?" and then sends notifications to them (which slows down the function a bit).
Is there a more efficient/faster/flexible way to setup notifications? maybe through a script that runs via a cron job? or shall I just keep doing it this way?
I appreciate your help.
I implemented a similar method to the one you're following on a website with a multi-table approach. The users table held the contact information along with opt-in, opt-out options while an event table held the instructions to notify. Several other events were hard coded because of their importance. The thing that set the site apart a bit was a "workflow" area on the user's dashboard that also showed the user what action items they had. We found that most users ignored the emails and dealt directly with that dashboard workflow area. You'd be surprised how many times people change emails or just ignore them altogether.
With 280,000 users and daily visits in the tens of thousands, there was no performance issue noticed. However, the process of queuing emails can be inefficient if you're not careful, so take particular time to benchmark your mail sending functions--its as easy as echoing out microtime before and after the mail send is accomplished--to evaluate its effectiveness. On my current company's site, such improvements yielded a 800% reduction of email queuing time (queuing being the process of generating the emails and submitting them via php mailer to the mail system for distribution)
I'd say have a table that is a queue of notifications. Let the function that post a comment still check "who wants to be notified about this?" but then just log entries containing the messages in this table. Then have a separate process work from the queue i.e. your cron job suggestion.
Depending on your database you may perhaps make use of database events or triggers instead of a cron job. This however have the requirement that your database allow you to put code in your database that will send the SMS or Email. This poses a security risk normally which you may or may not be concerned about in your setup.
I'm creating email notification system on my site to send email to the users who has subscribed the article for new comments... I would like to know what is the best way to handle with this situation in php. Should I use the mail function just after the database insertion or there is some better ways. Will it slow down the process of adding new comments if there are too many subscribers?
I would create a new database table and add the subscribers that needs notifications to that table. Then run a crontab every 5 minutes that sends the emails to those whose article has been commented. That way you don't have to send it directly thus clogging the user experience with longer loading times.
You can send an email as soon as a comment is inserted into the database or when admin/mod approves from admin side if you such mechanism.
Will it slow down the process of
adding new comments if there are too
many subscribers?
It will because you will be sending the email to more and more subscribers. However, you might want to consider optimizing your insertion query as well as your code if you can.