Simple PHP Form Mail Tutorial
Tuesday, 12 June 2012
0
comments
Simple mail form
This tutorial will show you how to create a simple form mail that emails a specified email.
The Following Code is the actual form where the input can be typed.
CODE
<form method="post" action="mailME.php">
<table border="1" width="444" height="41" style="border-collapse: collapse" bordercolor="#000000">
<tr>
<td height="4" width="95">
<b>YourEmail:</b> </td>
<td height="4" width="342"> <input type="text" name="email" size="45"></td>
</tr>
<tr>
<td height="27" width="95">
<b>Subject:</b></td>
<td height="27" width="342"> <input type="text" name="subject" size="45"></td>
</tr>
<tr>
<td height="20" width="95"><b>Message:</b></td>
<td height="20" width="342">
<textarea name="comments" cols="20" rows="1"></TEXTAREA></td>
</tr>
</table>
<p>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Reset"></p>
</form>
<p> </p>
As you can see above that just a simple html form, save this as contact.html
This is where the php begins
CODE
<?
// Replace with your email address!
$to = "YOUR_EMAIL@EMAILHOST.COM";
if($submit)
{
mail("$to", "$subject", "$email", "$message");
} else {
echo "There was an error please try again";
}
?>
<form method="post" action="mailME.php">
<table border="1" width="444" height="41" style="border-collapse: collapse" bordercolor="#000000">
<tr>
<td height="4" width="95">
<b>YourEmail:</b> </td>
<td height="4" width="342"> <input type="text" name="email" size="45"></td>
</tr>
<tr>
<td height="27" width="95">
<b>Subject:</b></td>
<td height="27" width="342"> <input type="text" name="subject" size="45"></td>
</tr>
<tr>
<td height="20" width="95"><b>Message:</b></td>
<td height="20" width="342">
<textarea name="comments" cols="20" rows="1"></TEXTAREA></td>
</tr>
</table>
<p>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Reset"></p>
</form>
<p> </p>
As you can see above that just a simple html form, save this as contact.html
This is where the php begins
CODE
<?
// Replace with your email address!
$to = "YOUR_EMAIL@EMAILHOST.COM";
if($submit)
{
mail("$to", "$subject", "$email", "$message");
} else {
echo "There was an error please try again";
}
?>