Friday 27 February 2009

Autopost to Blogger blogs with PHP script

1 comments
Yes, you can autopost to blogspot (blogger) blogs with php, and it’s a lot easier than you might think.
Similar to the way that plugins like wp-o-matic work for automatically posting rss feeds to Wordpress blogs, you can have a blogger blog which is automatically populated with RSS feed content, at intervals that you determine (by a cron job).
Blogger blogs allow the blogs owner to post via email, so we’re going to use PHP’s mail function to post new content, and PHP’s SimpleXML to gather the content before posting.
Firstly, we need to set up our blogger blog to accept emailed posts: We need to go to our settings page in Blogger, and click the “Settings” tab at the top. Then click the “email” button.
You’re now at the Email settings page, look for the Mail-to-Blogger Address. Here you just need to enter a password (in the box before the “@ablogger.com”) that you’ll use in your emails to post to the blogger blog.
Once you’ve chosen your password, write down the email address, as this is the email address we’ll be using in the PHP script to tell it where to post the rss feed to.
Now on to the script:
channel->item as $item) {
if($i < $num){ //Have a bit of a rest so we’re not posting too fast to our blogger blog sleep(10); $title = $item->title;
$title = str_replace(””, “”, $title);
$subject = str_replace(”
”, “”, $title);
$link = $item->link;
$description = $item->description;
$description = str_replace(””, “”, $description);
$body = str_replace(”
”, “”, $description);
//put our secret blogger email address here:
$to = “accountname.password@blogger.com”;
//ignore this line - the script just needs something in the “From” field.
$headers = ‘From: mail@whatever.com’;
//Send the email / How’d we go?
if(mail($to, $subject, $body, $headers)) {
echo $subject. ” - sent
”;
}
else
{
echo $subject. ” - NOT sent
”;
}
}
//add one to our counter
$i++;
}
?>
And that’s it.
Customise the script to suit your purposes, upload to your server, and call it via a cron job.

Comments

1 comments to "Autopost to Blogger blogs with PHP script"

Unknown said...
4 January 2013 at 01:47

btw, where i can add the feed URL address to get feed from ??

Post a Comment

Labels

 

Copyright © 2009 by Free Blogger Themes. Revolution 2 Church Theme by Brian Gardner. Converted into Blogger Template by Bloganol dot Com