Support » Plugins » wp_mail and line breaks

  • I’m writing a small plugin that adds some data to some email notifications, and can’t figure out how to force newlines in the body that gets sent via wp_mail.

    I tried “\n”, ” \n “, ” \r\n “, and can’t get it to work. Any ideas?


Viewing 4 replies - 1 through 4 (of 4 total)
  • Are you certain you enclosed the line break characters in double quotes and not single quotes? Double quotes are important in this context because they tell PHP to interpret escaped characters in the enclosed string — if you use single quotes, the escaped characters just get passed through as text. So "\n" comes through as a line break, but '\n' doesn’t.

    I’m having this same issue. Using the regular PHP mail function works fine, but when I try to use wp_mail, it doesn’t add line breaks.

    I should add that I’ve tried “\n”, ” \n “, ” \r\n “, and I also tried using HEREDOC syntax.

    @jalefkowit – this worked (and explained why) perfectly for me. Currently finishing a client WP project, and having to format auto-emails for the first time. Feels like I spent way too much time trying to resolve this one (having come from the MS ASP.NET world just over a year ago and have never had a problem with \n), and your response is excellent … thanks so much!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_mail and line breaks’ is closed to new replies.