PHP Email Sample

This form submits to mail.php (shown below):

Source of: mail.php

<?php
// Always be sure to have some check so a random person does not use
// your mail program! Here i just check to make sure that the page 
// that has sent the information is my page.

if  ($HTTP_REFERER=="http://www.uvm.edu/~rerickso/education/php/mail/formmail.html"){

/* recipients */
$to $txtEmail ", " 
// note the comma ONLY used for sending to more than one person

$to .= "another@zoo.uvm.edu";

/* subject */
$subject $mail_subject;

//get date and time
$Todays_Date=strftime("%x");
$Current_Time=strftime("%X");

/* message */
$message '
<html>
<head>
 <title>Employee Termination</title>
</head>
<body>
<p>The following information reflects the form you filled out on '
;

$message $message .  $Todays_Date ', please keep this copy for your records.</p>
<p>Employee Number: ' 
$txtEmployeeID;

$message $message .  '<p>Employee Name: ' $txtEmployeeName '<p>Your Email: ' $txtEmail '<p>Termination Date: ' $txtDate '<p>This person is: ' $optEmployee

password REDACTED

/* To send HTML mail, you can set the Content-type header. */
$headers  "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */
$headers .= "From: PHP page <mtnbob@togehter.net>\r\n";

$headers .= "Cc: webmaster@uvm.com\r\n";
$headers .= "Bcc: anyone@zoo.uvm.edu\r\n";

/* and now to mail it 
   Code is commented out so it never really mails my sample */

//$blnMail=mail($to, $subject, $message, $headers);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <title>Form Information Mailed</title>
</head>

<body>

<h1>Mail has <? 
if ($blnMail==False) {
    echo 
"not ";
}
echo 
"been sent</h1><p>";

/* you could also display all the information
from the form as a way to show the user what
information has been sent */

echo $message;
}
else {
    echo 
"You are not supposed to be here :(";
}
?>
</body>
</html>