来自联系表格的邮件没有日期

时间:2014-06-19 11:17:55

标签: php email date contact-form

经过多次试验和错误后,我终于得到了一个php联系表单,按照我想要的方式工作,将正确的信息发送到我的托管邮件地址。除了Date之外,一切都很好看,它根本没有出现(在我的收件箱中)。我已经联系了托管服务,但他们没有回复。我也去研究php手册,但几乎没有关于Date atribute / header的信息。有谁知道如何解决这个问题?

这是我的php:

<?php 
if(isset($_POST['email'])) {

foreach( $_POST as $value ){
if( stripos($value,'Content-Type:') !== FALSE ){
echo "There seems to be something wrong with your information. Please try again.";
exit;
}
}

if ($_POST["morada"] != "") {
    echo "Oops! Error. Please try again.";
    exit;
}

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "main@myemailaccount.com";
$email_subject = "Contact Form";


// validation expected data exists
if(!isset($_POST['nome']) ||
    !isset($_POST['email']) ||
    !isset($_POST['phone']) ||
    !isset($_POST['website']) ||
    !isset($_POST['motivo']) ||
    !isset($_POST['mensagem'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');      
}

$nome = $_POST['nome']; // required
$email = $_POST['email']; // required
$phone = $_POST['phone']; // required
$website = $_POST['website']; // not required
$motivo = $_POST['motivo']; // required
$mensagem = $_POST['mensagem']; // required
$error_message = "";

$email_message = "Form details below.<br><br>";

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .= "Nome: ".clean_string($nome)."<br>";
$email_message .= "Email: ".clean_string($email)."<br>";
$email_message .= "Telefone: ".clean_string($phone)."<br>";
$email_message .= "Website: ".clean_string($website)."<br>";
$email_message .= "Motivo: ".clean_string($motivo)."<br>";
$email_message .= "Mensagem: ".clean_string($mensagem)."<br><br><br><br>";

$email_message = wordwrap($email_message, 70);

// create email headers
$headers =  "";
$headers .= 'From: '.$nome.'<'.$email.'>'.$eol;
$headers .= 'Reply-To: '.$nome.'<'.$email.'>'.$eol;
$headers .= 'Return-Path: '.$nome.'<'.$email.'>'.$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-type: text/html; charset=utf-8".$eol;


@mail($email_to, $email_subject, $email_message, $headers);
    {
      echo header("Location: thanks.html");
    }}
?>

1 个答案:

答案 0 :(得分:1)

没有配置邮件引擎的服务器,所以我无法对其进行测试。但我认为你只需要添加&#39;日期&#39;头:

$headers .= 'Date: '.date('r').$eol;

您可能需要配置默认时区:

date_default_timezone_set("UTC");

http://il1.php.net/manual/en/function.date-default-timezone-set.php