PHP错误输出清除了我的html布局的一部分

猫鼬情人

我从如何做PHP电子邮件程序中借用了此代码。但是,不是他们的文件,而是这里的文件:http : //www.freecontactform.com/email_form.php我决定使用$PHP_SELF它并在一个文件中完成所有操作。

但是,由于输出错误,因此删除了我的“联系我们”内容,表格和页脚内容。

所以我想,一定是当场小故障,我只是回显“联系我们”,表格和页脚中的内容,并将错误消息放在表格末尾和页脚之间。

但是,令我非常烦恼的是,它仍然被擦除,并且像我的新玩意儿一样不在场。为什么会这样,我该怎么做才能解决?我最好像他们一样使用两个单独的文件吗?(我不喜欢他们的方法,因为一旦他们输入正确或输入错误,就再也没有后退按钮。)

甚至更陌生,如果我正确地处理了它并且不执行错误消息,那么它确实将上面的所有内容输出了,尽管是在底部,而不是原来的形式和形式。

最后,当我检查我的电子邮件时(我知道我上面还有其他内容,但是在我的主要电子邮件地址中,我使用了我的电子邮件地址,也将其放在“发件人”框中。但是,它没有显示在我的邮箱中。

<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._%-]+@[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>
马克西姆·塞梅尼欣(Maksym Semenykhin)

有您的nice固定代码=)

<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._%-]+@[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>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章