Send email with line breaks using mail() in php

后端 未结 5 2043
猫巷女王i
猫巷女王i 2020-12-06 10:42

I am trying to send email using mail() in php. I need the message to be formatted or at least allow line breaks.

$mail = mail(WEBMASTER_EMAIL, $subject, $me         


        
相关标签:
5条回答
  • 2020-12-06 11:30

    because it's \r\n

    0 讨论(0)
  • 2020-12-06 11:40

    It's \r\n, as in backslash not forward slash.

    Also you can try it like this:

    $message = "
    
    Hi!
    
    This is one line.
    
    And this is another.
    
    
    
    Bye!
    ";
    
    0 讨论(0)
  • 2020-12-06 11:40

    you should set the content type of the mail (read: tell php you're sending a html e-mail) http://php.net/manual/en/function.mail.php

    it's all explained in Example #5 Sending HTML email.

    0 讨论(0)
  • 2020-12-06 11:40

    To format message body you should use \n, as follow:

    $message = "Hi!
    \nThis is one line.
    \nAnd this is another.
    \nBye!";
    

    This is formatting your message body.

    0 讨论(0)
  • 2020-12-06 11:44

    It's the solution I got after waisting too many time and It's working perfectly.

    echo "line 1".PHP_EOL."line 2".PHP_EOL;
    

    If you're planning to show the result in a browser then you have to use "<br>".

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