Reputation: 577
I am trying to send emails from PHPMailer. Everything is working but the problem is it is sending emails along with HTML tags even after writing $mail->IsHTML(true);
. Below is my code for sending emails.
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = EMAIL_COMPOSE_SECURE;
$mail->Host = EMAIL_COMPOSE_SMTP_HOST;
$mail->Port = EMAIL_COMPOSE_PORT;
$mail->Username = EMAIL_COMPOSE_OUTGOING_USERNAME;
$mail->Password = EMAIL_COMPOSE_OUTGOING_PASSWORD;
$mail->SetFrom(EMAIL_COMPOSE_INCOMING_USERNAME);
$mail->Subject =$subject;
$mail->Body = $message;
$mail->IsHTML(true);
$mail->AddAddress($email_to);
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
And one more thing I will mention, in my application text editor for writing the emails is ckeditor. Will that cause any problem? Please help.
Upvotes: 7
Views: 19655
Reputation: 37818
Why would you not expect it to use HTML if you call IsHTML(true)
? That's how you tell PHPMailer to treat your message body as HTML! If you don't want HTML as the content type, call IsHTML(false)
, or just don't call it at all since plain text is the default.
If you want both HTML and plain text, call msgHTML($html)
instead and it will also handle the HTML->text conversion for you.
As Chris said, call IsHTML
before setting Body
.
And as Dagon said, if you put HTML in $message
, it will send HTML...
Upvotes: 8
Reputation: 3730
Unless I'm misunderstanding your question, it should be sending the HTML tags. Check that the received email has the Content-Type:
is text/html
.
It has to send the HTML tags still for the client at the other side to be able to display it properly. If the message contains HTML tags and you don't want the tags, then you want to call IsHtml(false)
and you need to actually strip the HTML from the message.
Not all email clients can read HTML tags. So if you're seeing the HTML it's either because your client can't render HTML, or that the Content-Type:
is text/plain
.
Upvotes: 0