Friday, 15 August 2014

PHP mail() Function

Send an HTML email:

<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Libero</td>
<td>Ram</td>
</tr>
</table>
</body>
</html>
";

// 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: <Liberoram@example.com>' . "\r\n";
$headers .= 'Cc: liberoram@example.com' . "\r\n";

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

No comments:

Post a Comment