• C

mailing in php?

This is here since there is no php section.

I am using the mail function.  In the "message" section, I entered text, being very careful that it was formatted correctly.  However, once mailed, I end up with line breaks in the text in strange places, apparently random.  Sometimes there will be one word and then a line break in a sentance, sometimes 6 or 7 words and then a break.

Any idea what would might be causing this?


Who is Participating?
EatEmAndSmileConnect With a Mentor Commented:
This is caused because your breaks will be always respected, while another breaks will be added by the mail client according to it's line width tolerance.

 What you must do is to add a forced break '\n' only in the end of paragraphs. This will separate paragraphs and let the other lines to be handled by the mail client dinamically.

 An example would be:

$message="This is a sample message to show how to handle line breaks dinamically, without causing undesired line breaks.\nThis example was posted to the Experts Exchange website in answer to ChrisAndrews question.\nWe hope he can solve his problem with this example PHP3 code.\nWe also hope that the Experts Exchange staff make a PHP3 section available soon.\n\nSender IP Address: $REMOTE_ADDR\n\nRegards,\n\nEatEm And Smile.";

mail("webmaster@example.org", "Sample Message", $message);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.