正确地编码PHP邮件格式中的字符(“我已经”变成“我不”) [英] Correctly encode characters in a PHP mail form ("I'm" turns to be "I\'m")
本文介绍了正确地编码PHP邮件格式中的字符(“我已经”变成“我不”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在测试一个PHP邮件表单,一个非常准确的一个,发现这里:
I'm testing a PHP mail form, a very barebones one, found here:
<?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 = 'mymail@mail.com';
$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: webmaster@mysite.com";
$message = "Name: ".$contactname."\n";
$message .= "Adress: ".$adress."\n";
$message .= "E-mail: ".$contactemail."\n";
$message .= "Message: ".$textmessage."\n";
mail($to, $subject, $message, $headers);
}
?>
问题是我每次写单或一个时候都收到不必要的斜杠\在我的邮箱中双引号,所以我在我的邮箱中显示为我。
The problem is I'm receiving an unwanted slash "\" everytime I write a single or a double quote in my message, so "I'm" appear as "I\'m" in my mailbox.
我知道它与PHP的方式有关将代码引号与只有讲义引用区分开来,但我不知道在我的表单中添加什么来使其正常运行。
I know it have to do with the way PHP distinguishes code quotes from only lecture quotes, but I wouldn't know what to add in my form to get it properly running.
任何帮助都不胜感激,
推荐答案
你可以尝试去剥离你的消息,如:
you can try stripslashing your message , something like :
$message = stripslashes($message);
这篇关于正确地编码PHP邮件格式中的字符(“我已经”变成“我不”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文