PHP Code for sending Emails


The below code sends a email through PHP code,
<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

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

<body>

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

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

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

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

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

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

</body>
</html>

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

<?php

$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
mail($mailTo,$mailSubject,$mailBody,$mailHeaders);

?>