Question

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.

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.

I found one forum post about it suggesting that there is a character limit of about 990 characters that leads to this problem.

Does anyone know the cause? Does anyone know a fairly easy fix for this?

Relevant PHP 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);
Was it helpful?

Solution

There is a limit to the number of characters in a line of an email:

There are two limits that this standard places on the number of characters in a line. Each line of characters MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF. (RFC 2882)

You can use the PHP function wordwrap to achieve this:

$contents = wordwrap($contents);

In any case, this will improve the readability of the emails sent with your script, as well as making them standards-compliant.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top