title: PHP - Form mail inserting ! and line break into long strings
body: <p>I have a form on my company's site which takes a name, telephone number, and comments (and a couple other things). The comments box lets you type up to 5000 characters - a large limit to allow for very verbose customers. A valid form has its contents sent using php form mail as a plain-text e-mail to our sales dept.</p>
  
  <p>For some reason, if the Comments are longer than about 1000 characters, they will have and exclamation point, a line break, and sometimes an indent inserted in. Note this applies to the e-mail only; if the form has an error in it, the data gets inserted into the form and errors are marked, and the comments do not have the exclamation marks + line breaks yet.</p>
  
  <p>I found one forum post about it suggesting that there is a character limit of about 990 characters that leads to this problem.</p>
  
  <p>Does anyone know the cause? Does anyone know a fairly easy fix for this?</p>
  
  <p>Relevant PHP code:</p>
  
  <pre><code>$to = $email;
  
  $subject = "Website Order Received: $offer";
  
  $contents = "
  Order Form Received -\n
  Name: $name\n
  Company: $company\n
  Email: $email\n
  Phone: $phone $phoneExt\n
  Order Contents:\n" .
  ($offer == 'web-demo' ? "- I want a live software demonstration.\n" : "") .
  ($offer == 'pricing' ? "- I'd like pricing information.\n" : "") .
  ($offer == 'holiday-pricing' ? "- I'd like to sign up before December 31st for the special holiday offer!\n" : "") .
  ($offer == 'bid-help' ? "- Please give me marketing materials and other assistance for winning bids.\n" : "") .
  ($offer == 'demo-cd' ? "- Send me the full-version demonstration CD.\n" : "");
  if (!empty ($comments)) {
      $comments = str_replace("
  ", "\n", $comments); // Preserves line breaks in the comments.
      $contents = $contents."\nComments: $comments\n\n";
  }
  $contents = str_replace("\n", "\r\n", $contents);
  
  mail($to, $subject, $contents);
  </code></pre>