2013-01-07 126 views
0

我一直在這個小時,我無法確定爲什麼我的PHP電子郵件表格不工作。 我已經設置了if,然後檢查每個表單字段,因爲在這個時間點所有字段都是可選的。我已經檢查了我能想到的一切。PHP電子郵件不起作用

<?php 
if(isset($_POST['email'])) { 

    // EDIT THE 2 LINES BELOW AS REQUIRED 
    $email_to = "[email protected]"; 
    $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

通常不建議直接使用mail() - 一旦進入多部分和附件,它會很快變得雜亂無章。考慮使用像SwiftMailer這樣的庫。 – halfer

回答

2

@mail($email_to, $email_subject, $email_message, $headers);

應該是:

mail($email_to, $email_subject, $email_message, $headers);

取出@,看看是否有任何錯誤。請注意0​​函數不支持SMTP。您可能需要檢查您的設置。可能是另一個問題。

+0

附加答案:函數前面的「@」符號使其靜音。這意味着,即使執行失敗,也不會收到任何類型的錯誤消息。所以我也建議:**不要使用它**。 – Peon

+0

也許[這](http://stackoverflow.com/questions/6093976/setting-smtp-details-for-php-mail-function)發佈可以幫助你。 – SeanWM

0

我想通了這個問題...

線路2:

if(isset($_POST['email'])) { 

包含提到「郵件」,這是在形式不再離開現場。

謝謝大家的幫助,至少我學到了一些東西(@符號在PHP中做了什麼)。

+0

這樣做。很高興你想出來了。 – SeanWM