How to send html emails using php

1
2
3
4
5
6
7
8
/*
*
* Write down your message or generate your message and parse it with the
* htmlentities function to work properly with the email server
*/
 
$message = "Hiii this is waytcode & am sending you an email !!!";
$message= htmlentities($message);

1
2
3
4
5
/*
*
* ow Create a HTML email Template and put your parsed email inside it
*
*/

$body = "<html>n";
$body .= "<body style="font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#666666;">n";
$body = $message;
$body .= "</body>n";
$body .= "</html>n"

1
2
3
4
5
6
7
8
9
10
11
12
13
/*
*
* Now define the Header information about your email ,
* this is the most important part of your email
*/
 
$to = 'username@example.com';
$subject = 'Subject goes here';
$headers = "From: bikash@example.comrn" .
'X-Mailer: PHP/' . phpversion() . "rn" .
"MIME-Version: 1.0rn" .
"Content-Type: text/html; charset=utf-8rn" .
"Content-Transfer-Encoding: 8bitrnrn";

 

1
2
3
4
5
6
/*
*
* Now send the email using the mail function of PHP
*
*/
mail($to, $subject, $body , $headers);