Ok, here's some code..
I both store my message in mysql, and I send it with the mail()-function. Before I store it/send it, I do this:
//Remove dangerous ' (for insertion to database - SQL insert-query)
$message= str_replace("'","´",stripslashes($message));
//Remove linebreaks
$message= str_replace("\r\n","",$message);
$message= str_replace("\n\r","",$message);
$message= str_replace("\n","",$message);
$message= str_replace("\r","",$message);
/
The reason for doing the four lines above, is that I use a richtext editor (http://sourceforge.net/projects/richtext) which inserts (unwanted) linebreaks when making html-text. The editor inserts <br> and <p> when linebreak is wanted, but also inserts \n\r etc. to make the html-code more readable. It inserts \n\r after e.g. a <tr> or <table>-tag. To avoid the \n\r to be translated to <br> when using nl2br(), I just remove them, as shown above.
/
//Define some headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".user_getrealname()." <".user_getemail().">\r\n";
//I am ready to send the message:
$res = mail($to_email, strip_tags($subject), nl2br($message), $headers);
If I run a striptags()-on the $message, everything seems be allright (not fully tested, though), but when I send MIME mail, exclamation marks are inserted into the $message. Pretty strange, if you ask me...
Thank you for your comments!
Regards,
Torbjørn