Click here to Skip to main content
12,621,168 members (31,910 online)
Rate this:
 
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 18:35pm
Comments
Sandeep Mewara 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 9 Feb 2013
Copyright © CodeProject, 1999-2016
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