Home » Php » php – exclamation mark is appears in email message body using phpmailer

php – exclamation mark is appears in email message body using phpmailer

Posted by: admin July 12, 2020 Leave a comment

Questions:

I m using phpmailer for sending emails in my website. My code works fine but sometimes in email message body contains exclamation mark at random places. My code is as follows:

$mail->SetFrom(FROM_EMAIL,FROM_NAME); //emailid of sender(admin)                
$mail->Subject = 'Subject here.'; //subject of email
$mail->AddAddress(Address here); //emailid of user(recipient)
$content = 'some html code here';

$mail->MsgHTML($content); //this is body of email
$mail->Send();

This works fine. But can’t find why exclamation comes sometimes.
Thanks in advance…

How to&Answers:

I think it’s because the email messages can’t have more than 998 characters on one line.

Try adding,

$mail->WordWrap = 50;

Answer:

I know this is late but there is an alternate solution that worked for me:

Use this line to encode your entire message using base64:

$message = chunk_split(base64_encode($message));

Then, append this your header:

$headers .= "Content-Transfer-Encoding: base64\r\n\r\n";

That will tell the mail client that your message is base64 encoded.

Answer:

if you are using PHPmailer then only one line of code should help:

$mail = new PHPMailer();
$mail->Encoding = 'base64';

this will do Content-Transfer-Encoding: base64 and chunk_split(base64_encode($message)) internally.

Answer:

I had this problem also, after long searching I have found that you should wordwrap your HTML

$emailContent = '<p>some large html</p>';
$mail->msgHTML(wordwrap($emailContent, 50));