My goal for a recent project was to setup a way to send reliable, custom emails each time a new WordPress post is published. Sadly, that rules out leveraging Jetpack because its email templates cannot be customized. Enter MailPoet, arguably one of the most feature rich freemium newsletter and email plugins for WordPress.
Email, especially WordPress email, is a tough beast to tackle, and a reliable method to email WordPress posts to subscribers can prove elusive. Many emails get flagged as spam or are rejected entirely and rendered undeliverable. Read more about how Mandrill makes quick work of increasing your WordPress email deliverability using the same engine that powers MailChimp. Best of all, the Mandrill development team created a free plugin to integrate Mandrill with WordPress: wpMandrill.
Enter Mandrill & MailPoet
Daniel Klose wrote a great tutorial on how to setup Mandrill and MailPoet to send free newsletters with WordPress. Although it doesn’t discuss why you might want to do that, it’s a great starting point if your WordPress site will involve voluminous transactional emails—new post notifications, membership confirmations and notices, invoices, shipping updates, etc. Basically any automated emails you plan to send are good candidates for deliverability issues which Mandrill aims to reduce significantly.
Shared Hosting Problems
Klose’s MailPoet and Mandrill tutorial configures MailPoet to use Mandrill via SMTP. Unfortunately, many shared hosts block the ports required for WordPress to connect with an external SMTP server, which is where I ran into difficulty. MailPoet does offer the ability to send emails through GMail, but it’s recommended to have a paid GMail account if you plan on significant email volume, which wasn’t exactly keeping in the spirit of sending free newsletters reliably for my budget-minded client.
MailPoet comes with the native ability to use PHP’s
sendmail() functions, claiming the functions work on 95% and 5% of servers respectively. I think we can do better than that. So I dug around…
wpMandrill actually “intercepts” WordPress’s mail function and uses the Mandrill API instead. Unfortunately, this only works when we call WordPress’s own mail function (
wp_mail()). MailPoet does not provide us with the ability to use
wp_mail(), so it looks like we’re stuck. Or are we?
I sifted through the MailPoet code and found an interesting line:
'allow_wpmail' => false1
After some more digging, I noticed that the complete infrastructure is in place to enable MailPoet to send emails with
wp_mail(), which could then magically be intercepted by wpMandrill—all without the need to pay for GMail or a VPS! A quick consult with the MailPoet support team led me to create a function which enables
wp_mail() in MailPoet and remains update proof. So I added this to my
Now when we go to the settings (MailPoet->Settings->Send With…->Your own website) we see the two default options are now three beautiful options:
Choose WP Mail, save the settings, and send yourself a test. Now you should be off and running, ready to email WordPress posts to subscribers with Mandrill and MailPoet on your shared host, even if your outgoing ports are blocked!
Thanks to MailPoet and Rafael for helping me navigate the MailPoet codebase.
This function makes it possible to adjust any of the parameters in the MailPoet
$defaults array2. Some of them are a bit cryptic, so the MailPoet support desk was kind enough to provide more details on the MailPoet hidden options. Just be sure to test your settings on a non-production installation first!
This doesn’t work anymore. Can you please check?
I guess i was hoping for a quick cheat like changing the string in the snippet to call Postman instead…lol
Thanks for your efforts, much appreciated. I entered your snippet which worked beautifully to bring up the use wp-mail option. My question is a little different. I currently have Mailpoet but it delivers mail with red padlocks saying the mail is not verified by the server. I installed POSTMAN SMTP which adds Gmail API. CF7 contact form and test mail is clean and verified by the API. POSTMAN SMTP actually replaces wp_mail so i thought your snippet might help. Sadly i get an error from Mailpoet when test email is attempted. Should i be talking to the people at Postman? or do you have some advice, best regards
You are a wonderful example of the spirit of open source collaboration. It took you a lot of effort to discover and develop this and you give it away for free; and I bet that is partially due to the great benefit you have received from other open-source work (ie WordPress and others).
This is great work, explained very nicely and made very simple for us to use. Thank you.
You are an absolute genius!! I have been fighting with this for over a day and just happened upon this post after Googling in desperation! Thank you sooo much! :):):)
Excellent!!! Remember to put the script in
functions.php(located in your theme’s folder)
I cannot for the life of me get this to work. I added the code to functions.php, and it’s still not showing the 3rd option. Also not quite sure where to add the
allow_wpmail => truecode as well.
Forgive my ignorance. Please advise.
Michael, your post is worth its weight in gold! It fixed the unfixable!
I’m not extremely experienced with PHP, so to my untrained eye, what your functions.php code snippet does is just changes allow_wpmail from “false” to “true”, right? Is this something that can be achieved simply by going into the Mailpoet config.php and making the change manually? Would the only reason to put the code into functions.php to make it update-proof in case Mailpoet updates itself & reverts the change? Or is there something else going on?
Thanks, glad it helped. Correct, you add this snippet to
functions.phpso that the change will persist even if you update the plugin. I mention that in the comment just above yours and there are other comments above with some links to more info on
functions.phpwhich you may find useful as a PHP newcomer. Enjoy!
You didn’t place that coding into “functions.php”. You place it under “wysija-newsletters/index.php”. I was on a wild goose chase looking for “functions.php” in the long list of Plugin Files.
See this comment above. If you add the snippet directly to any of the plugin files then you will lose the code because the files will be overwritten when you update the plugin. Adding the code to
functions.phpensures that the change will persist after plugin updates.
Oh my goodness! You are a lifesaver! Thank you so much for this. I have bluehost and my emails stopped working. I set up mandrill and I thought all was well except my newsletters no longer worked. I thought I was going to have to change services from mailpoet even though I’d already written a well thought out newsletter. Your simple workaround saved me so much aggravation!
Thanks Kristin, glad you found it useful!
Adding the snippet didn’t show the send method options, I saw the DOM and noticed that the element was there but hidden, if the options of mail engine won’t show to you, you can open the console and execute this:
Hi Marco, with the latest version of WordPress (4.1.1) and MailPoet (2.6.15) I see the snippet still working. I even see MailPoet’s WP Mail send option when I remove the snippet, so it appears MailPoet may now show this option by default.
If you’re not seeing the entire
div.choice-sending-method-sitethen something may be wrong with your installation.
You may need to: (1) update WordPress; (2) update MailPoet; or (3) try disabling all other plugins on your site to rule out any conflicts. A healthy installation should not experience the issue you reported.
You are an utter lifesaver. Thank you, thank you, thank you!
After Adding the code snippet to my themes functions.php, My site stopped loading entirely.
i had to upload a backup of the functions.php before it will load again.
On testing locally, it said error unexpected ‘ ‘ in php
The code snippet was pasted after the previous codes there
Hmm, is it possible that you included the opening
<?phptag from my code when you didn’t need to?
“So I added this to my functions.php:”
What did you add to your functions.php? Something missing in the article?
Nevermind, found it ! =)
“So I added this to my functions.php ”
Where is that “functions.php” file? do we have to create it? I do not find it.
I really do not understand the process:
Do we have to set “‘allow_wpmail’ => false” to “allow_wpmail’ => true” ? or leave it as it is?
Do we have to create a file called “mailpoet-wp_mail.php” with that code?
Sorry but I don’t get it, could yo please explain those details?
functions.phpshould be inside your theme directory and is used to change default WordPress behavior. See more here: http://codex.wordpress.org/Functions_File_Explained. If it’s not there you can simply create one. Then you can just copy and paste my snippet into that file and be sure to set
'allow_wpmail' => trueif you’re experiencing the issue I discussed.
a sigh of relief when i saw this post with a hope that you will reply to my problem.
I am also using mailpoet with mandrill. All is working fine, but
the problem is that I am unable to send bulk emails. Like if i want to send bulk resend confirmation link, smtp gives an error, but if i send them individually, it works like charm.
I am on godaddy’s shared hosting, and all my transactional mail are working fine.
What do you suggest me to do in this case? because i think the tweak you gave is for those whose port is blocked and no mail is going out.
I consulted with mailpoet and they reffered me to this article, but my situation is different.
Sorry that you’re having issues sending your emails, Himanshu. I’m not sure what you mean by “bulk resend confirmation link,” but if you’re receiving an error then seeing that error would be extremely helpful. Consider posting to http://wordpress.stackexchange.com too because I don’t provide support for or work with your hosting platform (and you shouldn’t either!).
How does the wpMandrill plugin setting affect your MailPoet Tweak above?
I implemented what you suggested above and it worked without installing the wpMandrill plugin, so I am kind of confused how the wpMandrill plugin and your tweak interact each other.
Please let me know. Thank you!
Hi Chloe, see my section called “The Problem.”
If you’re just using MailPoet and you don’t care about your transactional emails’ deliverability then there is no need to use wpMandrill. If you do care, and you do use wpMandrill, and your host blocks certain outgoing ports, then
allow_wpmailcan help you get around that. Does that make sense?
Great article!! Was getting crazy and I solved in 1 min with your suggestion
Nice digging! WP Engine’s 3rd party email provider went down on wednesday causing a client to phone in that they weren’t getting quote requests. They recommended Mandrill. Might have to start down that route soon! Thanks!
Problem found. http://postimg.org/image/sgv4eib1d/
please check the screenshot above.
Sending test mail from the settings > Send with page with WP_mail is successful.
but when I tried to send a preview while editing a newsletter sending failed and gave me the above error.
waiting for updates.
I can try to help but you may want to contact MailPoet. What does that error message say? Can you translate it into English?
Where there is a will there is way out…
you made my smile wider.
Awesome post. Totally bookmarking for later. Thanks!
Thanks Kronda, this was a doozy to get up and running but worth it. Seems like a viable, reliable way of increasing deliverability!