Creating a Basic Form
Processing Form Data with PHP
Sending Confirmation Email
Creating a Thank You Message for Your Form
Saving Form Information to File
Making a Simple Send to Friend Script





 
Processing From Fields with PHP.

So now that we have our form set up, we need to process it and control what happens to the form data.  The first step is to convert the variables of your form fields to something that is understood by php.

$email = $_POST["emailaddress"];

This is converting the name of your text field "emailaddress" to the php equivalent "$email".  So what this will do is anytime you place "$email" in the file, it will produce whatever was entered into that form field. Now we need to add items to mail the results.

$to = "you@youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";

$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n

Email Address: $email";

So now you have indicated who will receive the form information.  The subject line, and who its from.  Notice how in the from area it calls "$email" ... this will post the email address entered in the form.

We also added a small message, and the email address again.

The last step is to actually mail the information, and we do that using this line of code.

mail($to,$subject,$message,$headers);

So here is the full code for the "process.php" page to take the text field of your form, convert to php, and send the data to your email.

<?PHP
$email = $_POST["emailaddress"];

$to = "you@youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";

$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n

Email Address: $email";

mail($to,$subject,$message,$headers);

?>

Previous - Next