Click here to Skip to main content
11,581,186 members (61,173 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP
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
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 8-Feb-13 17:35pm
Comments
Sandeep Mewara at 9-Feb-13 14:44pm
   
elaborate 'not working' a little - you see raw html? escaped data? what exactly?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

 
$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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 260
1 Frankie-C 145
2 Sergey Alexandrovich Kryukov 135
3 virusstorm 85
4 RyanDev 84
0 OriginalGriff 1,183
1 Sergey Alexandrovich Kryukov 825
2 Abhinav S 597
3 F-ES Sitecore 500
4 Suvendu Shekhar Giri 433


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 9 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100