PHP页面不重定向或发送数据

时间:2014-11-12 20:34:52

标签: php

以下是我发送给电子邮件的posts.php文档的代码 - 它目前正在做的是显示一个白页 - 状态是200所以它不是WPOD它也没有发送电子邮件而我无法点击为什么。

CODE:

   <?php
        if($_POST['formSubmit'] == "Place Order")
      {
          $errorMessage = "";
            if(empty($_POST['Name']))
        {
          $errorMessage .= "<li>You forgot your name</li>";
         }
            if(empty($_POST['Contact']))
        {
          $errorMessage .= "<li>You forgot your contact number</li>";
         }   

            if(empty($_POST['Email']))
        {
          $errorMessage .= "<li>You forgot your email</li>";
         }

            if(empty($_POST['Company']))
        {
          $errorMessage .= "<li>You forgot your company name</li>";
         }

            if(empty($_POST['Attending']))
        {
          $errorMessage .= "<li>You forgot the number of people attending</li>";
         }

            if(empty($_POST['Function']))
        {
          $errorMessage .= "<li>You forgot the function date</li>";
         }

            if(empty($_POST['FunctionDay']))
        {
          $errorMessage .= "<li>You forgot the function day</li>";
         }

            if(empty($_POST['Time']))
        {
          $errorMessage .= "<li>You forgot the time required</li>";
         }

            if(empty($_POST['Address']))
        {
          $errorMessage .= "<li>You forgot the delivery address</li>";
         }

            if(empty($_POST['Invoice']))
        {
      $errorMessage .= "<li>You forgot the invoice name</li>";
     }
        if(empty($_POST['Details']))
    {
      $errorMessage .= "<li>You forgot the order details</li>";
     }

    $varName = strip_tags($_POST['Name']);
    $varContact = strip_tags($_POST['Contact']);
    $varEmail = strip_tags($_POST['Email']);
    $varCompany = strip_tags($_POST['Company']);
    $varAttending = strip_tags($_POST['Attending']);
    $varFunction = strip_tags($_POST['Function']);
    $varFunctionDay = strip_tags($_POST['FunctionDay']);
    $varOrdered = strip_tags($_POST['Ordered']);
    $varTime = strip_tags($_POST['Time']);
    $varOnsite = strip_tags($_POST['Onsite']);
    $varOnsite2 = strip_tags($_POST['Onsite2']);
    $varInvoice = strip_tags($_POST['Invoice']);
    $varAddress = strip_tags($_POST['Address']);
    $varSpecial = strip_tags($_POST['Special']);
    $varDetails = strip_tags($_POST['Details']);
    $menu = strip_tags($_POST['menu']);

    $itemstr = '';
    $i=0;

    foreach($_POST['item'] as $item)
    {
        $itemstr .= "ITEM:". $item . ' Amount: '. $_POST['amount'][$i++]."<br/>";

    }

    /*$specialstr = '';
    $i=0;

    foreach($_POST['special'] as $special)
    {
        $specialstr .= "Special Needs:". $special ."<br/>";

    }

    ."<br/><strong>Special Needs:</strong><br/><br/>".  $specialstr
    */



    if(empty($errorMessage)) 
    {   
        $to = "jess@jzm.co.nz";
        $subject = "Booking";
        $headers = "From: " . strip_tags($_POST['Email']) . "\r\n" . "Reply-To: ". strip_tags($_POST['Email']) . "\r\n" . "Content-Type: text/html; charset=ISO-8859-1\r\n"  . header("Location: http://redherringcatering.co.nz/Thankyou.html");
        $message = "\n" . "<strong>NAME:</strong>    ". $varName . "<br />" . "<br />"  . "<strong>CONTACT:</strong>     " . $varContact . "<br />" . "<br />" . "<strong>EMAIL:</strong>    ". $varEmail . "<br />" . "<br />"  ."<strong>COMPANY:</strong>     ". $varCompany . "<br />" . "<br />"  . "<strong>No. ATTENDING:</strong>    ".$varAttending . "<br />" . "<br />"  ."<strong>FUNCTION DATE:</strong>    ". $varFunction . "<br />" . "<br />"  ."<strong>FUNCTION DAY:</strong>     ". $varFunctionDay . "<br />" . "<br />"  ."<strong>DATE ORDERED:</strong>  ". $varOrdered . "<br />" . "<br />"  ."<strong>TIME REQUIRED:</strong>     ". $varTime . "<br />" . "<br />"  . "<strong>ONSITE:</strong>  ". $varOnsite . ", ". $varOnsite2 . "<br />" . "<br />"  ."<strong>INVOICE TO:</strong>     ". $varInvoice . "<br />" . "<br />" ."<strong>ADDRESS:</strong>\n". $varAddress . "<br />" . "<br />"  ."<strong>SPECIAL NEEDS:</strong>   ". $varSpecial . "<br />" . "<br />" . "<strong>ORDER DETAILS:</strong>".  $varDetails. "<br /><strong>Menu:</strong><br/><br/>".  $menu . "<br/><strong>Item Details:</strong><br/><br/>".  $itemstr ."\n";

    mail($to,$subject,$message,$headers);


        exit;
    }


  }
?>

1 个答案:

答案 0 :(得分:2)

您似乎误解了header()重定向的工作原理:

$headers = "From: " . strip_tags($_POST['Email']) . "\r\n" . "Reply-To: ". strip_tags($_POST['Email']) . "\r\n" . 
           "Content-Type: text/html; charset=ISO-8859-1\r\n"  . 
           header("Location: http://redherringcatering.co.nz/Thankyou.html");

这不是重定向的方式,您不会在邮件的标题中添加header()重定向,这是两个截然不同的事情。

您应该删除重定向并将其放在mail()函数之后。但是,只有邮件成功发送:

if(empty($errorMessage)) 
{   
    $to = "jess@jzm.co.nz";
    $subject = "Booking";
    $headers = "From: " . strip_tags($_POST['Email']) . "\r\n" . "Reply-To: ". strip_tags($_POST['Email']) . "\r\n"
               . "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $message = "\n" . "<strong>NAME:</strong>    ". $varName . "<br />" . "<br />"  . "<strong>CONTACT:</strong>     " . $varContact . "<br />" . "<br />" . "<strong>EMAIL:</strong>    ". $varEmail . "<br />" . "<br />"  ."<strong>COMPANY:</strong>     ". $varCompany . "<br />" . "<br />"  . "<strong>No. ATTENDING:</strong>    ".$varAttending . "<br />" . "<br />"  ."<strong>FUNCTION DATE:</strong>    ". $varFunction . "<br />" . "<br />"  ."<strong>FUNCTION DAY:</strong>     ". $varFunctionDay . "<br />" . "<br />"  ."<strong>DATE ORDERED:</strong>  ". $varOrdered . "<br />" . "<br />"  ."<strong>TIME REQUIRED:</strong>     ". $varTime . "<br />" . "<br />"  . "<strong>ONSITE:</strong>  ". $varOnsite . ", ". $varOnsite2 . "<br />" . "<br />"  ."<strong>INVOICE TO:</strong>     ". $varInvoice . "<br />" . "<br />" ."<strong>ADDRESS:</strong>\n". $varAddress . "<br />" . "<br />"  ."<strong>SPECIAL NEEDS:</strong>   ". $varSpecial . "<br />" . "<br />" . "<strong>ORDER DETAILS:</strong>".  $varDetails. "<br /><strong>Menu:</strong><br/><br/>".  $menu . "<br/><strong>Item Details:</strong><br/><br/>".  $itemstr ."\n";

    $result = mail($to,$subject,$message,$headers);

    if ($result)
    {
        header("Location: http://redherringcatering.co.nz/Thankyou.html");
        exit;
    }
    else
    {
      // some error handling
    }
}