How to send a mail in php ?

PHP have a feature which allows you to send the mail from the server using mail() function.

In order to sent mail using php  it requires three mandatory  parameters 
  1. The Reciever 
  2. The Sender
  3. The subject
And the more optional parameters like headers and others …
Syntax for PHP mail function..
   mail( to, subject, message, headers, parameters );
Example : 
$to = “,”;
$subject = “The test email from php”;

$message = “
<title>Here Goes the test email</title>
<p>The php email from php interview questions </p>
<th>Name </th>

//  setting the  content-type for sending HTML email
$headers = “MIME-Version: 1.0” . “rn”;
$headers .= “Content-type:text/html;charset=UTF-8” . “rn”;

// More headers for sender and CC
$headers .= ‘From: <>’ . “rn”;
$headers .= ‘Cc:‘ . “rn”;


Here ,
$to stand for the receiver
$subject as subject line 
$message  as the message body 
$headers as optional parameters 

Leave a Reply

Your email address will not be published.Required fields are marked *