由于一些奇怪的原因,商业输入值不会提交给电子邮件......它总是空白的......有人可以告诉我什么是错的吗?谢谢!
<?php
// Check for empty fields
if(isset(empty($_POST['submit']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['business']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$business = strip_tags(htmlspecialchars($_POST['business']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = 'somekoreanguy@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nBusiness: $business\n\nMessage:\n$message";
$headers = "From: noreply@yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
这是我的HTML:
<form name="sentMessage" id="contactForm" novalidate method="post">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Business Name *" id="business" required data-validation-required-message="Please enter your business name.">
<p class="help-block text-danger"></p>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" name="submit" class="btn btn-xl">Send Message</button>
</div>
</div>
</form>
出于某种原因,当我把那个&#34;空($ _ POST [&#39; business&#39;])||&#34;在那里,没有任何东西进入电子邮件。当我删除&#34;键入=&#34; text&#34;从我的业务html部分,电子邮件通过但没有任何作为价值。它只会说商业:空白....
答案 0 :(得分:0)
您没有定义method="post"
<form name="sentMessage" id="contactForm" novalidate>
所以它就像
<form name="sentMessage" id="contactForm" novalidate method="post">
给出
的名称 <button type="submit" name ="submit" class="btn btn-xl">Send Message</button>
所以你的代码将是
if(isset($_POST['submit']){
//set your code here
}
答案 1 :(得分:0)
它总是空白的,因为输入表单中没有name=""
,name=""
在提交表单后引用表单数据。像这样添加name=""
到你的输入..
<?php
// Check for empty fields
if(isset($_POST['submit'])) {
if(trim($_POST['email'])== '' || trim($_POST['phone'])== '' || trim($_POST['business'])== '' || trim($_POST['message'])== '' || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
}else{
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$business = strip_tags(htmlspecialchars($_POST['business']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = 'somekoreanguy@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nBusiness: $business\n\nMessage:\n$message";
$headers = "From: noreply@yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
}
}
?>
<html>
<head>
</head>
<body>
<form name="contactForm" novalidate method="POST">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" name="name" id="name" data-validation-required-message="Please enter your name." required>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" name="email" id="email" data-validation-required-message="Please enter your email address." required>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" name="phone" id="phone" data-validation-required-message="Please enter your phone number." required>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Business Name *" name="business" id="business" data-validation-required-message="Please enter your business name." required>
<p class="help-block text-danger"></p>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" name="message" id="message" data-validation-required-message="Please enter a message." required></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div name="success"></div>
<button type="submit" name ="submit" class="btn btn-xl">Send Message</button>
</form>
</body>
</html>