当我提交表单时,电子邮件中的所有字段都是空白的,我无法弄清楚原因。它开始于获取未写入的变量的php错误,然后在此处搜索后我找到了一个解决方案来添加“isset”并将变量启动到空白字符串。我在错误日志中没有任何内容,但是当表单发送到电子邮件时,所有细节都是空白的。
这是我的HTML表单代码:
<form action="dish-business.php">
<div class="col-md-4">
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="businessname" class="sr-only control-label">Business Name</label>
<input name="businessname" id="businessname" type="text" placeholder="Business Name*" required="" data-validation-required-message="Please enter your business name" class="form-control input-lg"><span class="help-block text-danger"></span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="name" class="sr-only control-label">Name*</label>
<input name="name" id="name" type="text" placeholder="Full Name*" required="" data-validation-required-message="Please enter your full name" class="form-control input-lg"><span class="help-block text-danger"></span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="phone" class="sr-only control-label">Phone*</label>
<input name="phone" id="phone" type="tel" placeholder="Phone*" required="" data-validation-required-message="Please enter phone number" class="form-control input-lg"><span class="help-block text-danger"></span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="email" class="sr-only control-label">Email*</label>
<input name="email" id="email" type="email" placeholder="Email*" required="" data-validation-required-message="Please enter email" class="form-control input-lg"><span class="help-block text-danger"></span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="business" class="sr-only control-label">Type of Business</label>
<!-- <input id="business" type="text" placeholder="Type of Business" required="" data-validation-required-message="Please enter your type of business" class="form-control input-lg"><span class="help-block text-danger"></span> -->
<select name="business" class="form-control input-lg"><span class="help-block text-danger">
<option value="">Type of Business</option>
<option value="Airports">Airports</option>
<option value="Automotive">Automotive</option>
<option value="Banks" onclick="changeValue('Banks');">Banks</option>
<option value="Bar/Restaurant" onclick="changeValue('Bar/Restaurant');">Bar/Restaurant</option>
<option value="Beauty Services" onclick="changeValue('Beauty Services');">Beauty Services</option>
<option value="Church" onclick="changeValue('Church');">Church</option>
<option value="Firehouse/Oil Rig/EMT" onclick="changeValue('Firehouse/Oil Rig/EMT');">Firehouse/Oil Rig/EMT</option>
<option value="Golf Course" onclick="changeValue('Golf Course');">Golf Course</option>
<option value="Government" onclick="changeValue('Government');">Government</option>
<option value="Grocery/Health Food Store" onclick="changeValue('Grocery/Health Food Store');">Grocery/Health Food Store</option>
<option value="Hair salon" onclick="changeValue('Hair salon');">Hair salon</option>
<option value="Health/Fitness" onclick="changeValue('Health/Fitness');">Health/Fitness</option>
<option value="Health Care" onclick="changeValue('Health Care');">Health Care</option>
<option value="Liquor Store" onclick="changeValue('Liquor Store');">Liquor Store</option>
<option value="Lobbies" onclick="changeValue('Lobbies');">Lobbies</option>
<option value="Medical / Dental" onclick="changeValue('Medical / Dental');">Medical / Dental</option>
<option value="Nail Salon" onclick="changeValue('Nail Salon');">Nail Salon</option>
<option value="Office" onclick="changeValue('Office');">Office</option>
<option value="Private Club" onclick="changeValue('Private Club');">Private Club</option>
<option value="Professional Services" onclick="changeValue('Professional Services');">Professional Services</option>
<option value="Retail Store" onclick="changeValue('Retail Store');">Retail Store</option>
<option value="School" onclick="changeValue('School');">School</option>
<option value="Service Industry" onclick="changeValue('Service Industry');">Service Industry</option>
<option value="Sports Facilities" onclick="changeValue('Sports Facilities');">Sports Facilities</option>
<option value="Stadiums" onclick="changeValue('Stadiums');">Stadiums</option>
<option value="Other" onclick="changeValue('Other');">Other</option>
</select>
</div>
</div>
</div>
<div class="col-md-4">
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="locations" class="sr-only control-label">Locations*</label>
<input name="locations" id="locations" type="text" placeholder="Number of Locations*" required="" data-validation-required-message="Please enter the number of locations" class="form-control input-lg"><span class="help-block text-danger"></span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="units" class="sr-only control-label">Units*</label>
<input name="units" id="units" type="text" placeholder="Number of Units*" required="" data-validation-required-message="Please enter the number of units" class="form-control input-lg"><span class="help-block text-danger"></span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="dishcustomer" class="sr-only control-label">Are you a dish customer</label>
<!-- <input id="business" type="text" placeholder="Type of Business" required="" data-validation-required-message="Please enter your type of business" class="form-control input-lg"><span class="help-block text-danger"></span> -->
<select name="dishcustomer" class="form-control input-lg"><span class="help-block text-danger">
<option value="">Are you a current DISH Customer?</option>
<option value="yes">Yes</option>
<option value="no">No</option>
<option value="idk">Don't Know</option>
</select>
</div>
</div>
</div>
<div class="col-md-4">
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="zip" class="sr-only control-label">Zip Code</label>
<input name="zip" id="zip" type="text" placeholder="Business Zip Code*" required="" data-validation-required-message="Please enter your business zip code" class="form-control input-lg"><span class="help-block text-danger"></span>
</div>
</div>
</div>
<div class="col-md-12">
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label for="message" class="sr-only control-label">Details</label>
<textarea name="message" id="message" rows="2" placeholder="Any Other Details" class="form-control input-lg"></textarea><span class="help-block text-danger"></span>
</div>
</div>
<div id="success"></div>
<button type="submit" class="btn btn-dark btn-lg text-center">Send</button>
</div>
</form>
这是我的PHP代码:
<?php
$EmailFrom = "mail@.com";
$EmailTo = "@gmail.com";
$Subject = "Mail";
$Name = "";
$Businessname="";
$Tel="";
$Email="";
$Business="";
$Locations="";
$Units="";
$DishCustomer="";
$Zip="";
$Message="";
if (isset($_POST['businessname'])) {
$BusinessName = Trim(stripslashes($_POST['businessname']));
}
if (isset($_POST['name'])) {
$Name = Trim(stripslashes($_POST['name']));
}
if (isset($_POST['phone'])) {
$Tel = Trim(stripslashes($_POST['phone']));
}
if (isset($_POST['email'])) {
$Email = Trim(stripslashes($_POST['email']));
}
if (isset($_POST['business'])) {
$Business = Trim(stripslashes($_POST['business']));
}
if (isset($_POST['locations'])) {
$Locations = Trim(stripslashes($_POST['locations']));
}
if (isset($_POST['units'])) {
$Units = Trim(stripslashes($_POST['units']));
}
if (isset($_POST['dishcustomer'])) {
$DishCustomer = Trim(stripslashes($_POST['dishcustomer']));
}
if (isset($_POST['zip'])) {
$Zip = Trim(stripslashes($_POST['zip']));
}
if (isset($_POST['message'])) {
$Message = Trim(stripslashes($_POST['message']));
}
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=404.html\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Business: ";
$Body .= $Business;
$Body .= "\n";
$Body .= "Number of Locations: ";
$Body .= $Locations;
$Body .= "\n";
$Body .= "Units: ";
$Body .= $Units;
$Body .= "\n";
$Body .= "Currently a Dish Customer: ";
$Body .= $DishCustomer;
$Body .= "\n";
$Body .= "Zip Code: ";
$Body .= $Zip;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=thank-you.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=404.html\">";
}
?>
任何帮助都将不胜感激。谢谢。
答案 0 :(得分:1)
表单默认为method="GET"
。将表单更改为:
<form action="dish-business.php" method="POST">