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: \r\n";
$mailHeaders .= "Return-Path: \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


Recent Posts:

Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.