0

我目前正在这个网站上工作: 链接到网站

并且表格似乎不起作用。当您提交时,它总是会转到错误页面。我还在 Windows 服务器上尝试了这个站点(不确定这是否会有所不同)并且表单工作正常。

这是我正在使用的代码...

            <?php

            // get posted data into local variables

            $EmailTo = "***@***.com";
            $Subject = Trim(stripslashes($_POST['Subject'])); 
            $Name = Trim(stripslashes($_POST['Name'])); 
            $Email = Trim(stripslashes($_POST['Email'])); 
            $Address = Trim(stripslashes($_POST['Address'])); 
            $City = Trim(stripslashes($_POST['City'])); 
            $State = Trim(stripslashes($_POST['State'])); 
            $Zip = Trim(stripslashes($_POST['Zip'])); 
            $Phone = Trim(stripslashes($_POST['Phone'])); 
            $Message = Trim(stripslashes($_POST['Message'])); /*
            $Sign = Trim(stripslashes($_POST['Sign'])); 
            $Volunteer = Trim(stripslashes($_POST['Volunteer'])); 
            $Walk = Trim(stripslashes($_POST['Walk'])); 
            $Coffee = Trim(stripslashes($_POST['Coffee'])); 
            $Calls = Trim(stripslashes($_POST['Calls'])); 
            $Donate = Trim(stripslashes($_POST['Donate'])); */
            $EmailFromName = $Name;
            $EmailFromAddress = $Email;

            // validation
            $validationOK=true;
            if (!$validationOK) {
              print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
              exit;
            }

            // prepare email body text
            $Body = "";
            $Body .= "This Email was sent from the Saviano for State Representative Website, contact page.";
            $Body .= "\n";
            $Body .= "\n";
            $Body .= "Name: ";
            $Body .= $Name;
            $Body .= "\n";
            $Body .= "Address: ";
            $Body .= $Address;
            $Body .= "\n";
            $Body .= "City: ";
            $Body .= $City;
            $Body .= "\n";
            $Body .= "State: ";
            $Body .= $State;
            $Body .= "\n";
            $Body .= "Zip: ";
            $Body .= $Zip;
            $Body .= "\n";
            $Body .= "\n";
            $Body .= "Phone: ";
            $Body .= $Phone;
            $Body .= "\n";
            $Body .= "Email: ";
            $Body .= $Email;
            $Body .= "\n";
            $Body .= "\n";
            $Body .= "Subject: ";
            $Body .= $Subject;
            $Body .= "\n";
            $Body .= "\n";
            $Body .= "Message: ";
            $Body .= $Message;
            $Body .= "\n";
            $Body .= "\n";/*
            $Body .= "Sign: ";
            $Body .= $Sign;
            $Body .= "\n";
            $Body .= "\n";
            $Body .= "Volunteer: ";
            $Body .= $Volunteer;
            $Body .= "\n";
            $Body .= "\n";
            $Body .= "Walk: ";
            $Body .= $Walk;
            $Body .= "\n";
            $Body .= "\n";
            $Body .= "Coffee: ";
            $Body .= $Coffee;
            $Body .= "\n";
            $Body .= "\n";
            $Body .= "Calls: ";
            $Body .= $Calls;
            $Body .= "\n";
            $Body .= "\n";
            $Body .= "Donate: ";
            $Body .= $Donate;*/
            $Body .= "\n";




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

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

ps调查和志愿者页面上的表格也不起作用,但可以在Windows服务器上使用。

4

1 回答 1

0

根据RFC 2822:标题字段由 CRLF 终止。

试试这个(我在最后添加了“\r\n”):

$success = mail($EmailTo, $Subject, $Body, "From: $EmailFromName <$EmailFromAddress>\r\n");
于 2012-08-16T03:20:02.280 回答