Jump to content

[SOLVED] Mail special character escape problem


thefollower

Recommended Posts

I have tried so many functions yet every time i send a message which has the ' symbol it becomes \'

 

 

And its very frustrating.. i have this:

 

$POST['letter'] = "Can't do this";

 

<?php
		$Message = mysql_real_escape_string(stripslashes(nl2br(strip_tags($_POST['letter']))));

				// Send the email.
		$subject = "Login Infomation Desk";
		$headers = 'From: Server';
		$message = "A username ".$Username." has requested help !\r \r ~------------------~ \r \r";
		$message = $message. "Their message is: \r \r ".$Message." \r \r ~------------------~ \r \r";
		$message = $message. " \r Username is: ".$Username." \r";
		$message = $message. " \r Email is: ".$Email;
		mail('myemail here', $subject, $message, $headers);
?>

 

 

My email shows:

Can/'t do this!

 

What function do i need to make it come out correctly?

stripslashes function is already in there =/

 

So it is...sorry. Personally I would do it like this, but I don't know if this will help you.

 


<?php
         $letter = mysql_real_escape_string(stripslashes(nl2br(strip_tags($_POST['letter']))));

               // Send the email.
         $subject = "Login Infomation Desk";
         $headers = 'From: Server';
         $message = "A username ".$Username." has requested help !\r \r ~------------------~ \r \r";
         $message = $message. "Their message is: \r \r ".$letter." \r \r ~------------------~ \r \r";
         $message = $message. " \r Username is: ".$Username." \r";
         $message = $message. " \r Email is: ".$Email;
         mail('myemail here', $subject, $message, $headers);
?>

Here is what your doing...

 

$message = "My name\'s Jon";

stripslashes($message);
//Produces "My name's Jon";

mysql_real_ecape_string($message);
//Produces "My name\'s Jon";

 

Mysql_real_escape_string(); is the problem.

 

You are escaping characters again, after removing the slashes.

 

Here is what your doing...

 

$message = "My name\'s Jon";

stripslashes($message);
//Produces "My name's Jon";

mysql_real_ecape_string($message);
//Produces "My name\'s Jon";

 

Mysql_real_escape_string(); is the problem.

 

You are escaping characters again, after removing the slashes.

 

 

But logically the mysql_real_escape_string is before the stripslashes.. not after.. i already thought of that :P

$Message = mysql_real_escape_string(stripslashes(nl2br(strip_tags($_POST['letter']))));

 

That is your code. First you strip_tags, then nl2br, then stripslahes and then after you are escaping it again. What is the point of that?

 

You are first removing slashes and then adding them again. You read from the inside-to-out, like math functions.

functions execute from the inside out, so mysql_real_escape_string happens last. but also, you aren't inserting it into a DB, so there is no need to escape it. remove mysql_real_escape_string and you should be good to go

 

p.s. - the content type of your email is plain text anyways, so why do you do nl2br?

functions execute from the inside out, so mysql_real_escape_string happens last. but also, you aren't inserting it into a DB, so there is no need to escape it. remove mysql_real_escape_string and you should be good to go

 

p.s. - the content type of your email is plain text anyways, so why do you do nl2br?

 

I see i didn't know that functions worked backwards... also I have nl2br because I was about to ask how to make emails with nice formats and stuff... can't find a tutorial on how to do it anywhere with google.

 

 

I got  mysql_real_escape_string there just from sheer habit...lol!

 

 

Thanks for the tip off.

<?php
         $letter = nl2br(strip_tags(stripslashes($_POST['letter'])));

          // Send the email.
         $subject = "Login Infomation Desk";
         $headers  = "From: Server\r\n";
         $headers .= "Content-type: text/html;\r\n";
         $message  = "A username $Username has requested help !<br /><hr>";
         $message .= "Their message is: <br /> $letter <br />";
         $message .= "Username is: $Username <br />";
         $message .= "Email is: $Email ";
         mail('myemail here', $subject, $message, $headers);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.