Killersites Community: PHP concatenation - Killersites Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PHP concatenation

#1 User is offline   Wickham 

  • PipPipPipPip
  • View gallery
  • Group: Advanced Member
  • Posts: 1,732
  • Joined: 20-December 08
  • LocationSalisbury UK

Posted 10 February 2012 - 02:27 PM

I found this code on php.net page
http://php.net/manua...nction.mail.php
<?php
// The message
$message = "Line 1\nLine 2\nLine 3";

// Send
mail('caffeinated@example.com', 'My Subject', $message);
?>

but when I test with an echo statement like this:-
<?php
$message = "Line 1\nLine 2\nLine 3";
echo "$message";
?>

in WampServer2 there aren't any line breaks. Why Not? Has php.net given a wrong example? How can I get \n or \r\n to create a line break from a variable?

I really want to concatenate several variables like:-
$name = "Name";
$email = "Email";
$message = "Message";
$messagebody = $name . "\r\n" . $email . "\r\n" . $message;
echo "$messagebody";

but there aren't any line breaks, it's all on one line. How do I make \r\n work?
0

#2 User is offline   benjaminmorgan 

  • PipPipPipPip
  • Group: Member
  • Posts: 237
  • Joined: 18-September 11

Posted 10 February 2012 - 05:10 PM

I wondered the same thing. It seems like it only works on emails. I can't get \r\n to work in browser but when i put it in email it seems to work. I'm not sure if that is what you are asking though.
Things should be made as simple as possible, but not any simpler. -Albert Einstein
0

#3 User is offline   Wickham 

  • PipPipPipPip
  • View gallery
  • Group: Advanced Member
  • Posts: 1,732
  • Joined: 20-December 08
  • LocationSalisbury UK

Posted 11 February 2012 - 06:21 AM

I am intending to use \r\n in a concatenated variable in an email function but I thought I would test it first. Why should it work in an email function but not in an echo statement?

Would it make any difference if it was a plain text email or if I included these headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

to make an html email?
Note that it's used in the headers code, but of course that doesn't print out.
0

#4 User is offline   benjaminmorgan 

  • PipPipPipPip
  • Group: Member
  • Posts: 237
  • Joined: 18-September 11

Posted 11 February 2012 - 08:13 AM

I don't know why it doesn't work in echo. I guess it is a mail function only kind of thing. I know it works in regular text only emails as well.
Things should be made as simple as possible, but not any simpler. -Albert Einstein
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users