我开发了此代码,用于在填写联系表单后发送联系信息。但是,它仍然无法正常工作。它不断显示消息" Not Ok"。我无法找出错误。请指导我使这段代码可行。
抱歉,我还没有添加任何php代码 - 请在下面查看现在更新的一个。
<?php
if(isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['email']) && isset($_POST['message'])){
if(!empty($_POST['fname'])&& !empty($_POST['lname']) && !empty($_POST['email']) && !empty($_POST['message'])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$message = $_POST['message'];
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo 'Kindly proivde valid email id';
}else{
$body = $fname."\n".$lname."\n".$email."\n".$message;
if(mail('example@mail.com','Website Response',$body,'From: response@self.com')){
echo 'Thanks for contacting us.';
} else {
echo "Error Occured in sending mail";
}
}
} else{
echo 'All fields are mandatory';
}
} else{
echo 'Not ok';
}
?>
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text], input[type=email], textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 16px;
resize: vertical;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
</style>
</head>
<body>
<h3>Contact Form</h3>
<div class="container">
<form action="" method="POST">
<label for="fname">First Name</label>
<input type="text" id="fname" name="firstname" placeholder="Your name..">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lastname" placeholder="Your last name..">
<label for="email">Email</label>
<input type="email" id="email" name="emailid" placeholder="example@company.com">
</br>
<label for="message">Description</label>
<textarea id="message" name="subject" rows="6" cols="30" placeholder="Write something.." style="height:200px"></textarea>
<input type="submit" value="Submit Details">
</form>
</div>
</body>
</html>
答案 0 :(得分:0)
你需要改变:
<form action="your_name.php" method="POST">
并创建文件&#34; your_name.php&#34;,您可以在其中发布表单中的所有参数。 例如:
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$emailid = $_POST['emailid'];
$subject = $_POST['subject'];
如果要将信息发送到已检查的电子邮件,则必须使用函数mail() http://php.net/manual/ru/function.mail.php