嘿我对php很新,但是我试图通过视频教程制作一个电子邮件联系表单,我收到一条错误说
“警告:mail():SMTP服务器响应:530 5.7.0必须首先发出STARTTLS命令。在第83行的C:\ xampp \ htdocs \ ContactForm \ form_process.php中输出gsmtp”。
必须首先发出STARTTLS命令,我不知道这是什么,也不知道怎么做。我联系了我的ISP并获得了SMTP地址(mail.mymts.net)和端口#(587),我已经发送了sendmail_from的电子邮件,(anexample@gmail.com),但我不明白为什么这样做需要sendemail_from,因为它不会从电子邮件文本框中的任何电子邮件发送?这是否需要与$地址相同?这个STARTTLS命令只需要本地主机,还是我需要它的版本才能实际从某个地方托管网站?对不起,我有很多问题,我只是非常困难,不知道该怎么做,如果有人卖给我写什么来解决这个问题,我会很感激。我已经包含了我的2个php文件。这是我需要修复的最后一件事才能使我的网站上线,直到我在本地测试它才能做到这一点。
Index.PHP(表格):
<!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()">×</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">☰ </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;
}