How to send an email using php ?

In this article, We’ll see how to send an email using php?

before sending an email, we’ll read about mail function.

php mail function used to send an email, it takes require three parameter i.e recipient’s email address, subject of the email and message. There are other two optional parameters.

Below the syntax of mail function.

   bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

let’s see example

Example1: Send an email with extra headers:

	$to      = "";
	$subject = "Mail Subject";
	$txt     = "Welcome to!";
	$headers = "From:" . "\r\n" .


Example2: Send an html email:

$to      = "";
$subject = "Php html email";

$msg     = "<html>
				<title>Php Html email</title>
<th>Tutorial Site</th>






// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <>' . "\r\n";
$headers .= 'Cc:' . "\r\n";

mail($to, $subject, $msg, $headers);

That’s it!. Please share your thoughts or suggestions in the comments below.

Posted in PHP

Leave a Reply

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