这是我的代码:
<?php
header('Content-type: text/plain; charset=utf-8');
$to = 'example@gmail.com';
$subject = 'Message to the site';
$realname = htmlspecialchars($_POST['realname']);
$email = htmlspecialchars($_POST['email']);
$msg = htmlspecialchars($_POST['msg']);
$headers = 'From: example@gmail.com' . "'r'n" .
'Reply-To: example@gmail.com' . "'r'n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $msg, $headers) or die("Error!");
echo 'Thank you! :)';
?>
有人能解释一下为什么这个代码不能正常工作吗?我的意思是,当我点击提交按钮时,它会发送电子邮件,但我不能在其中包含$msg
,我不知道为什么。
尝试添加:
$headers .= 'Content-type: text/html';
在$headers下添加这一行,然后选中,我希望这对你有用。。。