Snippet for a simple form example
A simple snippet posted here as a note and for all those who are looking with the form submit example. A very simple example that demontrates on creating a form with a submit and action.
The snippet would get the data submitted by a user using the form and will send an email to the admin.
First let’s create a page with the form ,let’s name it as our index.html.
[html]
<html>
<body>
<!–this is just a simple page ,no style is created –>
<form id="email_form" method="POST" action="sendmail.php">
<input type="text" name="name" size="20"/>
<input type="text" name="email" size="20"/>
<textarea name="message"></textarea>
</form>
</body>
</html>
[/html]
If you noticed on the code above, the form looks for sendmail.php so we will create sendmail.php for our form. It should be located where the index.html for this example.
[php]
<?php
$name=$_POST[‘name’];
$email=$_POST[’email’];
$message=$_POST[‘message’];
$headers = ‘MIME-Version: 1.0’ . "rn";
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . "rn";
$headers .= ‘From: ‘ . $name . ‘<‘.$email . ‘>’ . "rn";
$to = "xmeappxxxx@yahoo.com";
$subject = "Contact Form";
mail($to, $subject, $message,$headers);
header(‘Location: /index2.html’);
?>
[/php]
So that’s it.
If you have question just post below and give some comments.
The code above is not tested but it should work.
Thanks!
Very interesting sites I come back soon. I would say that the topic of this site is very useful. I recommend to visit me site http://superobozy.pl/.