2016-06-24 7 views
0

PHPの電子メールを行う方法からこのコードを借りました。しかし、ここにある彼らのものよりむしろ:http://www.freecontactform.com/email_form.php私は$PHP_SELFを使用し、それをすべて1つのファイルで行うことに決めました。PHPのエラーがHTMLレイアウトの消去部分を出力しています

しかし、エラーが出力されると、私の連絡先物、表、およびフッターの内容が削除されていました。

だから私はダンググリッチでなければならないと思っています。連絡先、表、およびフッターの内容をエコーし​​て、表の最後とフッターの間にエラーメッセージを入れます。

しかし、私の煩わしさにもかかわらず、それはまだそれを消去し、私の新しいもののように行動することさえありません。それはなぜですか、私はそれを修正するために何ができますか?私は彼らのように2つの別々のファイルを使用する方が良いですか? (彼らが正しく入力したか、間違って入力したとしても、戻ってきたボタンは決してなかったので、私はアプローチが嫌いでした)

私はそれを正しく取得してもエラーはしませんメッセージは、上のすべてのものを出力しますが、フォームとフォームの場所にはありません。

最後に、私は自分のメールをチェックすると(私は上記以外の何かを持っていることを知っていますが、私の主なメールアドレスで私は自分のメールアドレスを使っています。私のメールボックス。

<html> 
    <head> 
     <title> Contact Us </title> 
     <link rel="stylesheet" type="text/css" href="./main.css"> 
     <link rel="icon" href="./ski_icon.png"> 
     <script src="jquery-3.0.0.min.js" type="text/javascript"></script> 
     <script> 
      $(document).ready(function() { 
       $("#container").css("height", 1135); 
      }); 
     </script> 
    </head> 
    <body> 
     <style> 
      form { 
       border: 1px solid transparent; 
       text-align: center; 
      } 
     </style> 
     <div id="content"> 
      <div id="logo"> 
       <img src="./logo.png"></img> 
      </div> 
      <div id="container"> 
       <nav id="hor"> 
        <div><a href="index.html"> Home </a> </div> 
        <div><a href="mountains.html"> The Mountains </a></div> 
        <div><a href="resorts.html"> The Resorts </a></div> 
        <div><a href="snowreports.html"> Snow Reports </a></div> 
        <div><a href="eventsandactivities.html"> Events &amp Activities </a></div> 
        <div><a href="plantrip.html"> Plan A Trip </a></div> 
       </nav> 
       <div id="middle"> 
        <nav id="vert"> 
         <a href="index.html"> Home </a> <br/> 
         <a href="mountains.html"> The Mountains </a><br/> 
         <a href="resorts.html"> The Resorts </a><br/> 
         <a href="snowreports.html"> Snow Reports </a><br/> 
         <a href="eventsandactivities.html"> Events &amp Activities </a><br/> 
         <a href="plantrip.html"> Plan A Trip </a> 
        </nav>  
        <style> 
         td { 
          vertical-align: top; 
         } 
        </style>  
        <?php 
         if(isset($_POST['email'])) { 
          // EDIT THE 2 LINES BELOW AS REQUIRED 
          $email_to = "[email protected]"; 
          $email_subject = "Your email subject line"; 
          function died($error) { 
           // your error code can go here 
           echo "<div id='text-container'>" ; 
            echo "<h1>Contact Us</h1>"; 
            echo "<form name='contactform' method='post' action='$_PHP_SELF'>"; 
             echo"<table width='450px'>"; 
              echo "<tr>"; 
               echo" <td valign='top'>"; 
                echo "<label for='first_name'>First Name *</label>"; 
               echo "</td>"; 
               echo " <td valign='top'>"; 
                echo" <input type='text' name='first_name' maxlength='50' size='30'>"; 
               echo "</td>"; 
              echo "</tr>"; 
              echo "<tr>"; 
               echo"<td valign='top'>"; 
                echo "<label for='last_name'>Last Name *</label>"; 
               echo "</td>"; 
               echo "<td valign='top'>"; 
                echo "<input type='text' name='last_name' maxlength='50' size='30'>"; 
               echo "</td>"; 
              echo "</tr>"; 
              echo "<tr>"; 
               echo "<td valign='top'>"; 
                echo "<label for='email'>Email Address *</label>";  
               echo "</td>"; 
               echo "<td valign='top'>"; 
                echo "<input type='text' name='email' maxlength='80' size='30'>"; 
               echo "</td>"; 
              echo "</tr>"; 
              echo "<tr>"; 
               echo "<td valign='top'>"; 
                echo "<label for='telephone'>Telephone Number</label>"; 
               echo "</td>"; 
               echo "<td valign='top'>"; 
                echo "<input type='text' name='telephone' maxlength='30' size='30'>"; 
               echo "</td>"; 
              echo "</tr>";  
              echo "<tr>"; 
               echo "<td valign='top'>"; 
                echo "<label for='comments'>Comments *</label>"; 
               echo "</td>"; 
               echo "<td valign='top'>"; 
                echo "<textarea name='comments' maxlength='1000' cols='25' rows='6'></textarea>"; 
               echo "</td>"; 
              echo "</tr>"; 
              echo "<tr>"; 
               echo "<td colspan='2' style='text-align:center'>"; 
                echo "<input type='submit' value='Submit'> <a href='http://www.freecontactform.com/email_form.php'>Email Form</a>";  
               echo "</td>"; 
              echo "</tr>"; 
             echo "</table>"; 
            echo "</form>"; 
            echo "Bla bla bla"; 
            echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
            echo "These errors appear below.<br /><br />";  
            echo $error."<br /><br />"; 
            echo "Please go back and fix these errors.<br /><br />"; 
           echo "</div>"; 
          echo "</div>"; 
         echo "</div>"; 
         echo "<div id='footercontainer'>"; 
          echo "<footer>"; 
           echo "Copyright &copy; 2016 Dimaond Peaks Resort, &nbsp; All Rights Reserved. <br/>"; 
           echo "<a href='http://www.allwebpromotion.com/' target='_blank'>Website Design</a> by: All Web Promotion"; 
          echo "</footer>"; 
         echo "</div>"; 
        echo "</div>"; 
       } 
       // validation expected data exists 
       if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) 
       { 
        died('We are sorry, but there appears to be a problem with the form you submitted.');  
       } 
       $first_name = $_POST['first_name']; // required 
       $last_name = $_POST['last_name']; // required 
       $email_from = $_POST['email']; // required 
       $telephone = $_POST['telephone']; // not required 
       $comments = $_POST['comments']; // required 
       $error_message = ""; 
       $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
       if(!preg_match($email_exp,$email_from)) { 
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
       } 
       $string_exp = "/^[A-Za-z .'-]+$/"; 
       if(!preg_match($string_exp,$first_name)) { 
        $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 
       } 
       if(!preg_match($string_exp,$last_name)) { 
        $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; 
       } 
       if(strlen($comments) < 2) { 
        $error_message .= 'The Comments you entered do not appear to be valid.<br />'; 
       } 
       if(strlen($error_message) > 0) { 
        died($error_message); 
       } 
       $email_message = "Form details below.\n\n"; 
       function clean_string($string) { 
        $bad = array("content-type","bcc:","to:","cc:","href"); 
        return str_replace($bad,"",$string); 
       } 
       $email_message .= "First Name: ".clean_string($first_name)."\n"; 
       $email_message .= "Last Name: ".clean_string($last_name)."\n"; 
       $email_message .= "Email: ".clean_string($email_from)."\n"; 
       $email_message .= "Telephone: ".clean_string($telephone)."\n"; 
       $email_message .= "Comments: ".clean_string($comments)."\n"; 
       // create email headers 
       $headers = 'From: '.$email_from."\r\n". 
         'Reply-To: '.$email_from."\r\n" . 
         'X-Mailer: PHP/' . phpversion(); 
       @mail($email_to, $email_subject, $email_message, $headers); 
      ?> 
      <!-- include your own success html here --> 
      Thank you for contacting us. We will be in touch with you very soon. 
      <?php } ?> 
      <div id="text-container"> 
       <h1>Contact Us</h1> 
       <form name="contactform" method="post" action="<?php $_PHP_SELF ?>"> 
        <table width="450px"> 
         <tr> 
          <td valign="top"> 
           <label for="first_name">First Name *</label> 
          </td> 
          <td valign="top"> 
           <input type="text" name="first_name" maxlength="50" size="30"> 
          </td> 
         </tr> 
         <tr> 
          <td valign="top""> 
           <label for="last_name">Last Name *</label> 
          </td> 
          <td valign="top"> 
           <input type="text" name="last_name" maxlength="50" size="30"> 
          </td> 
         </tr> 
         <tr> 
          <td valign="top"> 
           <label for="email">Email Address *</label> 
          </td> 
          <td valign="top"> 
           <input type="text" name="email" maxlength="80" size="30"> 
          </td> 
         </tr> 
         <tr> 
          <td valign="top"> 
           <label for="telephone">Telephone Number</label> 
          </td> 
          <td valign="top"> 
           <input type="text" name="telephone" maxlength="30" size="30"> 
          </td> 
         </tr> 
         <tr> 
          <td valign="top"> 
           <label for="comments">Comments *</label> 
          </td> 
          <td valign="top"> 
           <textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea> 
          </td> 
         </tr> 
         <tr> 
          <td colspan="2" style="text-align:center"> 
           <input type="submit" value="Submit"> <a href="http://www.freecontactform.com/email_form.php">Email Form</a> 
          </td> 
         </tr> 
        </table> 
       </form> 
      </div> 
     </div> 
    </div> 
    <div id="footercontainer"> 
     <footer>Copyright &copy; 2016 Dimaond Peaks Resort, &nbsp; All Rights Reserved. <br/><a href="http://www.allwebpromotion.com/" target="_blank">Website Design</a> by: All Web Promotion</footer> 
    </div> 
</body> 
</html> 
+0

エラーメッセージは何ですか? –

+0

大変申し訳ございませんが、送信したフォームにエラーが見つかりました。これらのエラーは以下に表示されます。 入力した電子メールアドレスが有効ではありません。 入力した名字は有効ではありません。 入力した姓が有効ではありません。 入力したコメントは有効ではありません。 戻って、これらのエラーを修正してください。 – MongooseLover

+0

それは問題ではありません。問題は、フォームの下にそのメッセージを追加し、フォームとその下のフッターを上書きしないようにすることです。さらに、それが正しいとすれば、それはフォームがあった場所ではなく、話すために、すべてを底に置いています。そして、最後に、私は自分のメールボックスにメッセージが表示されることはありません。 – MongooseLover

答えて

1

... [戻る]ボタンやフォームを表示)

<html> 
<head> 
<title> Contact Us </title> 
<link rel="stylesheet" type="text/css" href="./main.css"> 
<link rel="icon" href="./ski_icon.png"> 
<script src="jquery-3.0.0.min.js" type="text/javascript"></script> 
<script> 
$(document).ready(function() { 

    $("#container").css("height", 1135); 


    }); 

    </script> 

</head> 
<body> 


<style> 

form 
{ 
border: 1px solid transparent; 
text-align: center; 

} 
</style> 

<div id="content"> 
<div id="logo"> 
<img src="./logo.png"></img> 
</div> 
<div id="container"> 
<nav id="hor"> 
<div><a href="index.html"> Home </a> </div> 
<div><a href="mountains.html"> The Mountains </a></div> 
<div><a href="resorts.html"> The Resorts </a></div> 
<div><a href="snowreports.html"> Snow Reports </a></div> 
<div><a href="eventsandactivities.html"> Events &amp Activities </a></div> 
<div><a href="plantrip.html"> Plan A Trip </a></div> 
</nav> 
<div id="middle"> 
<nav id="vert"> 
<a href="index.html"> Home </a> <br/> 
<a href="mountains.html"> The Mountains </a><br/> 
<a href="resorts.html"> The Resorts </a><br/> 
<a href="snowreports.html"> Snow Reports </a><br/> 
<a href="eventsandactivities.html"> Events &amp Activities </a><br/> 
<a href="plantrip.html"> Plan A Trip </a> 
</nav> 

<style> 

td 
{ 

vertical-align: top; 
} 

</style> 

<?php 

if(isset($_POST['email'])) { 



    // EDIT THE 2 LINES BELOW AS REQUIRED 

    $email_to = "[email protected]"; 

    $email_subject = "Your email subject line"; 





    function died($error) { 

     // your error code can go here 



     echo "<div id='text-container'>" ; 

echo "<h1>Contact Us</h1>"; 

echo "<form name='contactform' method='post' action='$_PHP_SELF'>"; 

echo"<table width='450px'>"; 

echo "<tr>"; 

echo" <td valign='top'>"; 

    echo "<label for='first_name'>First Name *</label>"; 

echo "</td>"; 

echo " <td valign='top'>"; 

echo" <input type='text' name='first_name' maxlength='50' size='30' value='".(isset($_POST['first_name'])?$_POST['first_name']:'')."' >"; 

echo "</td>"; 

echo "</tr>"; 

echo "<tr>"; 

echo"<td valign='top'>"; 

    echo "<label for='last_name'>Last Name *</label>"; 

echo "</td>"; 

echo "<td valign='top'>"; 

    echo "<input type='text' name='last_name' maxlength='50' size='30' value='".(isset($_POST['last_name'])?$_POST['last_name']:'')."' >"; 

echo "</td>"; 

echo "</tr>"; 

echo "<tr>"; 

echo "<td valign='top'>"; 

echo "<label for='email'>Email Address *</label>"; 

echo "</td>"; 

echo "<td valign='top'>"; 

echo "<input type='text' name='email' maxlength='80' size='30' value='".(isset($_POST['email'])?$_POST['email']:'')."' >"; 

echo "</td>"; 

echo "</tr>"; 

echo "<tr>"; 

echo "<td valign='top'>"; 

echo "<label for='telephone'>Telephone Number</label>"; 

echo "</td>"; 

echo "<td valign='top'>"; 

echo "<input type='text' name='telephone' maxlength='30' size='30'  value='".(isset($_POST['telephone'])?$_POST['telephone']:'')."' >"; 

echo "</td>"; 

echo "</tr>"; 

echo "<tr>"; 

echo "<td valign='top'>"; 

echo "<label for='comments'>Comments *</label>"; 

echo "</td>"; 

echo "<td valign='top'>"; 

echo "<textarea name='comments' maxlength='1000' cols='25' rows='6'> ".(isset($_POST['comments'])?$_POST['comments']:'')." </textarea>"; 

echo "</td>"; 

echo "</tr>"; 

echo "<tr>"; 

echo "<td colspan='2' style='text-align:center'>"; 

    echo "<input type='submit' value='Submit'> <a href='http://www.freecontactform.com/email_form.php'>Email Form</a>"; 

echo "</td>"; 

echo "</tr>"; 

echo "</table>"; 

echo "</form>"; 

echo "Bla bla bla"; 

     echo "We are very sorry, but there were error(s) found with the form you submitted. "; 

     echo "These errors appear below.<br /><br />"; 

     echo $error."<br /><br />"; 

     echo "Please go back and fix these errors.<br /><br />"; 


     echo "</div>"; 
echo "</div>"; 
echo "</div>"; 

echo "<div id='footercontainer'>"; 
echo "<footer>"; 
echo "Copyright &copy; 2016 Dimaond Peaks Resort, &nbsp; All Rights Reserved. <br/>"; 
echo "<a href='http://www.allwebpromotion.com/' target='_blank'>Website Design</a> by: All Web Promotion"; 

echo "</footer>"; 
echo "</div>"; 
echo "</div>"; 

    } 



    // validation expected data exists 

    if(!isset($_POST['first_name']) || 

     !isset($_POST['last_name']) || 

     !isset($_POST['email']) || 

     !isset($_POST['telephone']) || 

     !isset($_POST['comments'])) { 

     died('We are sorry, but there appears to be a problem with the form you submitted.'); 

    } 



    $first_name = $_POST['first_name']; // required 

    $last_name = $_POST['last_name']; // required 

    $email_from = $_POST['email']; // required 

    $telephone = $_POST['telephone']; // not required 

    $comments = $_POST['comments']; // required 



    $error_message = ""; 

    $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 

    if(!preg_match($email_exp,$email_from)) { 

    $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 

    } 

    $string_exp = "/^[A-Za-z .'-]+$/"; 

    if(!preg_match($string_exp,$first_name)) { 

    $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 

    } 

    if(!preg_match($string_exp,$last_name)) { 

    $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; 

    } 

    if(strlen($comments) < 2) { 

    $error_message .= 'The Comments you entered do not appear to be valid.<br />'; 

    } 

    if(strlen($error_message) > 0) { 

    died($error_message); 

    } 

    $email_message = "Form details below.\n\n"; 



    function clean_string($string) { 

     $bad = array("content-type","bcc:","to:","cc:","href"); 

     return str_replace($bad,"",$string); 

    } 



    $email_message .= "First Name: ".clean_string($first_name)."\n"; 

    $email_message .= "Last Name: ".clean_string($last_name)."\n"; 

    $email_message .= "Email: ".clean_string($email_from)."\n"; 

    $email_message .= "Telephone: ".clean_string($telephone)."\n"; 

    $email_message .= "Comments: ".clean_string($comments)."\n"; 





// create email headers 

$headers = 'From: '.$email_from."\r\n". 

'Reply-To: '.$email_from."\r\n" . 

'X-Mailer: PHP/' . phpversion(); 

@mail($email_to, $email_subject, $email_message, $headers); 
exit; 
?> 



<!-- include your own success html here --> 



Thank you for contacting us. We will be in touch with you very soon. 



<?php 

} 

?> 




<div id="text-container"> 

<h1>Contact Us</h1> 

<form name="contactform" method="post" action="<?php $_PHP_SELF ?>"> 

<table width="450px"> 

<tr> 

<td valign="top"> 

    <label for="first_name">First Name *</label> 

</td> 

<td valign="top"> 

    <input type="text" name="first_name" maxlength="50" size="30"> 

</td> 

</tr> 

<tr> 

<td valign="top""> 

    <label for="last_name">Last Name *</label> 

</td> 

<td valign="top"> 

    <input type="text" name="last_name" maxlength="50" size="30"> 

</td> 

</tr> 

<tr> 

<td valign="top"> 

    <label for="email">Email Address *</label> 

</td> 

<td valign="top"> 

    <input type="text" name="email" maxlength="80" size="30"> 

</td> 

</tr> 

<tr> 

<td valign="top"> 

    <label for="telephone">Telephone Number</label> 

</td> 

<td valign="top"> 

    <input type="text" name="telephone" maxlength="30" size="30"> 

</td> 

</tr> 

<tr> 

<td valign="top"> 

    <label for="comments">Comments *</label> 

</td> 

<td valign="top"> 

    <textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea> 

</td> 

</tr> 

<tr> 

<td colspan="2" style="text-align:center"> 

    <input type="submit" value="Submit"> <a href="http://www.freecontactform.com/email_form.php">Email Form</a> 

</td> 

</tr> 

</table> 

</form> 



    </div> 
</div> 
</div> 

<div id="footercontainer"> 
<footer> 
Copyright &copy; 2016 Dimaond Peaks Resort, &nbsp; All Rights Reserved. <br/> 
<a href="http://www.allwebpromotion.com/" target="_blank">Website Design</a> by: All Web Promotion 

</footer> 
</div> 
</div> 

</body> 
</html> 
1

あなたの死んだ()関数の出力はあなたのコードを少し再構築、以下に示しているのと同じコンタクトフォームが含まれています。

が死亡してフォームを取り除く()関数

function died($error) { 

     echo "Bla bla bla"; 

     echo "We are very sorry, but there were error(s) found with the form you submitted. "; 

     echo "These errors appear below.<br /><br />"; 

     echo $error."<br /><br />"; 

     echo "Please go back and fix these errors.<br /><br />"; 

    } 

あなたが

<!-- include your own success html here --> 
Thank you for contacting us. We will be in touch with you very soon. 

<a href="<?php $_PHP_SELF ?>">Go Back</a> 

<?php 

} 


// get rid or comment this condition if want show form with the errors messages 
if (!$error_message) { 

?> 


<div id="text-container"> 

<h1>Contact Us</h1> 

形をしたい場合はショーの後、検証エラーは=あなたのniceと固定コードがある

<?php 
    } 
?> 
関連する問題