0

I have a very simple form with a textarea.

I can get the textarea's value with PHP by:

<?php $val = $_POST['txt']; ?>

My question is, that, how could I preserve the newline separators when I'm processing the text?

I intend to send a Plain text email, NOT a HTML email, this is why I need PHP to send the email in the exact same format, which the user types in the textarea.

How is it possible?

Radical_Activity
  • 2,618
  • 10
  • 38
  • 70

3 Answers3

0

Have you tried nl2br? (http://www.php.net/nl2br)

echo nl2br($val);
Synchro
  • 35,538
  • 15
  • 81
  • 104
MTM
  • 919
  • 10
  • 22
  • He doesn't want a HTML email, ONLY plain text, http://uk3.php.net/nl2br converts `\n` etc to `
    `
    – Ian Jul 17 '14 at 14:05
0

Answer found:

If you are planning to send Plain text email messages, you should only use the raw Textarea data and paste it as the email's body.

Radical_Activity
  • 2,618
  • 10
  • 38
  • 70
0

You don't need to do anything... Because you already have the new lines when you get the data from your textarea... Just make sure to use double quotes " and not single ' for new lines \n.

echo '\n'; // this will output these two characters: \n
echo "\n"; // this will output a new line
Jo Smo
  • 6,923
  • 9
  • 47
  • 67