PHP Code for sending Emails

The below code sends a email through PHP code,
<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

<title>Sending Email using PHP : Code2care Examples</title>


<form action="EmailSender.php" method="post">

To : <input name="to" type="text" />

Subject : <input name="subject" type="text" />

From : <input name="from" type="text" />

Body : <textarea name="body" rows="25" cols="100"></textarea>

<input type="submit" value="submit"> 


Below is the PHP file that is called when the form is submitted,


$mailTo = $_POST['to']."\r\n";
$mailSubject = $_POST['subject']."\r\n";
$mailBody = $_POST['body']."\r\n";
$mailHeaders = "From: ".$_POST['from']."\r\n";
$mailHeaders .= "Reply-To: [email protected] \r\n";
$mailHeaders .= "Return-Path: [email protected] \r\n";
$mailHeaders .= "X-Mailer: PHP5 \r\n";
$mailHeaders .= 'MIME-Version: 1.0' . "\r\n";
$mailHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

//Send Email Function