Exclamation Point Randomly In Result of PHP HTML-Email

后端 未结 4 1287
自闭症患者
自闭症患者 2021-01-04 08:26

I\'m getting exclamation points in random spots in the result of this PHP email function. I read that it\'s because my lines are too long or I have to encode the email in Ba

相关标签:
4条回答
  • 2021-01-04 08:29

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

    Content-Transfer-Encoding: quoted-printable
    
    0 讨论(0)
  • 2021-01-04 08:32

    The answers here have the correct information regarding the line length, however none of them provided me with the sufficient code snippet to fix the issue. I looked around and found the best 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);
    // ==============================================
    
    0 讨论(0)
  • 2021-01-04 08:44

    Try to use 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 be longer than 998 characters. (see also https://stackoverflow.com/a/12840338/2136148)

    0 讨论(0)
  • 2021-01-04 08:46

    As stated here: Exclamation Point in HTML Email

    The issue is that your string is too long. Feed an HTML string longer than 78 characters to the mail function, and you will end up with a ! (bang) in your string.

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

    0 讨论(0)
提交回复
热议问题