WordPress: How to use wp-mail.php correctly in Gmail blog posts? This is my solution

Update: this blog post doesn’t apply to WordPress versions newer than 2.7.

Let’s say you wish to use the WordPress function for blogging via email posts. This work great for HTML emails in Yahoo Mail. It works great for Google’s Gmail in plain-text format. How about Gmail in HTML emails? Things get trickier. That’s why I present you my very first PHP small add-on.What ca you read in this blog post?
1. What does my software do?
2. What does my software doesn’t do?
3. How can you personalize the blog to work only for your email address?
4. What should you note?
5. Ok, ok, where’s the software? Download link?
6. How do you know it works?
Ok, now you know it. Let’s get going.

1. What does my software do?
My PHP add-on does one single trick: helps you put HTML emails. It works great with Gmail (tested it a lot on some of my blogs, see the end of this blog post), and it works not-so-bad with Yahoo! Mail (only done a few tests, though).
It also try to fix a bug of WordPress for breaking posts that contain Unicode characters.

2. What does my software doesn’t do?
Unicode characters are a big pain for WordPress. There are some characters which are poorly converted. This problem is also common for sending emails. What’s the solution? I’ll present my case story: whenever I send an email that has Unicode characters, I first try to convert those Unicode characters into ASCII. This can be solved quite easily in Notepad (under Windows Operating System). Just create a blank document in Notepad, put the Unicode text in there. Save it. Notepad usually warns you that if you want don’t save as Unicode, you’ll lose some formatting. Hit Ok, then reopen the document. Most Unicode texts are gone. There are still some problems (quotes, for example, are not converted) and for those … I’ve created a different software. See the blog post in here.

3. How can you personalize the blog to work only for your email address?
You can replace this line:
if (( is_email($author) ) && ($author == ‘PUTYOUREMAILADDRESSINHERE@SOMEMAIL.COM’)) {

with this line:
if ( is_email($author) ) {

Also, replace these two lines:
// Author not found in DB, set status to pending.  Author already set to admin.
$post_status = ‘publish’;

with these two lines:
// Author not found in DB, set status to pending.  Author already set to admin.
$post_status = ‘pending’;

Finally, replace these three lines:
if (!$userdata) {
$post_author = 1;
$author_found = false;

with these three lines:
if (!$userdata) {
$post_author = 1;
$author_found = true;

4. What should you note?
I am not responsible for errors you might encounter with your software. You can leave a comment below and explain your errors, and I’ll see what I can do, you can post your errors on WordPress’s support page or search its archives. Please note that this is my very first software in PHP and I’ve learned the commands mostly by trial and error.

5. Ok, ok, where’s the software? Download link?
You can download my software in here:
wp-mail.php made by Olivian BREDA. Use at your own risk

Use it at your own risk.

6. How do you know it works?
Well, I’ve tested it for a few months now. These are the blogs where I’ve tested my software:

Update: this blog post doesn’t apply to WordPress versions newer than 2.7.

46 comentarii

  1. Great Hack! I used your code to post my very first Post Via Emails! Many Many Many Thanks!

  2. I’m so glad you like it. :)

    You’re the very first person confirming it works. :d/

    Olivian BREDA’s last blog post..Botnets – first understand them and then fight them. A practical guide

  3. [quote]Plugin Installed

    However, I couldn’t verify that it really is a plugin. Hmm.[/quote]

    and I can’t find it in plugin panel :(

    Salvatore’s last blog post..Finalmente in vendita, su eBay, il Bosone di Higgs

  4. Hello Salvatore, you should try to replace your wp-mail.php file in your FTP folder with my own. I didn’t make a plug-in, it’s just a new PHP file.

    You then run it by typing this in the address bar:
    [name of your blog]/wp-mail.php
    and hit Enter.

    Does this solve the problem?

    Olivian BREDA’s last blog post..Botnets – first understand them and then fight them. A practical guide

  5. AL Geddis

    I just uploaded your wp-mail.php file to my site. I then went to http://www.mysite.com/blog/wp-mail.php and got this message: POP3 connect: Error [97] [Address family not supported by protocol]

    I also do not understand how this would work-I want to be able to send a post via my gmail account, but to WHERE would I send it?

  6. Hello AL Geddis,

    Thanks for the comment.

    1. Could you please try the original wp-mail.php, the one provided by WordPress and tell me the error you get? I can then find out if the error is in my software or in your configuration;

    2. You must configure an email address on your server on which to send emails to;
    so if your site is greatsite.com, you’ll have to have an address like myemail@greatsite.com. You can configure this address in the Settings area (or Options for older versions of WordPress); Then go to Writing Tab and voila. At the end of the page you’ll find these settings;

    You can read all about it here:
    http://codex.wordpress.org/Blog_by_Email

    If you wish, you can let us know how’s it going. :”>

    Olivian BREDA’s last blog post..Botnets – first understand them and then fight them. A practical guide

  7. I am still getting this error!!!

    Hey! Welcome to my optimized-for-Yahoo-and-Gmail interface.

    I’ve read the following encoding before actually reading the email (to evoid gmail errors):7bit

    I’ve read the following encoding before actually reading the email (to evoid gmail errors):7bit

    Gmail address found. Setting specific settings.

    Yahoo address NOT found. Going to normal email settings.
    Author of the blog post = ghajinii2008@gmail.com

    Author: 1

    Posted title: Test

    Mission complete, message 1 deleted.

    You can always check out my web site for more IT tricks: http://olivian.ro/:(:(

    Souvik Banerjee’s last blog post..Movie Poster

  8. There are some problems with emails that contain:
    1. Images;
    2. Special characters;

    Try posting different types of emails.

    Olivian BREDA’s last blog post..Botnets – first understand them and then fight them. A practical guide

  9. THANK YOU! I work for the government and so I can’t really blog anythiung political from work, but with email, I feel OK doing it. Now that I can easily get HTML in there, I’m excited!!

    SOmething else that would be nice: being able to assign categories through email. Right now, there’s just the default email category, but if I could select more…

    just a thought if you are feeling like writing up other enhancements ;)

    thanks again!!

    moleboy’s last blog post..Huckabee: Prop 8 doesn’t ban gay marriage

  10. I’ve got such a proposal via email and I’m working on it right now. :D

    Olivian BREDA’s last blog post..Botnets – first understand them and then fight them. A practical guide

  11. You da man ;)
    (someday I’ll get off my butt and learn php)

    moleboy’s last blog post..Huckabee: Prop 8 doesn’t ban gay marriage

  12. Thanks, when I’m done making it, I’ll post the update in this blog post. :D

    Olivian BREDA’s last blog post..Botnets – first understand them and then fight them. A practical guide

  13. This is working for me, however in step 3:
    if (( is_email($author) ) && ($author == ‘PUTYOUREMAILADDRESSINHERE@SOMEMAIL.COM’)) {

    with this line:
    if ( is_email($author) ) {

    I get an error…
    Parse error: syntax error, unexpected ‘@’ in /homepages/4_/d_________/htdocs/samburu/blog/wp-mail.php on line 112

    any suggestions? I changed it back to default, and by golly, it is working! I would like to have only one sender email address set though.
    Thanks!

  14. There’s something wrong. If you replace the strings as said, there is no more a ‘@’ sign.

    Please open the wp-mail.php in a text editor and go to line 112 and provide me with that line.

    Thanks.

    Olivian BREDA’s last blog post..Why vote? The one reason for which anyone should vote. Read this message, and then go voting!

  15. ok, I may have had it backwards… Currently, line 112 has:

    if ( is_email($author) ) {

    I was thinking I had to change it to:
    if (( is_email($author) ) && ($author == ‘PUTYOUREMAILADDRESSINHERE@SOMEMAIL.COM’)) {
    adding my sending email address.

    Are the posts supposed to post automatically, or do I have to install WP-Cron? I noticed they show up after running wp-mail.php from my url window…

    Thanks! David

  16. This line works perfectly for me:
    if (( is_email($author) ) && ($author == ‘mymail@gmail.com’)) {

    I can’t figure it out.

    You have to instal WP-Cron or a similar feature.

    Olivian BREDA’s last blog post..Why vote? The one reason for which anyone should vote. Read this message, and then go voting!

  17. all right, I did install WP-Cron, that is working now,
    I did change the line to:

    if (( is_email($author) ) && ($author == ‘myaccountname@gmail.com’)) {

    and get this error still:
    Parse error: syntax error, unexpected ‘@’ in /homepages/40/d_________/htdocs/samburu/blog/wp-mail.php on line 112

    very odd!

  18. I’ll look into it when changing for a new version. Don’t know what causes the problem. :(

    Olivian BREDA’s last blog post..Why vote? The one reason for which anyone should vote. Read this message, and then go voting!

  19. I tried just tried removing the “@gmail.com”
    leaving only my username on line 112
    and it seems to be working now.

    Well… I just did 2 tests, and they are listed in posts as pending. I will check my cron settings. What alternative to wp-cron can you suggest?

    Thanks again!

  20. I’m glad it worked for you.

    Regarding Cron: This is what I personally use:
    http://activeblogging.com/info/wordpress-cron-plugin/

    Basically, whenever a user visits my blog, it runs the function. If 15 minutes (or whatever) passed since I last run the code, then the code is executed (run wp-mail.php). I use more than one blog and all of them have this function.

    It’s less bother to me than do a WP-Cron server side. :)

    Olivian BREDA’s last blog post..Why vote? The one reason for which anyone should vote. Read this message, and then go voting!

  21. Hey Olivian, I tried the plugin you mentioned above, it hasn’t started working yet. what do you set you “time” (00:00) for?

    Looks like everything else is working great. Thanks again, David

  22. my settings are like this:
    1. an hour to start like 17:30 (you can also put 00:10)
    2. 15m
    3. http://olivian.ro/conferinte/wp-mail.php

    You should also check out this thing:
    Your theme MUST have the function wp_footer included in it, like this:
    < ?php wp_footer(); ?>

    (most newer themes already have this in footer.php or possibly index.php).

    So: put it to 10 minutes.

    After 12 minutes pass, visit your blog.

    After you visit your blog, visit it once again.

    Olivian BREDA’s last blog post..Why vote? The one reason for which anyone should vote. Read this message, and then go voting!

  23. @moleboy: for now I can’t make categories work. More research required, but no solution for now. :(

    Olivian BREDA’s last blog post..Why vote? The one reason for which anyone should vote. Read this message, and then go voting!

  24. Yeah, I think that’s been something a lot of people have tried and not been able to do.
    Oh well.
    I was actually trying to fake my way through to get it to handle posts emailed from Google Reader better. But, not knowing anything about php made that rather difficult. I might take another whack at it at some point…just to get it to maybe strip out the graphics or, at the very least, the signature that this came from google reader, etc.

    moleboy’s last blog post..Daily Kitteh!

  25. Sorry, I’m also at very beginning of PHP. :(

    Olivian BREDA’s last blog post..Why vote? The one reason for which anyone should vote. Read this message, and then go voting!

  26. Hi, does this hacked version of wp-mail.php support categories? Thats really all I want and dont want to fly the route of ‘postie’, just looking for a revised version that allows the old [1] or [category] in the subject title. This is killing me. Im thinking i should just take a look, not sure why im posting first really, guess in the hope of a quick fire response…

    gd day

  27. Sorry, no support for categories.

    In the latest version of WordPress you have options for batch editing, there are plugins for that, but mine doesn’t.

    I don’t have the time now to do the necessary update.

    Olivian BREDA’s last blog post..Why vote? The one reason for which anyone should vote. Read this message, and then go voting!

  28. Hi thanks for the quick response. And fair enough. Thing is I have found close but not exactly it, and some that are exactly it but out of date (see code below if u can be arsed) and no use. The actual wordpress codex page for ‘post by email’ says at the bottom that it is possible as a hack in the new versions. But in practise it just doesnt seem to work, so Im figuring its just a little slice of code im missing that must be out there, surely there is not the need to use the full postie plugin for this. aHwell. this was the guy that did it previously seemingly, but not much action on the subject and its an obvious bugger, cant be doing with ugrading to 2.7 at the mo either.

    // Author: Anthony Jay Bull
    // URL: http://www.thebullog.net
    // Date: December 15th, 2007 (Tweaked for 2.3.0 support
    // Purpose: Add categories using brackets in the subject

    // Parse out the categories
    if ( ereg(“[{1}(.*)]{1}”, $subject, $regs) ) {

    // Do a lookup on the categories table
    $result = $wpdb->get_row(“SELECT term_id FROM
    $wpdb->categories WHERE name=’$regs[1]‘ ORDER BY term_id DESC LIMIT 1″);

    if ($result) {
    // If you get a result, set that ID
    // for use further below…
    $post_categories[0] = $result->term_id;
    } else {
    // else, insert a new row and get its new ID
    $ret_id = wp_insert_category(array(‘cat_name’ => $wpdb->escape($regs[1])));
    $post_categories[0] = $ret_id;
    }

    $subject = substr($subject, 0, strpos($subject, “[“) – 1);
    }
    }

  29. This may come to you as a surprise, but I knew nothing on PHP before writing this software. I worked quite a few days just to learn the little changes I’ve made. So, until I learn some more serious PHP, I can’t help you with this. :)

    A PHP programmer might be easy to find on http://getafreelancer.com/

    Olivian BREDA’s last blog post..Why vote? The one reason for which anyone should vote. Read this message, and then go voting!

  30. Ok Olivian, Have a good one, sure we dont need to run the freelancer route, but just maybe… thanks anyway.

  31. Harry Chefitz

    I put your script in place and it runs without error.

    However, I am not using Yahoo or Gmail and it only posts the Subject line (as the title).

    Here is the output:

    Hey! Welcome to my optimized-for-Yahoo-and-Gmail interface.

    I’ve read the following encoding before actually reading the email (to evoid gmail errors):7BIT

    I’ve read the following encoding before actually reading the email (to evoid gmail errors):7BIT

    Gmail address NOT found. Going to normal email settings …

    Yahoo address NOT found. Going to normal email settings.
    Author of the blog post = xxx@xxx.com

    Author: 1

    Posted title: field trip: IMPORTANT DROP OFF REMINDER

    Mission complete, message 1 deleted.

    You can always check out my web site for more IT tricks: http://olivian.ro/

    My test blog is here:
    http://netivotmontessori.com/students/

  32. Hello,

    From my experience, 7bit messages include pictures in email.

    Try sending only an email with text only. Then try sending an email with basic formatting (bold, italic, underline). Then try sending an email with pictures embedded.

    WP-Mail doesn’t “know” about pictures, and me “teaching” it would be hard. :(

    If you’re not putting pictures, you might be putting pictures from your email provider (a signature or such).

    Anyhow, mail encoded with 7bit is usually not displayed. :(

    Olivian BREDA’s last blog post..Why vote? The one reason for which anyone should vote. Read this message, and then go voting!

  33. Harry Chefitz

    I’m using a Mac. So the email program is Apple Mail.

    I tested it with non-formatted text and it worked.

    I tested it with one bold word and it didn’t work.

  34. Try and view the source of the email you send in non-formatted case and in formatted case.

    If you see 7-bit when you just bold a word, well that’s bad. :(

    Look at the source: if you manage to understand anything from the 7bit, then my software is not good. If you don’t get to understand the email, neither can the PHP software. :(

    It’s not typical & right to convert an email to 7-bit only for bolding one word.

    May I suggest another email software for Mac?

    Olivian BREDA’s last blog post..Why vote? The one reason for which anyone should vote. Read this message, and then go voting!

  35. Great post, thanks for the info

  36. I’ve never given this a try, but I think it’s about time I do.

  37. Go ahead, Dillon. :D

    Olivian BREDA’s last blog post..Four things I’ve learned at recent events in my life

  38. Does this still work in 2.7?

    Programmer Career’s last blog post..What was your first programming book?

  39. Sorry, I haven’t kept updating this software. Actually, it’s not tested for WP 2.7

    Olivian BREDA’s last blog post..What insights I had on “Walk on your own path” – seminar by Vasile PAUN?

  40. I tired with gmail a/c but didn’t work, it didn’t publish when it received new mails/post.

    The URL I used is: ssl://pop.gmail.com, is this right? However, I am still facing the error/status as “Slow down cowboy, no need to check for new mails so often!”. Any help will be appreciated.

  41. Hi Veeresh, what version of WordPress have you used?

  42. is this even working now ???

    if we are doing this

    if (( is_email($author) ) && ($author == ‘PUTYOUREMAILADDRESSINHERE@SOMEMAIL.COM’)) {

    with this line:
    if ( is_email($author) ) {

    then where to specify email id ???

  43. niki, this version worked fine for WordPress 2.7. I don’t know about the new versions, sorry; you could ask on the wordpress.org forums; let me know if I can help you with something.

  44. thanks for your kind reply dude … i am searching to post via email to my self hosted wordpress blog and not able to find any thing for past 2 days .. can you please help with some other that is working …

    thanks in advance …

  45. If you want to use my solution, Google for an older version of WP:
    http://wordpress.org/download/release-archive/

    and try to use my solution. For support for a newer version, try posting on http://wordpress.org/support/

    I would appreciate if you would put a comment if you find a good solution, for others to know about it.

    Hope this helps. Good luck!

Lasă un comentariu

Adresa ta de email nu va fi afișată pe site. E OK să pui linkuri utile.





Abonează-te la comentariile articolului prin RSS.

Vezi ce drepturi ai, care sunt termenii și condițiile blogului.
Know your you rights, see the terms and the conditions for this blog.



Unde s-a vorbit despre asta

  1. links for 2008-10-01 « Schedelbeuk - [...] WordPress: How to use wp-mail.php correctly in Gmail blog posts? This … (tags: wordpress) [...]
  2. How to Posting Blog From Email to Wordpress | VR Junkyard - Articles, Tips, Downloads, Infos, and lots more - [...] - The installing is done but yours doesn’t seems to work? use the wp-mail.php plugin from this blog …
  3. ~daily random journal of the netholic vierz~ » Cara posting blog ke wordpress dari email dan blackberry - [...] Udah deh selesai. Tapi kalo udah install blom bisa juga pas ngerefresh wp-mail.php nya, pake aja plugin wp-mail.php yang …