-1

基本的なフォームがあり、送信時にインデックス ページとは異なるページにリダイレクトしようとしています。私はこれだけを得ることができます:

 header("Location: http://www.mysite.com/thanks.php"); 

上に置くと動作する

 <!doctype html>

しかし、これは IE では機能せず、HTML5 検証エラーが発生します。

ここに私のコードがあります: ページの上部:

   <?php
  include("functions/contactfunctions.php"); 



   ?>

さらに下:

  <?php
    if($_POST['submitted'] == "contactus")
    {
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];

    $email = $_POST['email'];
    $message = $_POST['message'];
    $location = $_POST['location'];
            if(!$firstname)
    $error = "Please enter your first name.";
    else
    if(!$lastname)
    $error = "Please enter your last name.";
    else
    if(!$email)
    $error = "Please enter a valid email.";
    else
    if(!$message)
    $error = "Please enter your message.";
    else
    if(!$location)
    $error = "Please tell us where you're from.";


    }
  ?>

    <?php
       if($_POST['submitted'])
       {
      ContactMessage($firstname, $lastname, $email, $message, $location);
        header("Location:http://www.mywebsite.com/thanks.php");
       exit;
    }

 ?> 

連絡先の functions.php は次のとおりです。

 <?php 
 include_once("databasefunctions.php");

 $contactsdbtable = "contacts";

 function GetHeaders()
 {
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    // Additional headers
    $headers .= "To: {$firstname} <{$email}>" . "\r\n";
    $headers .= 'From: My Site <noreply@mysite.com>' . "\r\n";
    return $headers;
 }
 function ContactMessage($firstname, $lastname, $email, $message, $location)
 {
global $contactsdbtable;
openDatabase();
$firstname = mysql_real_escape_string($firstname);
$lastname = mysql_real_escape_string($lastname);
$email = mysql_real_escape_string($email);
$message = mysql_real_escape_string($message);
$location = mysql_real_escape_string($location);

$result = QuickQuery("INSERT INTO {$contactsdbtable}(firstname, lastname, email,         message, location) 
                      VALUES('{$firstname}', '{$lastname}', '{$email}', '{$message}',  '{$location}')");

if($result)
   {
    $headers = GetHeaders();
    $message = "\"Thank you for contacting us blah blah. We will be        answering your website inquiry post haste.\"<br />
    <br />
    <br />
    Best Regards,<br />
    <br />
    Us
    ";
    mail($email, "RE: Website Inquiry", $message, $headers);
    mail("myemail@blank.com", "Website Inquiry", "{$firstname}, {$email}, has sent a web design inquiry", $headers);

     }
   }


 ?>

また、インデックス ページと contactfunctions.php に追加しようとしましたが、役に立ちませんでした。送信すると、フォームのアクションである index.php にリダイレクトされます。

よろしくお願いします。

4

3 に答える 3

2

開始前にスペースがあります<?php。ヘッダーを送信する前にコンテンツを持つことはできません。これには空白が含まれます

于 2012-07-30T01:05:05.140 に答える
0

前にスペースとワードラップを削除します

<?php

空白でさえナビゲーターに送信される情報であるため、ヘッダーにはもう含まれていません。

編集:答えはすでに与えられています。

于 2012-07-30T01:17:52.590 に答える
-1

もしヘッダー(); ページをリダイレクトしなかった場合は、フォームが適切に送信されていないことを意味します。$_POST['submitted'] をチェックする代わりに、フォームのすべての入力をチェックすることをお勧めします。

if($_POST['email']&&$_POST['message']/* And so on... */){
   echo "echo something here so you know it ACTUALLY HAS been submitted.";
}

ヒント: header(); を使用する場合。必ず ob_start(); を使用してください。およびob_flush(); このような:

//Start of script
ob_start();

//Now header(); will work efficiently here inside your functions...

//End of script
ob_flush();
于 2012-07-30T02:52:15.840 に答える