PHP mail is a simple mail function for PHP. It is used to send emails right from your web pages. It also allows you to send plain text and HTML based emails. Here are is a simple tutorial on how to send HTML emails from your website.
First step is to set parameters for recipient and subject
1 2 |
$Recipient = "tom@example.com"; $Subject = "My HTML Email"; |
Now let’s setup our message body with html tags.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$myMessage = "This is my HTML based email!"; $myMessage .= " <table> <tbody> <tr> <th>Firstname</th> <th>Lastname</th> </tr> <tr> <td>John</td> <td>Smith</td> </tr> </tbody> </table> "; $myMessage .= "Best regards"; |
Always set content-type when sending HTML email
1 2 |
$headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; |
You can set more headers
1 2 |
$headers .= 'From: ' . "\r\n"; $headers .= 'Cc: myccemail@example.com' . "\r\n"; |
Now we are ready to send the email
1 |
mail($Recipient,$Subject,$myMessage,$headers); |