Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi i am using php mailer to sending mails.But i need to send the HTML content in php mail i refer lot of site all are says IsHTML(true) function is used to send HTML content in php mail.But its not working for me.

This is my coding.
PHP
<?php
function smtpmailer($to, $to_cc, $to_bcc, $from, $from_name, $subject, $body) {
global $error;
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host  = "smtp.gmail.com";
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "************@gmail.com"; // GMAIL username
$mail->Password = "********"; // GMAIL password
$mail->SetFrom($from, $from_name);
$mail->AddAddress($to);
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;

if($to_cc!="")
{
$mail->AddCC($to_cc);
}
if($to_bcc!="")
{
$mail->AddBCC($to_bcc);
}

if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
print $error;
return false;
} else {
$error = 'Message sent!';
print $error;
return true;
}
}
?>


Please help me to solve this.
Posted
Comments
Sandeep Mewara 9-Feb-13 14:44pm    
elaborate 'not working' a little - you see raw html? escaped data? what exactly?

1 solution

For HTML mails, consider adding plain text version, i.e.

PHP
$textBody = 'My text-only body....';

$mail->Body($htmlBody);
$mail->isHTML(true);
$mail->AltBody($textBody);


most likely it will solve your issue, as content/type will become multipart/alternative, and you will target wider amount of browsers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900