Sunday, September 29, 2013
Sending mail with PHP mail() Function
Sunday, September 29, 2013 by Unknown
Hiiiiiii, we all at sometimes need a mail sending functionality in our PHP code . For this PHP community has given a very useful function to send a mail within your php code. This mail sending function name is mail() function and this function is very easy to use with no extra unusual parameters.So, in this tutorial , I'll be giving tutorial of how to use mail function.
NOTE : You cannot test mail() function on your local machine as it will create a SMTP error, to test this function , you have to host your website on some hosting sites.
mail() Function Syntax :
mail(to,subject,message,headers,parameters)
mail() Function usage :
<?php
$to = 'klm@example.com'; // single recipients
$to .= ', ''nop@example.com'; // multiple recipients
// subject
$subject = 'Test Mail';
// message
$message = '
<html>
<head>
<title>Test Mail</title>
</head>
<body>
<table>
<tr>
<th>Name</th><th>Age</th>
</tr>
<tr>
<td>Rohit</td><td>23</td>
</tr>
<tr>
<td>Shilpi</td><td>24</td>
</tr>
</table>
</body>
</html>';
// To send a mail with HTML format and CSS , the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: XYZ<xyz@example.com>, ABC<abc@example.com>' . "\r\n";
$headers .= 'From: MyCodeStock <mycodesstock@gmail.com>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
Hope you like this post……..Please Comment…………!!!!!!!!!
Tags: HTML , PHP
Subscribe to:
Post Comments (Atom)
0 Responses to “Sending mail with PHP mail() Function”
Post a Comment