AutoBlogger – Post feed to your blog

PHP script — By on March 23, 2009 at 8:55 pm

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.

<?php

//Your Blog’s Keyword: Hosting, Domain, etc

$keyword = “keyword”;

//How many articles do you want to grab each time? exp: 10 posts

$num = 10;

//Get the RSS Feed – In this instance, we’re using a google blogsearch feed based on our chosen keyword

$feed = simplexml_load_file(“http://blogsearch.google.com/blogsearch_feeds?hl=en&scoring=d&q=” .urlencode($keyword). “&ie=utf-8&num=10&output=rss”);

//Loop through our keywords

foreach ($feed->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(“<b>”, “”, $title);

$subject = str_replace(“</b>”, “”, $title);

$link = $item->link;

$description = $item->description;

$description = str_replace(“<b>”, “”, $description);

$body = str_replace(“</b>”, “”, $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<br>”;

}

else

{

echo $subject. ” – NOT sent<br>”;

}

}

//add one to our counter

$i++;

}

?>

Customise the script to suit your purposes, upload to your server, and call it via a cron job.

Now on to the script:

Tokokoo 300x250
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...

Random Articles

0 Comments

You can be the first one to leave a comment.

Leave a Comment


Tags: , , ,