0

私は何時間もこれに取り組んできましたが、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
}
?>
4

2 に答える 2

2

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

次のようにする必要があります。

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

を削除して@、エラーがないかどうかを確認します。

また、mail()関数は SMTP をサポートしていないことに注意してください。設定を確認する必要がある場合があります。別の問題かもしれません。

于 2013-01-07T14:53:24.943 に答える
0

私は問題を理解しました...

2行目:

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

フォームに存在しなくなったフィールドである「email」への参照が含まれています。

皆さんの助けに感謝します。少なくとも私は何かを学びました (@ 記号が PHP で何をするか)。

于 2013-01-07T15:18:19.720 に答える