为电子邮件在线PHP表单添加时间框架

为电子邮件在线PHP表单添加时间框架,php,forms,email,Php,Forms,Email,我在下面拼凑了一些PHP代码,这些代码通过Ajax表单提交创建了一封漂亮的HTML电子邮件,并附有一个表格。但是,我想这样做,如果输入的时间范围不到48小时,就会弹出一条错误消息。我想知道改变html和php的最简单的方法是什么,或者是否可行 HTML代码 <input name="Event Date" type="text" required id="Event Date" style="border-radius:5px; height:25px; font-family:'Quic

我在下面拼凑了一些PHP代码,这些代码通过Ajax表单提交创建了一封漂亮的HTML电子邮件,并附有一个表格。但是,我想这样做,如果输入的时间范围不到48小时,就会弹出一条错误消息。我想知道改变html和php的最简单的方法是什么,或者是否可行

HTML代码

<input name="Event Date" type="text" required id="Event Date" style="border-radius:5px; height:25px; font-family:'Quicksand', sans-serif; color:#666" title="Event Date" value="MM/DD/YYYY">

PHP代码

    <?php

 require_once('recaptchalib.php');
 $privatekey = "###########################";
 $resp = recaptcha_check_answer ($privatekey,
                                 $_SERVER["REMOTE_ADDR"],
                                 $_POST["recaptcha_challenge_field"],
                                 $_POST["recaptcha_response_field"]);
unset($_POST["recaptcha_challenge_field"]);
unset($_POST["recaptcha_response_field"]);
 if (!$resp->is_valid) {
   // What happens when the CAPTCHA was entered incorrectly
   die ("The human verification code above WAS NOT entered correctly, please reset the human verification code and try again :-) " .
        "(Error: " . $resp->error . ")");
 } else {
     // Code Below For Handling Form (Send Email)
   function validEmail($email)
{
   $isValid = true;
   $atIndex = strrpos($email, "@");
   if (is_bool($atIndex) && !$atIndex)
   {
      $isValid = false;
   }
   else
   {
      $domain = substr($email, $atIndex+1);
      $local = substr($email, 0, $atIndex);
      $localLen = strlen($local);
      $domainLen = strlen($domain);
      if ($localLen < 1 || $localLen > 64)
      {
         // local part length exceeded
         $isValid = false;
      }
      else if ($domainLen < 1 || $domainLen > 255)
      {
         // domain part length exceeded
         $isValid = false;
      }
      else if ($local[0] == '.' || $local[$localLen-1] == '.')
      {
         // local part starts or ends with '.'
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $local))
      {
         // local part has two consecutive dots
         $isValid = false;
      }
      else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
      {
         // character not valid in domain part
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $domain))
      {
         // domain part has two consecutive dots
         $isValid = false;
      }
      else if
(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
                 str_replace("\\\\","",$local)))
      {
         // character not valid in local part unless
         // local part is quoted
         if (!preg_match('/^"(\\\\"|[^"])+"$/',
             str_replace("\\\\","",$local)))
         {
            $isValid = false;
         }
      }
      if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
      {
         // domain not found in DNS
         $isValid = false;
      }
   }
   return $isValid;
}

//Reject hyperlinks
$SpamErrorMessage = "No Websites URLs permitted";
 if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();}
 if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();}
 if (preg_match("/http/i", "$Special Message")) {echo "$SpamErrorMessage"; exit();}

 //48 Hour Time Limit
if ((strptime($_POST['Event Date'], "%m/%d/%Y") - time()) < (48 * 60 * 60)) {echo "Date is under 48 hours notice. Please call for service."; exit();}

//Where is it being sent?
$destination = "handle@domain.com";
$email_from = $_POST['Email'];

if (!validEmail($email_from))
    die("Invalid email address");

$message = "<html>
<body style=\"font-family:Arial; font-size:10pt;\">
Hi,<br>
You have recieved an online order:<br><br>
<table width='600' border='1' cellspacing='3'>";

//Gather posted variables:
foreach($_POST as $keys => $vars){
    if (empty($vars)) continue; #skip if vars is empty
    $message .= "<tr>
    <td bgcolor='#CCCCCC'><b>$keys:</b></td> <td><b><font color='red'>$vars</font></b></td>
    </tr>";
}
$message = str_replace("_"," ", $message);
$message .= "
</table>
</body>
</html>
";

#separating headers properly
$headers = "From: $email_from\r\n".
'Reply-To: '.$email_from."\r\n".
"Content-Type: text/html; charset=\"utf-8\"\r\n".
"Content-Transfer-Encoding: 7bit\r\n".
"MIME-Version: 1.0\n";

mail($destination,"Online Catering Form Results",$message,$headers);

echo "Thank you for your order!";
 }
 ?>

试试这样的方法,看看实际计算的事件时间和时间是什么

//48 Hour Time Limit
if ((strptime($_POST['Event Date'], "%m/%d/%Y") - time()) < (48 * 60 * 60)) {
    echo "Event Time: " . strptime($_POST['Event Date']) . "\n";
    echo "Time: " . time() . "\n";
    echo "Date is under 48 hours notice. Please call for service."; 
    exit();
}
//48小时时限
如果((strtime($_POST['Event Date'],%m/%d/%Y”)-time()<(48*60*60)){
回显“事件时间:”.strtime($\u POST['Event Date'])。“\n”;
回显“时间:”.Time().“\n”;
echo“日期在48小时内通知。请致电服务。”;
退出();
}

如果((strotime($\u POST['Event Date'])-time())<(48*60*60)){$isValid=false;}
足够了吗?嗨@MichaelWheeler!谢谢你的回复!我将其输入到代码中,但当以MM/DD/YYYY格式输入“事件日期”时,即使日期超过48小时,它仍会拒绝。我用过:
如果((strotime($\u POST['Event Date'])-time())<(48*60*60)){echo“日期未到48小时通知。请呼叫服务。“exit();}
而不是
strotime()
,试试
strptime($\u POST['Event Date']),%m/%d/%Y”)
谢谢@MichaelWheeler!但是,无论日期是什么,我仍然会收到
echo
消息。您最好的选择是执行类似
$eventtime=strtime($\u POST['Event date'],%m/%d/%Y”);var_dump($eventtime)$时间=时间();var_dump($时间)并自己比较这些值。检查
strtime()
是否按预期运行。我收到警告:
strtime()需要2个参数,1个参数在第90行的/domain.com/folder/send.php中给出事件时间:时间:1378745498日期在48小时内通知。请呼叫服务。
Oops,将第二行更改为
echo“事件时间:”。strtime($_POST['Event Date','%m/%d/%Y')。'\n'
更改了它,现在我得到了-
事件时间:\n时间:13786375日期在48小时内通知。请致电服务。
-我输入了'09/14/2013'(不带引号)作为事件日期将回音行更改为
echo“事件时间:”$_发布['事件日期']。“\n”
您的列名可能是EventDate而不是Event Date吗?您好@MichaelWheeler很抱歉,在科罗拉多洪水泛滥地区,回复太晚了。我选中了,列名为“事件日期”-我应该更改它吗?我还输入了新代码,这样它就可以读取
//48小时的时间限制,如果((strtime($\u POST['Event Date'],%m/%d/%Y”)-Time())<(48*60*60)){echo“事件时间:.”POST['Event Date']。\n“echo”Time:.Time()。\n“echo”日期未提前48小时通知。请呼叫服务。“exit();}
-现在我收到
事件时间:时间:1379115196日期未提前48小时通知。请呼叫服务。
输入日期为
09/16/2013