WordPress.org

Ready to get started?Download WordPress

Forums

wp_mail and line breaks (5 posts)

  1. Jason Lemahieu (MadtownLems)
    Member
    Posted 2 years ago #

    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?

    thanks!

  2. jalefkowit
    Member
    Posted 2 years ago #

    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.

  3. jcexygy
    Member
    Posted 2 years ago #

    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.

  4. jcexygy
    Member
    Posted 2 years ago #

    I should add that I've tried "\n", " \n ", " \r\n ", and I also tried using HEREDOC syntax.

  5. wrsowner
    Member
    Posted 1 year ago #

    @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!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags