Thursday, February 2, 2012


I tried my luck at PHP today. The problem was to be able to create a form and have it post to a blog. Thus allowing any viewer to post to that blog. So the concept was similar to that of mlib, fml, etc. But how can someone do that for free? Or without designing a whole website in ruby on rails? Simpler than I thought.
Here's what I did:
Create an html form:
<form method="post" action="mailer.php">
<p>Title:<input type="text" id="title" name="title" size="19"></p>
<textarea rows="9" name="message" cols="30" id="message"</textarea><br>
<input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset">
Which then links to a PHP file that handles it:

$to = "";
$subject = $_POST['title'];
$message = $_POST['message'];
echo "submitting... \n";
$headers = 'From: default <>' . "\r\n";
mail($to, $subject, $message, $headers) or die("failure");
echo "done\n";
echo "redirecting in 5 seconds, otherwise click";
echo "<a href=\"\">here</a>\n";
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=">';

For the TO address, change your blog mobile/email settings to accept posts from a "secret" email, and use that address.  
Next, upload both files to the same directory on a PHP enabled server, and link to the form on your blog.
The website:

No comments:

Post a Comment