Thursday, June 26, 2008

Sample Code to send html mail in php

Sample Code to send html mail in php




The following code can be used to send html emails using php:

/** define email fields **/
$email_text = "Dear Friend

I am sending you HTML based email using PHP .";
$subject = "Your Subject";
$from_name = "Your Name";
$from_email = "yourEmail@sender-email-address.com";
$to_email = "receiver@receiver-email-address.com";

/** construct headers **/
$headers = "From: $from_name <$from_email>\r\n";
$headers .= "Content-type: text/html\r\n";

/** send the email **/
if (mail($to_email, $subject, $email_text, $headers)) {
echo "Html mail sent successfully.";
} else {
echo "Error";
}


No comments: