Single quote problem...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lamia
Forum Newbie
Posts: 11
Joined: Sun Jun 19, 2005 2:21 am

Single quote problem...

Post 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]
Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

As far as I can see, you never run escape_data() on any variables.
lamia
Forum Newbie
Posts: 11
Joined: Sun Jun 19, 2005 2:21 am

Post 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!
Post Reply