Send Email in HTML Format
-
Hello guys, I want to be able to send mail in html format like the one below but I get the raw html in my mail.
include_once "Mail.php";
function isMailSent($from, $to, $subject, $body) {
$host = "mail.domain.com";
$username = "email@domain.com";
$password = "password";$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
try {// add to the body
$body = '' . $body . '
Thank you!
';
// dispathc mail
$mail = $smtp->send($to, $headers, $body);// check if mail was sent successfully
if (PEAR::isError($mail)) {
return "" . $mail->getMessage() . "
";
} else {
return "Message successfully sent!
";
}} catch (Exception $e) {
return $e->getMessage();
}
}Please help.
-
Hello guys, I want to be able to send mail in html format like the one below but I get the raw html in my mail.
include_once "Mail.php";
function isMailSent($from, $to, $subject, $body) {
$host = "mail.domain.com";
$username = "email@domain.com";
$password = "password";$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
try {// add to the body
$body = '' . $body . '
Thank you!
';
// dispathc mail
$mail = $smtp->send($to, $headers, $body);// check if mail was sent successfully
if (PEAR::isError($mail)) {
return "" . $mail->getMessage() . "
";
} else {
return "Message successfully sent!
";
}} catch (Exception $e) {
return $e->getMessage();
}
}Please help.
I don't know much about PHP, but you must pass the proper content type in the mail header (adjust the charset and encoding if necessary, e.g. charset us-ascii with encoding 7bit):
$headers['Content-Type'] = "text/html; charset=\"UTF-8\"";
$headers['Content-Transfer-Encoding'] = "8bit"; -
I don't know much about PHP, but you must pass the proper content type in the mail header (adjust the charset and encoding if necessary, e.g. charset us-ascii with encoding 7bit):
$headers['Content-Type'] = "text/html; charset=\"UTF-8\"";
$headers['Content-Transfer-Encoding'] = "8bit";Thanks a million. I will do what you said!