Easy blogging with your mobile phone

I decided to see if I could write a simple web interface to Blogger that I could use from my mobile phone. To my surprise it was quite easy, even with my very limited PHP-skills. Follow the instructions below and you will be mobile blogging in no time.

What you need:
  • A web server you control, with Apache, PHP and mod_php.
  • The PEAR Mail package for PHP.
  • An account on an SMTP-server. Many ISPs provide one of these for you.
In the folder where you create your PHP-files, created two files, newblog.php and newblog_settings.php.

The approach here is not to use any of the APIs (I counted to at least three, all supported by Blogger) that Blogger provide. Instead I took the easy way out and decided to use the e-mail "gateway" to create glob posts.

First, create the settings file:

// -----------------------------
// Configuration for newblog.php
// -----------------------------
// Password required to submit the post
$required_pass = "password";
// Blogger e-mail address. This is enabled and the secret
// configured in the admin interface at Blogger.com.
$to = "My blog <username.secret@blogger.com>";
// From address.
$from = "Me <my.address@somedomain.net>";
// The SMTP-server to use.
$host = "smtp.somedomain.net";

Next, the actual code in newblog.php:

if ($method == 'GET')
<!-- Simple form. As light as possible. -->
<form name="newpost" action="newblog.php" method="post">
<input type="password" name="pass">
<input type="text" name="subject">
<textarea name="body"></textarea>
<input type="submit" value="Create post">
} elseif ($method == 'POST')
$pass = $_POST['pass'];
if ($pass == $required_pass)
$subject = $_POST['subject'];
$body = $_POST['body'];
if ($subject == '' || $body == '')
echo "<p>Subject and body is required!</p>";
require_once "Mail.php";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => false));
// If authentication is needed, use this:
// $smtp = Mail::factory('smtp',
// array ('host' => $host,
// 'auth' => true,
// 'username' => 'user',
// 'password' => 'pass'));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail))
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message with subject \"" . $subject . "\" successfully sent!</p>");
echo("<p>Wrong password!</p>");
<p><a href="/newblog.php">Create a new post</a></p>

The code should be quite easy to understand so I won't get into any details here.

The password check is very basic but it should work well as long as no one is sniffing your network connection. And if they do I guess you could always enable SSL.

The result of running the script looks like this:


And after posting:


Resulting post:


The screenshots are from a normal browser, but the result should look similar in even simple mobile phones that have a recent XHTML-browser.

There is one "bug" with the script and that is that characters outside ASCII (127 bit) will not be transferred correctly to the blog. I haven't figured out why, but I guess I would have to fiddle with MIME-encodings to get that working.

Happy blogging!
Post a Comment