Try this. I've just tried it and it works.
- Code: Select all
<html>
<body>
<form id="form1" name="form1" method="post" action="">
<p>
<label for="email"></label>
<span>Type anything here!</span>
</p>
<p>
<input type="text" name="message" />
<input type="submit" name="mysubmit" value="Send" />
</p>
</form>
<?php
if(isset($_POST["mysubmit"])) {
$to = "email@yourdomain.com";
$subject = "test mail";
$message = $_POST["message"];
if(mail($to,$subject,$message)) {
echo "Mail Sent.";
} else {
echo "Failed!";
}
}
?>
</body>
</html>
To make things simple I've left out the <table>. When you make a form, it's just a plain html, no php. And remember to assign name="namehere" to every input, as the inputs would be passed to php with the name.
When it comes to processing the input from the form,
- Code: Select all
if(isset($_POST["mysubmit"])) {
This code checks if a form is submitted, if yes, then it continues to execute the code in it.
Oh, and one more thing is that, when you choose method="post", the inputs will be stored in an array $_POST when it is passed to PHP, $_GET for method="get".
I suggest you reading some great tutorials found out there, like this one in w3schools.
http://www.w3schools.com/php/php_forms.asp