Tutorial details
Name : PHP HTML Email Form
Author : Kenneth Clark
Language : PHP 4
Platform : Platform Independant
Click here if you require development or hosting solutions : [ SkyeTech Solutions ]

This tutorial will show you how to create a simple HTML form that will email the data using PHP

First we need to define our form. A basci form will look something like: (this can be called email.html)

<form action="mailinfo.php" method="post">
  First Name: <input type="text" name="frmName"><br />
  Last Name: <input type="text" name="frmLastName"><br />
  Email : <input type="text" name="frmEmail"><br />
  <input type="submit" value=" Send " />
</form>
Pretty easy huh? The interesting things to note here are the input names, they will be used to retrieve the values from the form. So in other words the input with the name "frmName" will be accessed in the PHP POST array something like
//this will give us the value for an input with the
//name frmName (name="frmName")
$name = $_POST['frmName'];
Right now we get onto mailinfo.php
<?php
$firstName = isset($_POST['frmName'])
             ? $_POST['frmName'] : "No Name";
$lastName = isset($_POST['frmLastName'])
             ? $_POST['frmLastName'] : "No Last Name";
$email    = isset($_POST['frmEmail'])
             ? $_POST['frmEmail'] : "No Email supplied";
$mailBody  = "First Name : " . $firstName . "\n";
$mailBody .= "Last Name : " . $lastName . "\n";
$mailBody .= "Email : " . $email . "\n";

$mailResult = @mail("youremail@yourdomain.com",
                    "Email subject here",
                    $mailBody,
                    "From: " .$email);

if($mailResult){
  echo "Mail sent!";
}else{
  echo "Mail send failed";
}
?>
Now save the files and give it a spin! Make sure you are running this through a server that has PHP 4 or greater enabled on it.

Quick explanation
The HTML form submits the data inside it to the page mailinfo.php When mailinfo.php recieves the data, it formats the data into an email body, adds a busject and mails it off to the email you gave it.


SkyeTX Technologies Business Software Solutions
SkyeTX Technologies Business Software Solutions