联系php邮件页面,只发送空白电子邮件。

时间:2013-06-14 11:39:20

标签: php

我在这个联系页面遇到问题,电子邮件发送正常但是空白!我似乎无法找到解决方案。我认为需要添加$ _POST,但是,网络托管公司表示没有必要在这个PHP脚本中谢谢你的时间和帮助。下面的代码片段。

<?php

$EmailFrom = "sales@ibdengland.co.uk";
$EmailTo = "kent.collins.uk@gmail.com";
$Subject = "online form";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Message = Trim(stripslashes($_POST['Description of project']));
// validation
$validationOK=true;
if (!$validationOK) {
  echo "please check your details";
  header("Location: http://www.ibdengland.co.uk/thankyou.html");
  exit;
}

// prepare email body text

$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Description of project: ";
$Body .= $Message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"1;URL=thankyou.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"1;URL=thankyou.html\">";
}
?>

3 个答案:

答案 0 :(得分:1)

您忘了添加标题。

示例:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: '. $EmailFrom . "\r\n" .
'X-Mailer: PHP/' . phpversion();

答案 1 :(得分:0)

您没有使用任何header

here获取帮助。并使用它。我认为它会对你有帮助。

发布标题如下

$headers = 'From:'.$EmailFrom . "\r\n" .
'Reply-To: '.$EmailFrom . "\r\n" .
'X-Mailer: PHP/' . phpversion();

然后在下面替换

$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

使用以下代码

$success = mail($EmailTo, $Subject, $Body, $headers);

试试这个。并通知我这项工作与否。

答案 2 :(得分:0)

尝试更改:

$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

$success = mail($EmailTo, $Subject, $Body, "From: <".$EmailFrom.">");