PHP联系表单不起作用,得到"转发被拒绝"错误

时间:2017-11-08 02:46:09

标签: php html email server localhost

我对php非常陌生,并通过关注视频制作了联系表单,但它似乎无法正常工作。我收到了STARTTLS错误,但后来我添加了

的ini_set(" SMTP"" SSL://smtp.gmail.com"); 的ini_set(" SMTP_PORT"" 465&#34);

我不知道为什么它是gmail以及为什么这个端口当原来的smtp和端口是来自我的ISP而不是gmail,但是现在我已经添加了这个,我得到一个单独的错误?

错误:

警告:mail():SMTP服务器响应:550 5.7.1在第83行的C:\ xampp \ htdocs \ ContactForm \ form_process.php中拒绝接收

我在Localhost XAMPP Apache服务器上运行它以在注册托管服务之前对其进行测试。我已经包含了我的index.php(主要是html),我的form_process.php(实际的错误捕获和发送邮件就在这里)。

在我的php.ini中:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.mymts.net ;smtp.gmail.com
; http://php.net/smtp-port
smtp_port=587 ;465

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = ExampleEmail@gmail.com

index.php(我不确定我是否需要像doctype和标题的东西,但我添加了一个正文,因为我需要将css应用于整个身体,然后是一个标题来组织链接,其余只是因为我想也许没关系):

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php include ('form_process.php');?>
<html>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <head>
        <link rel="stylesheet" type="text/css" href="css/email.css">
        <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    </head>
    <body>    
        <div id="navbar" class="li flex-container nav hidden-xs">
            <a class="nav-link flex-item " href="index.html#bottom">PHOTOGRAPHER</a>
            <a class="nav-link flex-item" href="Portfolio.html">PORTFOLIO</a>
            <a class="hplogo-a flex-item hidden-xs hidden-sm" href=""><img id="logo" src="Images/WHITELOGO.png" alt=""></a>
            <a class="nav-link flex-item" href="Investment.html">INVESTMENT + FAQ</a>
            <a class="nav-link flex-item" href="#">BLOG</a>
        </div>
        <div id="myNav" class="overlay hidden-sm hidden-md hidden-lg">
            <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
            <div class="overlay-content">
                <a href="index.html#bottom">PHOTOGRAPHER</a>
                <a href="Portfolio.html">PORTFOLIO</a>
                <a href="javascript:window.location.reload();">INVESTMENT + FAQ</a>
                <a href="#">BLOG</a>
            </div>
        </div>

        <span id="toggle" style="font-size:30px;cursor:pointer" onclick="openNav()" class="hidden-sm hidden-lg hidden-md popup">&#9776; </span>
        <div class="container top email">

            <p class="eramble eramble1 col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10 "> Finding a photographer is a delicate process and you really need to trust your instinct. You put your trust and faith in us to capture your most valuable memories and to tell your story through our camera.  You're here because you feel that my work can represent and accentuate the love between you and your fiancé.</p>
            <p class="eramble eramble2  col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">If this is the case, I would love to hear more about you and about your wedding day.  So, lets start here! </p>
            <div class="email_form">  
                <form id="contact" action="<?= $_SERVER['PHP_SELF'];?>" method="post">
                    <div class="form-group row">

                        <div class="col-sm-5 col-xs-5 col-xs-offset-1 col-sm-offset-1">
                            <label for="fname">Name*</label>
                            <input class="form-control" id="fname" placeholder="Your first name" type="text" tabindex="1" size="30" name="fname" value="<?= $fname ?>" autofocus>
                            <label for="fname" style="font-size:9px; font-weight:normal; ">First Name</label> 
                            <span class="error"><?= $fname_error?> </span>
                        </div>
                        <div class="col-sm-5 col-xs-5">
                            <label class="visuallyhidden" for="lname">lNAME</label>
                            <input class="form-control" id="lname" placeholder="Your last name" type="text" name="lname" value="<?= $lname ?>" tabindex="4" >
                            <label for="lname" style="font-size:9px; font-weight:normal; ">Last Name</label>
                            <span class="error"><?= $lname_error?> </span> 
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-sm-10 col-xs-10 col-xs-offset-1 col-sm-offset-1">
                            <label for="email">Email Address*</label> 
                            <input class="form-control" id="email" placeholder="Your Email Address" type="text" name="email" value="<?= $email ?>" tabindex="2" >
                            <span class="error"><?= $email_error?> </span>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-sm-2 col-xs-2 col-xs-offset-1 col-sm-offset-1">
                            <label for="phone1">Phone*</label>
                            <input class="form-control" size="4" maxlength="3" id="phone1" placeholder="Your Phone Number" type="text" name="phone1" value="<?= $phone1 ?>" tabindex="3" >
                            <label for="phone1" style="font-size:9px; font-weight:normal; ">(###)</label>
                            <span class="error"><?= $phone1_error?> </span>
                        </div>
                        <div class="col-sm-2 col-xs-2">
                            <label class="visuallyhidden" for="phone2">Phone*</label>
                            <input class="form-control" size="4" maxlength="3" id="phone2" placeholder="Your Phone Number" type="text" name="phone2" value="<?= $phone2 ?>" tabindex="3" >
                            <label for="phone2" style="font-size:9px; font-weight:normal; ">###</label>
                            <span class="error"><?= $phone2_error?> </span>
                        </div>
                        <div class="col-sm-2 col-xs-2">
                            <label class="visuallyhidden" for="phone3">Phone*</label>
                            <input class="form-control" size="5" maxlength="4" id="phone3" placeholder="Your Phone Number" type="text" name="phone3" value="<?= $phone3 ?>" tabindex="3" >
                            <label for="phone3" style="font-size:9px; font-weight:normal; ">####</label>
                            <span class="error"><?= $phone3_error?> </span>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-sm-10 col-xs-10 col-xs-offset-1 col-sm-offset-1">
                            <label for="message">Message*</label>
                            <textarea placeholder="Type your Message Here...." class="message1 form-control" rows="5" id="message" name="message" tabindex="5" ><?php if(isset($_POST['message'])){ 
                    echo htmlentities ($_POST['message']); }?></textarea>
                            <span class="error"><?= $message_error?></span> 
                        </div>
                    </div>
                    <div >
                        <button class="btn-default btn rbutton col-xs-offset-1 col-sm-offset-1" name="submit" type="submit" id="contact-submit" data-submit="...Sending">Submit</button>
                    </div> 
                    <div class="success"><?= $success;?></div>
                </form>


            </div>
        </div>
        <div class="container bottom faq">
            <h1>FAQ</h1>
            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>

            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>
            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>
            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>
            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>
            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>
            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>
            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>
            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>
            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>
            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>
            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>
            <h3 class="question col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur.</h3>
            <p class="answer Lastanswer col-xs-offset-1 col-sm-offset-1 col-xs-10 col-sm-10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam sint voluptatibus libero unde ipsam, rem quod nesciunt vel amet totam quia, enim, doloribus esse iure, ad. Nesciunt suscipit molestias voluptates explicabo iure error, sapiente qui quam, laboriosam praesentium expedita doloribus magnam. Non aliquam, voluptatum earum odio cumque sapiente aut, necessitatibus</p>





        </div>
        <div class="footer">
            <footer class="foot">
                <h6> AVAILABLE WORLDWIDE</h6>      <h6> 2049671111</h6>
                <a href="#">MRPOOPYBUTTHOLE@GMAIL.COM</a>
            </footer>
        </div>

        <script>

            function openNav() {
                document.getElementById("myNav").style.height = "100%";
            }

            function closeNav() {
                document.getElementById("myNav").style.height = "0%";
            }
        </script>
        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
    </body>
</html>

form_process.php:

<?php 
// define variables and set to empty values
$fname_error = $lname_error = $email_error = $phone1_error = $phone2_error = $phone3_error = $message_error="";
$fname = $lname = $email = $phone1 = $phone2 = $phone3 = $message = $success = "";

//form is submitted with POST method
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["fname"])) {
    $fname_error = "Name is required";
  } else {
    $fname = test_input($_POST["fname"]);
    // check if name only contains letters and whitespace
    if (!preg_match("/^[a-zA-Z ]*$/",$fname)) {
      $fname_error = "Only letters and white space allowed"; 
    }
  }

  if (empty($_POST["lname"])) {
    $lname_error = "Name is required";
  } else {
    $lname = test_input($_POST["lname"]);
    // check if name only contains letters and whitespace
    if (!preg_match("/^[a-zA-Z ]*$/",$fname)) {
      $lname_error = "Only letters and white space allowed"; 
    }
  }

  if (empty($_POST["email"])) {
    $email_error = "Email is required";
  } else {
    $email = test_input($_POST["email"]);
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $email_error = "Invalid email format"; 
    }
  }

  if (empty($_POST["phone1"])) {
    $phone1_error = "required";
  } else {
    $phone1 = test_input($_POST["phone1"]);
    // check if e-mail address is well-formed

  }
  if (empty($_POST["phone2"])) {
    $phone2_error = "required";
  } else {
    $phone2 = test_input($_POST["phone2"]);
    // check if e-mail address is well-formed

  }
  if (empty($_POST["phone3"])) {
    $phone3_error = "required";
  } else {
    $phone3 = test_input($_POST["phone3"]);
    // check if e-mail address is well-formed
  }    
  if (empty($_POST["url"])) {
    $url_error = "";
  } else {
    $url = test_input($_POST["url"]);
    // check if URL address syntax is valid (this regular expression also allows dashes in the URL)
    if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$url)) {
      $url_error = "Invalid URL"; 
    }
  }

  if (empty($_POST["message"])) {
    $message_error = "Message is required";
  } else {
    $message = test_input($_POST["message"]);
  }

  if ($fname_error == '' and $lname_error == '' and $email_error == '' and $phone1_error == '' and $phone2_error == '' and $phone3_error == '' and $url_error == '' ){
      $message_body = '';
      unset($_POST['submit']);
      foreach ($_POST as $key => $value){
          $message_body .=  "$key: $value\n";
      }

      $to = 'thetalhasuboor@gmail.com';
      $subject = 'Contact Form Submit';
      if (mail($to, $subject, $message_body)){
          $success = "Message sent, thank you for contacting us!";
          $fname = $lname = $email = $phone1 = $phone2 = $phone3 = $message = $url = '';
      }
  }

}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

0 个答案:

没有答案