craftcms / contact-form

Add a simple contact form to your Craft CMS site.
https://plugins.craftcms.com/contact-form
MIT License
294 stars 93 forks source link

Line breaks in message body result in 4 newlines instead of 2 #214

Closed dgsiegel closed 2 years ago

dgsiegel commented 2 years ago

Description

Due to $body = preg_replace('/\R/u', "\n\n", $body); in https://github.com/craftcms/contact-form/blob/v2/src/Mailer.php#L216 (introduced with ae8dd32c53c6af2882efe0e8ab411880e44aaeb6), all newlines in a textarea field will be replaced by two newlines. Adding the following into the textarea field:

foo
bar

text after empty line

gives this:

foo

bar

text after empty line

Steps to reproduce

  1. Add a contact form like described in the readme, e.g.
  {{ tag('textarea', {
        text: message.message ?? '',
        id: 'message',
        name: 'message',
    }) }}
  1. Look at the resulting text version of the email.

Additional info

brandonkelly commented 2 years ago

Thanks for reporting! Just released 2.5.1 with a fix for this.