newline not working in PHP mail

前端 未结 3 1138
无人共我
无人共我 2020-12-05 12:40

I\'m using the following to send an email:



        
相关标签:
3条回答
  • 2020-12-05 13:12
    <?php ....
    $message = "Hi ".$fname.", \r\n Your entries for the week of "
       .$weekof." have been reviewed. \r\n Please login and View Weekly reports to see the report and comments. \r\n Thanks, \r\n".$myname;
    
    mail($to, $subject, $message, $from);
    ?>
    
    0 讨论(0)
  • 2020-12-05 13:34

    Not an answer to the question, but may be of help to someone.

    Send a HTML message, and instead of \n, use <BR>.

    And use <PRE></PRE> or CSS for preformatted text, thus translating \n to actual new lines.

    $headerFields = array(
        "From: who@are.you",
        "MIME-Version: 1.0",
        "Content-Type: text/html;charset=utf-8"
        );
    mail($to, $subj, $msg, implode("\r\n", $headerFields));
    
    0 讨论(0)
  • 2020-12-05 13:36

    Try to change your ' to " - php interprets a string inside single quotes as literals, whereas with quotes (") it will expand the \r\n to what you want.

    More information: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single

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