我已经在这里工作了几个小时,我无法确定为什么我的PHP电子邮件表单不起作用。 我已经设置if-then检查每个表单字段,因为此时所有字段都是可选的。我已经检查了我能想到的一切。
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "jim.ulle@mt.com";
$email_subject = "IND Form";
if(!isset($_POST['submit_name'])){$submit_name = " ";}
else{$submit_name = $_POST['submit_name'];}
if(!isset($_POST['companyName'])){$companyName = " ";}
else{$companyName = $_POST['companyName'];}
if(!isset($_POST['companyLocation'])){$companyLocation = " ";}
else{$companyLocation = $_POST['companyLocation'];}
if(!isset($_POST['companyCity'])){$companyCity = " ";}
else{$companyCity = $_POST['companyCity'];}
if(!isset($_POST['companyState'])){$companyState = " ";}
else{$companyState = $_POST['companyState'];}
if(!isset($_POST['timeframe'])){$timeframe = " ";}
else{$timeframe = $_POST['timeframe'];}
if(!isset($_POST['BenchCountingScales'])){$benchCountingScales = " ";}
else{$benchCountingScales = $_POST['BenchCountingScales'];}
if(!isset($_POST['FloorScales'])){$floorScales = " ";}
else{$floorScales = $_POST['FloorScales'];}
if(!isset($_POST['WeighModulesLoadCells'])){$weighModulesLoadCells = " ";}
else{$weighModulesLoadCells = $_POST['WeighModulesLoadCells'];}
if(!isset($_POST['TruckRailScales'])){$truckRailScales = " ";}
else{$truckRailScales = $_POST['TruckRailScales'];}
if(!isset($_POST['SQCFormulationSoftwareSolutions'])){$SQCFormulationSoftwareSolutions = " ";}
else{$SQCFormulationSoftwareSolutions = $_POST['SQCFormulationSoftwareSolutions'];}
if(!isset($_POST['Other'])){$other = " ";}
else{$other = $_POST['Other'];}
if(!isset($_POST['PreventativeMaintenanceAgreement'])){$preventativeMaintenanceAgreement = " ";}
else{$preventativeMaintenanceAgreement = $_POST['PreventativeMaintenanceAgreement'];}
if(!isset($_POST['GWPVerification'])){$GWPVerification = " ";}
else{$GWPVerification = $_POST['GWPVerification'];}
if(!isset($_POST['Other2'])){$other2 = " ";}
else{$other2 = $_POST['Other2'];}
if(!isset($_POST['CustomerApplication'])){$customerApplication = " ";}
else{$customerApplication = $_POST['CustomerApplication'];}
if(!isset($_POST['Salutation'])){$salutation = " ";}
else{$salutation = $_POST['Salutation'];}
if(!isset($_POST['CustomerFirstName'])){$customerFirstName = " ";}
else{$customerFirstName = $_POST['CustomerFirstName'];}
if(!isset($_POST['CustomerLastName'])){$customerLastName = " ";}
else{$customerLastName = $_POST['CustomerLastName'];}
if(!isset($_POST['CustomerAcademicTitle'])){$customerAcademicTitle = " ";}
else{$customerAcademicTitle = $_POST['CustomerAcademicTitle'];}
if(!isset($_POST['CustomerEmail'])){$customerEmail = " ";}
else{$customerEmail = $_POST['CustomerEmail'];}
if(!isset($_POST['CustomerPhone'])){$customerPhone = " ";}
else{$customerPhone = $_POST['CustomerPhone'];}
if(!isset($_POST['CustomerFax'])){$customerFax = " ";}
else{$customerFax = $_POST['CustomerFax'];}
if(!isset($_POST['CustomerCompanyName'])){$customerCompanyName = " ";}
else{$customerCompanyName = $_POST['CustomerCompanyName'];}
if(!isset($_POST['CustomerDepartment'])){$customerDepartment = " ";}
else{$customerDepartment = $_POST['CustomerDepartment'];}
if(!isset($_POST['CustomerJobTitle'])){$customerJobTitle = " ";}
else{$customerJobTitle = $_POST['CustomerJobTitle'];}
if(!isset($_POST['CustomerStreet'])){$customerStreet = " ";}
else{$customerStreet = $_POST['CustomerStreet'];}
if(!isset($_POST['CustomerCountry'])){$customerCountry = " ";}
else{$customerCountry = $_POST['CustomerCountry'];}
if(!isset($_POST['CustomerCity'])){$customerCity = " ";}
else{$customerCity = $_POST['CustomerCity'];}
if(!isset($_POST['CustomerState'])){$customerState = " ";}
else{$customerState = $_POST['CustomerState'];}
if(!isset($_POST['CustomerPostalCode'])){$customerPostalCode = " ";}
else{$customerPostalCode = $_POST['CustomerPostalCode'];}
if(!isset($_POST['BusinessType'])){$businessType = " ";}
else{$businessType = $_POST['BusinessType'];}
if(!isset($_POST['industryType'])){$industryType = " ";}
else{$industryType = $_POST['industryType'];}
if(!isset($_POST['Employees'])){$semployees = " ";}
else{$employees = $_POST['Employees'];}
$email_message = "Form details below.\n\n";
$email_message .= "Lead Submitted By: $submit_name\n";
$email_message .= "Company Name: $companyName\n";
$email_message .= "Location: $companyLocation\n";
$email_message .= "City: $companyCity\n";
$email_message .= "State: $companyState\n\n";
$email_message .= "Purchase Timeframe: $timeframe\n\n";
$email_message .= "Product Interest:\nBench Counting Scales: $benchCountingScales\n";
$email_message .= "Floor Scales: $floorScales\n";
$email_message .= "Weigh Modules Load Cells: $weighModulesLoadCells\n";
$email_message .= "Truck Rail Scales: $truckRailScales\n";
$email_message .= "SQC Formulation Software Solutions: $SQCFormulationSoftwareSolutions\n";
$email_message .= "Other: $other\n";
$email_message .= "Service Interest:\nPreventative Maintenance Agreement: $preventativeMaintenanceAgreement\n";
$email_message .= "GWP Verification: $GWPVerification\n";
$email_message .= "Other: $other2\n\n";
$email_message .= "Customer Information:\nCustomer Application: $customerApplication\n";
$email_message .= "Salutation: $salutation\n";
$email_message .= "First Name: $customerFirstName\n";
$email_message .= "Last Name: $customerLastName\n";
$email_message .= "Academic Title: $customerAcademicTitle\n";
$email_message .= "Email: $customerEmail\n";
$email_message .= "Phone: $customerPhone\n";
$email_message .= "Fax: $customerFax\n";
$email_message .= "Company: $customerCompanyName\n";
$email_message .= "Department: $customerDepartment\n";
$email_message .= "Job Title: $customerJobTitle\n";
$email_message .= "Address:\nStreet: $customerStreet\n";
$email_message .= "Country: $customerCountry\n";
$email_message .= "City: $customerCity\n";
$email_message .= "State: $customerState\n";
$email_message .= "Postal Code: $customerPostalCode\n\n";
$email_message .= "Type of Business: $businessType\n";
$email_message .= "Industry: $industryType\n";
$email_message .= "Number of Employees: $employees\n\n";
// create email headers
$headers = 'From: '.$email_to."\r\n".
'Reply-To: '.$email_to."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for submitting.
<?php
}
?>
答案 0 :(得分:2)
@mail($email_to, $email_subject, $email_message, $headers);
应该是:
mail($email_to, $email_subject, $email_message, $headers);
删除@
并查看是否有任何错误。
另请注意,mail()
功能不支持SMTP。您可能需要检查您的设置。可能是另一个问题。
答案 1 :(得分:0)
我弄明白了这个问题......
第2行:
if(isset($_POST['email'])) {
包含对“email”的引用,该字段不再以表单形式退出。
谢谢大家的帮助,至少我学到了什么(@符号在PHP中的作用)。