Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

html appearing in email being sent from form

Status
Not open for further replies.

karren

Programmer
Feb 26, 2002
42
CA
hi everyone,

i have an issue with emails being sent from a form, using the php mail() function.

the code i'm using automatically inserts link breaks and converts urls to links in the email body (which is written in a textarea) that is being sent out.

however, some people who receive the email receive them in plain text only. therefore, they see all the html in the formatted email, so it just appears very messy to them!

but if i remove the html, then the email just appears as one whole sentence (doesn't break into paragraphs) so the hard returns are not apprearing as hard returns when it is sent to the user.

anyone have a solution where i could get the text of the email to break into paragraphs without having html appear for the user who receives the email in plain text?

thanks all!!
 
ok, i guess the essence of my question is:

how do you send plain text emails without html formatting, while preserving the line breaks, so the email text doesn't appear as one huge paragraph?

thanks!

karren
 
When you use the mail() function in PHP, by default, it will be sent as text. If you are sending an html email then there have to be added headers to the function call.
Such as:
Code:
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

mail($To, $Subject, $MEssage, $headers);

By taking out these headers the mail will be sent as plain text, and should preserve the line breaks.

For security reasons you should always use strip_tags on user supplied text.

Hope this helps.
Itshim
 
thanks all, for your responses. i will try out this mailer class!
 
If you wish to display the text as entered in a textbox, without html.. hmm..

I was gonna say nl2br(), but that's the wrong way.

use strip_tags($text, "<br><p>");

Then afterwards, replace all occurrances of "<br>" with "\n" and replace "<p>" with "\r\n"
you will still have </p>, which has to be removed..

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top