An exclamation mark appears in the body of an email using phpmailer

I use phpmailer to send emails on my website. My code works fine, but sometimes the body of the email contains an exclamation point in 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(); 

It works great. But he cannot find why sometimes an exclamation comes. Thanks in advance...

+6
source share
4 answers

I think because email messages cannot contain more than 998 characters per line.

Try to add

 $mail->WordWrap = 50; 
+8
source

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

Use this line to encode the entire message with base64:

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

Then add this heading:

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

This will tell the email client that your message is base64 encoded.

+3
source

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)) inside.

+1
source

I also had this problem, after a long search, I found that you should fold your HTML

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

Source: https://habr.com/ru/post/927461/


All Articles