title: PHP String concatenation and New Lines
body: <p>I need a bit of help understanding some PHP behavior that is not making sense to me, thanks in advance for the help.</p>
  
  <p>First off, is there a difference between the use of <code>\r\n</code> and <code>\n\r</code>? I would think logically no, but I am thinking there has to be a practical reason why they are listed in the PHP document separately. I am currently using <code>\r\n</code> but sometimes I get a line break, sometimes I don't, its befuddling.</p>
  
  <p>Second, I am aware that if I was echoing the information inside the browser, I would use the <code>nl2br()</code> function but I am not showing the information to the browser, it is being gathered and concatenated into a string that is then being sent via <code>mail()</code> and that's where the visual discrepancy is showing up.</p>
  
  <p>Here is the script, pretty straight forward, nothing mind boggling here:</p>
  
  <pre><code>&lt;?php
      $browser = $_SERVER['HTTP_USER_AGENT'];
      $page = $_SERVER['PHP_SELF'];
      $ip = $_SERVER['REMOTE_ADDR'];
      $host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
      $from_page = $_SERVER['HTTP_REFERER'];
      $time = date('l, F jS Y - g:i:s A', $_SERVER['REQUEST_TIME']);
      $uri = $_SERVER['SCRIPT_URI'];
  
      $to = "***";
      $subject = "Visitor Log";
      $message = "IP Address : " . $ip . " ( HOST: " . $host . " )\r\n" . "Browser : " . $browser . "\r\n" . "From : " . $from_page . "\r\n" . "Page : " . $page . "\r\n" . "Time : " . $time . "\r\n" . "Script : " . $uri;
      $headers = "From: ***" . "\r\n" . "Reply-To: ***" . "\r\n" . "X-Mailer: PHP/" . phpversion();
      mail($to,$subject,$message,$headers);
  ?&gt;
  </code></pre>
  
  <p>But as you can see, I have linebreaks that are padded into the <code>$message</code> for obvious readability of the email that I receive. But sometimes the emails arrive and everything is on a separate line as should be and sometimes it doesn't. So I thought maybe the method of adding a line break is not the best and that I am doing something wrong.</p>
  
  <p>So the question is, what should I use to get the proper line breaks, if what I am using is not correct, and if it is correct, why isn't it always working? Your assistance to add some clarity to this would be greatly appreciated.</p>
  
  <p>If it matters or makes a difference, I am using PHP 5 (5.5.28) Linux server with Apache.</p>
  
  <hr>
  
  <h2>UPDATED ANSWER</h2>
  
  <p>Thank you for everyone's help but ultimately I ended up fixing it as follows and even added the content type for good measure (TY @TOM).</p>
  
  <pre><code>&lt;?php
      $browser = $_SERVER['HTTP_USER_AGENT'];
      $page = $_SERVER['PHP_SELF'];
      $ip = $_SERVER['REMOTE_ADDR'];
      $host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
      $from_page = $_SERVER['HTTP_REFERER'];
      $time = date('l, F jS Y - g:i:s A', $_SERVER['REQUEST_TIME']);
      $uri = $_SERVER['SCRIPT_URI'];
  
      $to = "***";
      $subject = "Visitor Log";
      $message = "IP Address : " . $ip . " ( HOST: " . $host . " )" . "\r\n";
      $message .= "Browser : " . $browser . "\r\n";
      $message .= "From : " . $from_page . "\r\n";
      $message .= "Page : " . $page . "\r\n";
      $message .= "Time : " . $time . "\r\n";
      $message .= "Script : " . $uri;
      $headers = "From: ***" . "\r\n";
      $headers .= "Reply-To: ***" . "\r\n";
      $headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
      $headers .= "Content-Type: text/html; charset=\"utf-8\"" . "\r\n";
  
      mail($to,$subject,nl2br($message),nl2br($headers));
  ?&gt;
  </code></pre>
  
  <p><strong>NOTE</strong>: The new formatting is not part of the solution, its just for myself. The solution is giving up on plain and going with html and using <code>nl2br</code> function to force the breaks, not elegant, not what I wanted entirely but works.</p>