drcmg28484 2013-12-11 22:20
浏览 30

添加标题到我的PHP代码?

I have been advised to add headers to my php code as my emails are coming through to my inbox with blank/empty form fields even though the user has iputted them on the webpage before clicking submit. I will be greatly appreciative if somebody can tell me if i have done this right?

<?php


$EmailFrom = "Quote@mydomian.co.uk";
$EmailTo = "me@mydomian.co.uk";
$Subject = "Online contact form";
$fullName = Trim(stripslashes($_POST['fullName'])); 
$contactNo = Trim(stripslashes($_POST['contactNo'])); 
$message = Trim(stripslashes($_POST['message'])); 

// prepare email body text
$Body = "";
$Body .= "fullName: ";
$Body .= $fullName;
$Body .= "
";
$Body .= "contactNo: ";
$Body .= $contactNo;
$Body .= "
";
$Body .= "message: ";
$Body .= $message;
$Body .= "
";

$headers  = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
$success = mail($EmailTo, $Subject, $Body, $headers, $EmailFrom");


// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=Thankyou.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
  • 写回答

2条回答 默认 最新

  • dtrz99313 2013-12-11 22:24
    关注

    You should use the php header() function:

    header('Content-type: application/html');

    as this will be send first to the browser...

    评论

报告相同问题?

悬赏问题

  • ¥15 求指导ADS低噪放设计
  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存