Printed from: http://www.stylehack.com/wordpress/index.php/2004/10/24/wordpress-hack-wp-mail-02/
I pulled the newest version (at the time) of WP-Mail 0.2 off of the
author’s site. It’s a nifty little tool that offers these options via an emailed post:
– can assign entry to a specific category of your choice
– can attach images/photos and have them inserted into your post
– ok to put coding into the body, including
iG Syntax Highlighter coding if you use that plugin
– post is processed one of two ways: via cron job or when you manually run the script from a browser
Things it can’t do at this time:
– look up categories (you have to know your category numbers, not just titles)
– send in a post and hold it as a draft or mark it as private
– turn on/off pingback, comments, etc… all your defaults come into play
– autoprocess entries as they come in instead of relying on a cron job or manual processing
Installation Notes
It’s really nicely documented in a README file that probably works well for a standard WP installation. I, of course, did things just a little bit differently so I had problems with consistent pathing. Being a slacker I took the easiest way possible out and so I thought I’d share the lazy solution for others like me.
My WP installation is not in the root of Stylehack, it’s in a directory of its own. So I actually have 2 versions of index.php… one in the root of Stylehack that points to the directory containing WP, and one in the WP directory itself that has not been changed from the standard install.
The problem I ran into with this hack relates to the path to the directory where the images are ultimately stored; there was no 2 second fix I could find that corrected the path problem posed by the two index.php files. The images ended up being available in one or the other “incarnation”, but not both. I tried many forms of pathing to try to keep things under the WP directory but finally decided to put them in the root and get it over with. “-)
Here’s the pathing I used (lines 32-34):
//global vars you can change
$photosdir = '../wp-pix/';
$filesdir = '../wp-filz/';
It just seemed less work to put them there and not have another variable somewhere to have to remember to change down the road.
The other thing I noticed about this script hack was that the entry time was just not correct for me. I did read on the author’s site and searched the WP Wiki forums but didn’t find a fix that would work for a dummy like me. So here’s what I did (lines 103-104):
//date reformatting modified Becky Peters for CST time via EST server 10 17 04
$post_date = date('Y-m-d H:i:s', strtotime($ddate) - (3600));
$post_date_gmt = gmdate('Y-m-d H:i:s', strtotime($ddate) );
Yep, I hardcoded in the - (3600) to force the time of the post to be correct for my local time (CST) reading from a server hosted in EST.
It works, I’m happy. Just happy, not a php programmer. “-)
Notice that I put in the comment starting // with info on what I did. It’s important that you always comment your own hacks so you don’t forget them. I always put in my name so I can search all modified files for it at once.
After you install it, you should test it manually. Email yourself a post, then go to your blog and type this in the address bar:
http://yourblog.com/path/to/wordpress/wp-mail.php
If it works, you’ll see a message telling you so, listing your post and displaying attached images (if any). Then check your index page to see if the images show up, the post is formatted properly, etc.
Tip: You’ll need to edit the entry at some point and add the ALT and TITLE tags to the images.
Before I go any further, let me make a comment about the format of the email you send: The README file gives some detailed instructions on how to format your mail (text v. html v. html/text). I use Thunderbird and found that I got consistent results whether I specified Text or left it at Auto… when I said “HTML (only)” it didn’t “look” the way I expected after it was posted to this blog. I tested it quite a few times… well, actually about 20 times. sheepish look.
Cron Job
This is the part that might confuse or scare you if you haven’t set one up before. I’m not going to teach you the basics here (there are a lot of sites that will do that for you — think Google); but I will tell you that if you have access to an interface like cPanel it should be pretty painless.
Here is the job form I set up using cPanel (you’d have to put in your own info):
wget http://yourblog.com/path/to/wordpress/wp-mail.php
I personally set it up to run every 6 hours, every day of the week & every month of the year. But that’s me, you might want it to run more often or less often.
The other thing you set up with a cron job is email notification — you can have it send you email each time it runs to let you know it has run, blah blah. Oh yeah, just what I need… more stupid notifications. If you leave the email address blank in cPanel it will not email you each time it runs.
Note: The README instructions say to use GET instead of WGET, but the server I am on didn’t like that so I chose to use WGET instead.
That’s about all I have to report on my experience with this hack. Well, that and that it is a great little tool! I hope the developers take the author up on his offer to include it (and planned enhancements) in future versions of Wordpress!
[Yep, I wrote this in EditPadPro and emailed it in when I was ready to do so. wink]
No comments yet.
Sorry, the comment form is closed at this time.