Hi!

I am having some problems using the mail()-function of PHP.

It seems like randomly in the mail, exclamation marks (!) are inserted into the text.

Since I am sending MIME mail, the exclamation marks destroy the mail. IMG-tags, links etc. are no longer working if there has been a ! inserted inside it.

I am pretty sure that my code is ok, but of course, I can't guarantee it. Has anybody else experienced this problem?

Is there something basic that I might be doing wrong, or is this an error in PHP?

If I have a text string full of HTML-code, is there then some functions that I have to run the string through to make mail()-send it properly?

-Thanks :-)

Torbjørn

    nope have never come across a problem like this, post some code so that we can to a look.

      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

        Write a Reply...