0

我在使用此联系页面时遇到问题,电子邮件发送正常但为空白!我似乎找不到解决方案。我认为需要添加 $_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\">";
}
?>
4

3 回答 3

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();
于 2013-06-14T11:43:04.583 回答
0

你还没有使用任何header.

这里寻求帮助。并使用它。我想它会对你有所帮助。

像下面这样的帖子标题

$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);

请试试这个。并告诉我这是否有效。

于 2013-06-14T11:55:15.923 回答
0

尝试改变:

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

到:

$success = mail($EmailTo, $Subject, $Body, "From: <".$EmailFrom.">");
于 2013-06-14T12:06:16.097 回答