Page 1 of 1

Single quote problem...

Posted: Sun Jun 19, 2005 11:25 pm
by lamia
Hi, I just thought it would be a better idead if I've posted this question on a different subject to make clearer understanding of the problem...

I have this mail script, and I have no problem whatsoever delivering it to other domains. The only problem I have is that whenever I put an apostrophe (') or single quote it turns like \'. For example I put "Tom's World" on the subject... The output would become "Tom\'s World". Any help would be appreciated, thanks!

For simplicity sake, I've ommited some of the variables I've used... Here's the code...

Code: Select all

function escape_data($data)
  {
  
   if (get_magic_quotes_gpc())  //magic quotes is on
   {
    $data = stripslashes($data);
   }  

   if (!is_numeric($data))
   {
    $data = mysql_real_escape_string($data);
   }
   
   return $data;
  
  }

   if(empty($_POSTї'subject']))
   {
     $s=false;
     $errmessage.='<p>Please enter a <b>subject</b>.</p>';
   }
   else
   { 
     $s=$_POSTї'subject']; //escape_data($_POSTї'subject']);
   }


   if(empty($_POSTї'message']))
   {
     $m=false;
     $errmessage.='<p>Please enter a <b>message</b>.</p>';
   }
   else
   { 
     $m=&quote;Message sent from http://mydomain.com\n\n&quote;;
     $m.= $_POSTї'message']; //escape_data($_POSTї'message'])
   }

   if ($n && $s && $e && $m)
   {

     ini_set(&quote;SMTP&quote;,&quote;localhost&quote;);
     ini_set(&quote;smtp_port&quote;,&quote;26&quote;);
     ini_set(&quote;sendmail_from&quote;,&quote;admin@localhost.com&quote;);

     $headers  = &quote;MIME-Version: 1.0\n&quote;;
     $headers .= &quote;Content-type: text/plain; charset=iso-8859-1\n&quote;;
     $headers .= &quote;X-Priority: 3\n&quote;;
     $headers .= &quote;X-MSMail-Priority: Normal\n&quote;;
     $headers .= &quote;X-Mailer: php\n&quote;;
     $headers .= &quote;From: \&quote;&quote;.$n.&quote;\&quote; <&quote;.$e.&quote;>\n&quote;;

     if (mail(&quote;somemail@domain.com&quote;,$s,$m,$headers))
     {
       $message.=&quote;<center><p>Success!</p></center>&quote;;
     }
     else
     {
       $message.=&quote;<center><p>The following errors occured!</p></center>&quote;;
       $errmessage.='<p>Unable to send message.</p>';
     }
   }
   else
   {
     $message.=&quote;<center><p>The following errors occured!</p></center>&quote;;
   }

 }
JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Jun 19, 2005 11:57 pm
by Revan
Use stripslashes();

Code: Select all

string stripslashes ( string str )

Code: Select all

$email = stripslashes($message);
For future code, please use

Code: Select all

tags.

Posted: Mon Jun 20, 2005 6:44 am
by John Cartwright
As far as I can see, you never run escape_data() on any variables.

Posted: Mon Jun 20, 2005 10:38 am
by lamia
If I use my escape_data() routine, another problem would arise... I wouldn't be able to make \n appear a newline like...

This
Is
A
Test

Would appear as...

This\r\nIs\r\n\A\r\nTest

so I refrained from using stripslashes()... By the way... I'm testing the output in my yahoo mail inbox... Thanks!