0

Im trying to get more variables just in one variable with linebreaks and after that variable is set I want to mail that variable to my mailadres but that is working fine! My code for now is:

$factuur = $bedrijfslogo . '<br>' . $bedrijfsadres . '<br>' . $datum . '<br>'
. $factuurnummer;

But this isnt working because in my mail i get <br> and not a linebreak. How do i fix that?

I tried to use echo <br> and echo <br /> but it isnt working. It gives me parse errors or other errors.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Chiel
  • 83
  • 10

2 Answers2

3

Try using "\r\n\r\n" instead '<br>':

$factuur = $bedrijfslogo . "\r\n\r\n" . $bedrijfsadres . "\r\n\r\n" . $datum . "\r\n\r\n" . $factuurnummer;

If you send the mail without explicitely stating that it contains HTML it will be interpreted as text. For text, a carriage return character \r followed by a newline character \n has to be used.

Since a single "\r\n" (the double quotes " instead of ' is also important here) has to be inserted to break lines in the email's "source code" so that the "source code" lines are not longer than 70 characters, a single "\r\n" is not enough to display a line break to the user. Therefore, two "\r\n" have to be used.

also see https://stackoverflow.com/a/9619131/641481

Community
  • 1
  • 1
zabbarob
  • 1,191
  • 4
  • 16
  • 25
0

you can use nl2br php function

<?php
   echo nl2br("One line.\nAnother line.");
?>

you can aslo give line break by

<?php
echo "<br />\n";
?>

If you want a new line character to be inserted into a plain text stream then you could use the OS independent global PHP_EOL

Ferrakkem Bhuiyan
  • 2,741
  • 2
  • 22
  • 38
  • 1
    nl2br() takes a newline (e.g., "\r\n") and replaces it with an HTML
    , which is the opposite of what the OP wanted.
    – Phil Perry Apr 01 '14 at 17:05