0

I have been at this for hours and I cant determine why my PHP email form is not working. I have set up if-then check for each form field since all fields are optional at this point in time. I have checked everything I can think of.

<?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
}
?>
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
JRulle
  • 7,448
  • 6
  • 39
  • 61
  • In general it's not recommended to use `mail()` directly - once you get into multipart and attachments, it gets messy quickly. Consider using a library like SwiftMailer. – halfer Jan 07 '13 at 14:55

2 Answers2

2

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

Should be:

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

Remove the @ and see if there are any errors.

Also keep in mind that the mail() function does not have support for SMTP. You may have to check your settings. Could be another issue.

SeanWM
  • 16,789
  • 7
  • 51
  • 83
  • Additional to the answer: The `@` symbol in front of a function silences it. Meaning, you won't get any types of error messages when executing it, even if it fails. So I also suggest: **don't use it**. – Peon Jan 07 '13 at 14:56
  • Maybe [this](http://stackoverflow.com/questions/6093976/setting-smtp-details-for-php-mail-function) post can help you out there. – SeanWM Jan 07 '13 at 15:08
0

I figured out the issue...

Line 2:

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

contains a reference to "email" which is a field that no longer exits in the form.

Thank you all for your help and at least I learned something (what the @ symbol does in PHP).

JRulle
  • 7,448
  • 6
  • 39
  • 61