2010-04-28 20 views
0

我測試一個PHP郵件的形式,很準系統一個,found here正確編碼在PHP郵件形式字符( 「我」 變成是 「I 'm」 是)

<?php 

    if(isset($_POST['submit'])) 

    { 

     //The form has been submitted, prep a nice thank you message 

     $output = '<h3>Thanks for your message</h3>'; 


     //Deal with the email 

     $to = '[email protected]'; 

     $subject = 'you have a mail'; 



     $contactname = strip_tags($_POST['contactname']); 

     $adress = strip_tags($_POST['adress']); 

     $contactemail = strip_tags($_POST['contactemail']); 

     $textmessage = strip_tags($_POST['textmessage']); 



     $boundary =md5(date('r', time())); 



     $headers = "From: My Site\r\nReply-To: [email protected]"; 





     $message = "Name: ".$contactname."\n"; 

     $message .= "Adress: ".$adress."\n"; 

     $message .= "E-mail: ".$contactemail."\n"; 

     $message .= "Message: ".$textmessage."\n"; 



     mail($to, $subject, $message, $headers); 

    } 

?> 

問題在於,每次我在郵件中寫入單引號或雙引號時,我都會收到不需要的斜槓「\」,因此「我」在我的郵箱中顯示爲「我\」。

我知道它與PHP區分代碼引號的方式只與演講引號有關,但我不知道要在表單中添加哪些內容才能使其正確運行。

任何幫助表示讚賞,

回答

3

你可以嘗試stripslashing您的留言,是這樣的:

$message = stripslashes($message); 
+0

感謝傢伙它的工作 – Peanuts 2010-04-28 04:05:29

5

做最簡單的事情是把魔術在php.ini中引用過,

magic_quotes_gpc的= FALSE

如果你不能做到這一點,你需要除去斜線這樣,

if (get_magic_quotes_gpc()) { 
    foreach($_POST as $k => $v) { 
     $_POST[$k] = stripslashes($v); 
    } 
}