2016-07-18 2 views
0

Im phpに新しくなったので、やさしくしてください。phpのコーディングエラーがメインページに戻っていない

私はウェブサイトを作成しており、ニュースレターセクションへの購読を追加しました。ユーザはsubmitを押す前に自分の名前と電子メールアドレスを追加します。私はほとんどの部分が働いているので電子メールを受け取りますが、フォームはウェブサイトのメインページに私を返しません。誰かが私が間違っている場所を指摘できますか?事前

おかげで、ウェブサイト上のコードです:

<form name="frmcontact" id="frmcontact" action="php/contact.php" method="post"> 
     <input id="name" name="name" type="text" value="Name" 
     onblur="this.value=(this.value=='') ? 'Name' : this.value;"    onfocus="this.value=(this.value=='Name') ? '' : this.value;" /> 
<input id="email" name="email" type="text" value="Email" 
onblur="this.value=(this.value=='') ? 'Email' : this.value;" onfocus="this.value=(this.value=='Email') ? '' : this.value;" /> 
<input name="submit" id="send" type="submit" value="Message" /> 
</form> 


The code in contact.php is: 

<?php session_start(); 

if(!$_POST) exit; 

    $address = '[email protected]'; 
    $email_subject ="Add me to the mailing list"; 
    $email = $_REQUEST['email']; 
    $name  = $_REQUEST['name']; 
    $subject = "Please add me to the mailing list "; 

     if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); } 


     $e_subject = 'You\'ve been contacted by ' . $name . '.'; 

     $msg = "You have been contacted by $name with regards to $subject.\r\n\n"; 
     $msg .= "$message\r\n\n"; 
     $msg .= "You can contact $name via email, $email.\r\n\n"; 
     $msg .= "-------------------------------------------------------------------------------------------\r\n"; 

     if(@mail($address, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n")) 
     {echo "<p class='ajax_success'>Thanks for Contact Us.</p>"; } 
     else 
     {echo "<p class='ajax_failure'>Sorry, Try again Later.</p>"; } 
    header('Location:http://www.websiteaddress/homepage.html'); 
?> 
+0

「をヘッダがすでに送信されては」 – JYoThI

+0

コマンドにここにエコーラインをあなたのコードを投稿し – JYoThI

+0

をしようと、あなたは私の手順を試したのですか? – JYoThI

答えて

0

headerheader使用exit前に、すべての出力を削除し、また

    v 
header('Location: http://www.websiteaddress/homepage.html'); 
exit; 
0

使用の下にマークされた空間を与えることを考えます正しいディレクトリパス

if(isset($_POST['submit'])){ 
    $address = '[email protected]'; 
    $email_subject ="Add me to the mailing list"; 
    $email = $_REQUEST['email']; 
    $name  = $_REQUEST['name']; 
    $subject = "Please add me to the mailing list "; 

     if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); } 


     $e_subject = 'You\'ve been contacted by ' . $name . '.'; 

     $msg = "You have been contacted by $name with regards to $subject.\r\n\n"; 
     $msg .= "$message\r\n\n"; 
     $msg .= "You can contact $name via email, $email.\r\n\n"; 
     $msg .= "-------------------------------------------------------------------------------------------\r\n"; 

     if(@mail($address, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n")) 
     {echo "<p class='ajax_success'>Thanks for Contact Us.</p>"; } 
     else 
     {echo "<p class='ajax_failure'>Sorry, Try again Later.</p>"; } 
      header('Location: homepage.html'); 
} 
+0

ディレクトリパスはどこで変更する必要がありますか? –

0

あなたは、ヘッダーを使用する前に、カントの出力は何も()

HTTP-ヘッダーは、サーバーから任意の出力の前に送信する必要があります。あなたが前に出力を持っている場合は、サーバが出力のような警告

<?php 
ob_start(); 

    echo "redirecting now ...."; 
    header('Location: http://www.websiteaddress/homepage.html'); 
    exit(); 

ob_end_flush(); 
?> 
関連する問題