In case you haven’t noticed, with most PHP form processors, if a user fills out a textarea within your form using paragraphs or line breaks the formatting of the paragraphs and line breaks are stripped away from your delivered email contents. We are going to use the PHP nl2br() function to fix this which will display your form e-mail contents exactly as the user provided them.

In this case, we want to use the PHP nl2br() function and insert our form textarea field contents within that function so we can achieve paragraphs and/or line breaks when the form is submitted to us as an e-mail.

The first order of business is our standard HTML textarea form field, for this tutorial we will name it “details” and this is how our form HTML will look: Now, within your PHP script to process your form to be delivered via e-mail, we will need to grab the textarea contents which will look like: Next, in order for the contents of $details to be delivered with paragraphs and line breaks included based on how the user filled out the textarea we will need to add our nl2br() function. With the PHP from the above code included, this will look like: There you have it, the above code places your textarea field contents within the PHP nl2br() function which will now save the line breaks that your user has entered into the specific textarea.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners