Functional Form To Send Email From Web Page
75Mail Form PHP/HTML
There are many cases when building a web-page when you have the need to send an email to your own email address, such as the case of a "contact-us" form.
These are typically used for requesting information or sending a message to the relevant party affiliated with the website, for example, a sales person following up on leads.
There is an adventatious side-effect to using a form instead of a link to an email address. This is that web-crawlers will not be able to see the email address and therefore not harvest it for spam databases.
For the purpose of this tutorial, I will assume that the reader has some basic scripting and html experience. For this example, I am going to use PHP which, if you are hosting your site with any major web-host you will have available to you.
Creating A Form
Create a form as usual in HTML. You will have your regular input values and submit button. The difference here is that you will change your action to point to a created PHP page, e.g. action="sendMail.php"
The form for this example must contain two input fields, emailFrom and message.
PHP Send Mail Page
This would be a seperately created .php file which would reside in the same directory as the page wanting to send the email. The example below is the entire page and can be copied without any knowledge of PHP.
<code>
<? PHP
$message = $_GET['message'] ;
$email = $_GET['emailFrom'] ;
mail( "yourEmail@yourDomain.com", "Subject of email, change this to whatever you want", $message, "From: $emailFrom" );
print "Your email has been sent, click xxxxx (insert html link) to return to the main page";
?>
This is all that is needed to easily send an email from your webform. If you get any errors, you should contact your hosting provider and ensure that you have permissions to run PHP scripts.
Please leave a comment if you have any questions.
Share it! — Rate it: up down [flag this hub]

