I have the following code:
$message = \"Good news! The item# $item_number on which you placed a bid of \\$ $bid_price is now available for purchase at your b
if you are outputting the code as html - change /n -->
and do echo $message;
When we insert any line break with a programming language the char code for this is "\n". php does output that but html can't display that due to htmls line break is
. so easy way to do this job is replacing all the "\n" with "
". so the code should be
str_replace("\n","<br/>",$str);
after adding this code you wont have to use pre tag for all the output oparation.
copyed this ans from this website :
EDIT: Maybe your class for sending emails has an option for HTML emails and then you can use <br />
1) Double-quotes
$output = "Good news! The item# $item_number on which you placed a bid of \$ $bid_price is now available for purchase at your bid price.\nThe seller, $bid_user is making this offer.\n\nItem Title : $title\n\nAll the best,\n $bid_user\n$email\n";
If you use double-quotes then \n will work (there will be no newline in browser but see the source code in your browser - the \n characters will be replaced for newlines)
2) Single quotes doesn't have the effect as the double-quotes above:
$output = 'Good news! The item# $item_number on which you placed a bid of \$ $bid_price is now available for purchase at your bid price.\nThe seller, $bid_user is making this offer.\n\nItem Title : $title\n\nAll the best,\n $bid_user\n$email\n';
all characters will be printed as is (even variables!)
3) Line breaks in HTML
$html_output = "Good news! The item# $item_number on which you placed a bid of <br />$ $bid_price is now available for purchase at your bid price.<br />The seller, $bid_user is making this offer.<br /><br />Item Title : $title<br /><br />All the best,<br /> $bid_user<br />$email<br />";
Are you building this string using single or double quotes? \r and \n only work with double quotes, as well as embedded variables. For example:
$foo = 'bar';
echo 'Hello \n $foo!';
will output:
Hello \n $foo!
But:
$foo = 'bar';
echo "Hello \n $foo!";
will output:
Hello
bar!
If you output to html or an html e-mail you will need to use <br>
or <br />
instead of \n
.
If it's just a text e-mail: Are you perhaps using '
instead of "
? Although then your values would not be inserted either...
you can use "Line1<br>Line2"