Title: Replace nl2br with wpautop
Last modified: August 22, 2016

---

# Replace nl2br with wpautop

 *  Resolved [Diego de Oliveira](https://wordpress.org/support/users/diegoliv/)
 * (@diegoliv)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/replace-nl2br-with-wpautop/)
 * Hi, Haet!
 * First, congrats for the plugin, I’ve just found it and loved it! I’ll start to
   using it for every project.
 * I’ve been having some issues using forms plugins and email templates for WordPress.
   I’m currently using Caldera Forms to create forms. I’ve tested many email template
   plugins but yours works the best. With only one small exception: **line breaks**.
   Let me explain:
 * When I create a form using Caldera Forms, for example, I have the possibility
   to format the email that will be sent using html (the TinyMCE editor). This way,
   the message comes formatted. Caldera Forms is using `nl2br` function to include
   line breaks.
 * Then, your plugin (and many more) gets all the email data (including the formatted
   message), wraps in the template, and sends it. I checked your code and I saw 
   that the plugin use `nl2br` too. This way, the function duplicates the line breaks,
   and the resulting email comes with lots of line breaks.
 * I digged both on the Caldera Forms and your plugin, to check what can be done
   to solve it. What I figured is that no matter if Caldera Forms uses `nl2br` or
   another WP native function, the `wpautop`, the line breaks still is wrong. So,
   I’d like to suggest a fix for this issue:
 * On the file `class-haet-mail.php`, at line **244**, replace:
 *     ```
       $message = nl2br($message);
       ```
   
 * with
 *     ```
       $message = wpautop($message);
       ```
   
 * This way, the `wpautop` function adds line breaks, wraps paragraphs and allow
   a better compatibility with Caldera Forms and probably other plugins.
 * I checked another email template plugin, **WP Email Template**, and it’s working
   good. I saw the plugin code and they are using `wpautop` to format the message
   string. So, I think that this fix could make your plugin works better with form
   builders.
 * [https://wordpress.org/plugins/wp-html-mail/](https://wordpress.org/plugins/wp-html-mail/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Hannes Etzelstorfer](https://wordpress.org/support/users/haet/)
 * (@haet)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/replace-nl2br-with-wpautop/#post-5782714)
 * Hi Diego,
    Thank you for this improvement. I tested your suggestion and released
   version 0.3 with some additional small improvements. It’s also possible to turn
   html mails on / off for caldera forms now on the “plugins” config page. best 
   regards, Hannes
 *  Thread Starter [Diego de Oliveira](https://wordpress.org/support/users/diegoliv/)
 * (@diegoliv)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/replace-nl2br-with-wpautop/#post-5782718)
 * Cool! Thanks for the quick update! I’m already using it!
 * And please, keep the good work, Hannes!
 * Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Replace nl2br with wpautop’ is closed to new replies.

 * ![](https://ps.w.org/wp-html-mail/assets/icon-256x256.png?rev=1730334)
 * [Email Template Designer - WP HTML Mail](https://wordpress.org/plugins/wp-html-mail/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-html-mail/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-html-mail/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-html-mail/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-html-mail/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-html-mail/reviews/)

## Tags

 * [email](https://wordpress.org/support/topic-tag/email/)
 * [html](https://wordpress.org/support/topic-tag/html/)
 * [wpautop](https://wordpress.org/support/topic-tag/wpautop/)
 * [wp_mail](https://wordpress.org/support/topic-tag/wp_mail/)

 * 2 replies
 * 2 participants
 * Last reply from: [Diego de Oliveira](https://wordpress.org/support/users/diegoliv/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/replace-nl2br-with-wpautop/#post-5782718)
 * Status: resolved