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 : 
<?php
$to = “some@evernews.online, me@evernews.online”;
$subject = “The test email from php”;

$message = “
<html>
<head>
<title>Here Goes the test email</title>
</head>
<body>
<p>The php email from php interview questions </p>
<table>
<tr>
<th>Name </th>
<th>Age</th>
</tr>
<tr>
<td>PHP</td>
<td>20</td>
</tr>
</table>
</body>
</html>
“;

//  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: <php@evernews.online>’ . “rn”;
$headers .= ‘Cc: me@evernews.online‘ . “rn”;

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

?>
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 *