Exclamation mark randomly as a result of PHP-HTML-Email

I get exclamation points at random points as a result of this PHP email function. I read that this is because my lines are too long or I need to encode the email in Base64, but I don't know how to do it.

This is what I have:

$to = " you@you.you "; $subject = "Pulling Hair Out"; $from = " me@me.me "; $headers = "From:" . $from; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers .= "Content-Transfer-Encoding: 64bit\r\n"; mail($to,$subject,$message,$headers); 

How to fix it so that it is not random! as a result? Thanks!

+6
source share
4 answers

As stated here: HTML Exclamation Mark

The problem is that your line is too long. Submit an HTML string longer than 78 characters in the mail function, and you get the result! (bang) on ​​your line.

This is due to string length restrictions in RFC2822 http://tools.ietf.org/html/rfc2822#section-2.1.1

+8
source

Try using this piece of code:

 $to = " you@you.you "; $subject = "Pulling Hair Out"; $from = " me@me.me "; $headers = "From:" . $from; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers .= "Content-Transfer-Encoding: 64bit\r\n"; $finalMessage = wordwrap( $message, 75, "\n" ); mail($to,$subject,$finalMessage,$headers); 

The problem is that one line should not exceed 998 characters. (see also fooobar.com/questions/927461 / ... )

+3
source

The answers here have the correct information about the length of the string, however, none of them provided me with a sufficient piece of code to fix the problem. I looked around and found a better way to do this, here it is:

 <?php // send base64 encoded email to allow large strings that will not get broken up // ============================================== $eol = "\r\n"; // a random hash will be necessary to send mixed content $separator = md5(time()); $headers = "MIME-Version: 1.0".$eol; $headers .= "From: Me < info@example.com >".$eol; $headers .= "Content-Type: multipart/alternative; boundary=\"$separator\"".$eol; $headers .= "--$separator".$eol; $headers .= "Content-Type: text/html; charset=utf-8".$eol; $headers .= "Content-Transfer-Encoding: base64".$eol.$eol; // message body $body = rtrim(chunk_split(base64_encode($html))); mail($email, $subject, $body, $headers); // ============================================== 
+2
source

You are right because your email is too long. Try replacing this line in your email header.

 Content-Transfer-Encoding: quoted-printable 
+1
source

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


All Articles