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?

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.