0

我创建了一个使用 php 邮件脚本提交的 HTML 表单。我遇到的问题是表单每天提交一次完全空白,每天正好一小时后提交。我完全被卡住了,我希望有人可以帮助发现我的问题。

我正在粘贴下面的代码,请注意:html 表单的结束位置在使用 Adob​​e CQ5 的站点的页面内,php 脚本位于单独的服务器上,我已删除所有验证以检查是否是问题(不是 - 无论有没有我的验证码,它仍然提交空白)。

HTML 表单代码:

<font size="2"><strong>* Required</strong></font><P><BR><form name="form1" action="http://mtindustrialservicerequest.com/phpFiles/send_form_email_ci-vision.php"  method="post">
<p><strong>Lead Submitted by: </strong><br/>
*Name: <input name="submit_name" type="text" id="submit_name" size="40"><br/>
*Company Name: <input name="companyName" type="text" id="CompanyName" size="40"><br/>
*City: <input name="companyCity" type="text" id="CompanyCity" size="25"> 
*State: <input name="companyState" type="text" id="CompanyState" size="15"></p>
<BR>
<p>Purchase Timeframe: <select name="timeframe" id="Timeframe">
<option value="0 - 6 months">0 - 6 months</option>
<option value="7 - 12 months">7 - 12 months</option>
</select>
</p>
<BR>
<p>
<strong>Customer Interest: </strong><br/>
<input type="checkbox" name="Product" value="Yes">Product<br/>
<input type="checkbox" name="Service" value="Yes">Service
</p>
<BR>
<p><strong>Customer Information: </strong><br/>
Application Details and Comments:<br/>
<textarea name="CustomerApplication" cols="55" rows="5" id="Customer Application"></textarea><br/>
<select name="Salutation" id="Salutation">
<option value="Mr">Mr.</option>
<option value="Ms">Ms.</option>
<option value="Mrs">Mrs.</option>
</select>
*First Name: <input name="CustomerFirstName" type="text" id="CustomerFirstName" size="25"> 
*Last Name: <input name="CustomerLastName" type="text" id="CustomerLastName" size="25"><BR>
Email: <input name="CustomerEmail" type="text" id="CustomerEmail" size="40"><br/>
*Phone Number: <input name="CustomerPhone" type="text" id="CustomerPhone" size="20"> 
Fax Number: <input name="CustomerFax" type="text" id="CustomerFax" size="20"><br/>
Job Title: <input name="CustomerJobTitle" type="text" id="CustomerJobTitle" size="40"><br/>
*Company Name: <input name="CustomerCompanyName" type="text" id="CustomerCompanyName" size="30"> 
Department: <input name="CustomerDepartment" type="text" id="CustomerDepartment" size="25"><br/>
*Address: <input name="CustomerStreet" type="text" id="CustomerStreet" size="50"> <BR>
*City: <input name="CustomerCity" type="text" id="CustomerCity" size="25"> 
*State: <input name="CustomerState" type="text" id="CustomerState" size="15"> 
*Postal Code: <input name="CustomerPostalCode" type="text" id="CustomerPostalCode" size="10"><br/>
Country: <input name="CustomerCountry" type="text" id="CustomerCountry" size="12"><br/>
</p>

<p>
Contact Workplace:<select name="BusinessType" id"BusinessType">
<option value="--------">--- Select One ---</option>
<option value="Research and Development">Research and Development</option>
<option value="Engineering, Process Development and Scale-Up">Engineering, Process Development and Scale-Up</option>
<option value="General Laboratory, Inspection and Quality Control">General Laboratory, Inspection and Quality Control</option>
<option value="Receiving and Warehousing">Receiving and Warehousing</option>
<option value="Production and Processing">Production and Processing</option>
<option value="Packaging and Filling">Packaging and Filling</option>
<option value="Logistics, Shipping and Mail">Logistics, Shipping and Mail</option>
<option value="Maintenance and Service">Maintenance and Service</option>
<option value="Information Technology">Information Technology</option>
<option value="Retail">Retail</option>
<option value="Water, Power and facility Utilities">Water, Power and Facility Utilities</option>
<option value="Procurement, Finance and Administration">Procurement, Finance and Administration</option>
<option value="Dealers and Distributors">Dealers and Distributors</option>
<option value="Other">Other</option>
</select><br/>
Industry:<select name="industryType" id"IndustryType">
<option value="--------">--- Select One ---</option>
<option value="Chemical">Chemical</option>
<option value="Pharma and Biotechnology">Pharma and Biotechnology</option>
<option value="Food and Beverage">Food and Beverage</option>
<option value="Academia and Education">Academia and Education</option>
<option value="Testing Labs and Health Institutes">Testing Labs and Health Institutes</option>
<option value="Metal, Plastics and Electronics Components">Metal, Plastics and Electronics Components</option>
<option value="Raw Materials and Jewelry">Raw Materials and Jewelry</option>
<option value="Pulp, Paper and Textile">Pulp, Paper and Textile</option>
<option value="Engineering, Machinery and Equipment Manufacturing">Engineering, Machinery and Equipment Manufacturing</option>
<option value="Transport and Logistics">Transport and Logistics</option>
<option value="Utilities and Municipalities">Utilities and Municipalities</option>
<option value="Retail">Retail</option>
</select><br/>
Number of Employees:<select name="Employees" id"Employees">
<option value="--------">--- Select One ---</option>
<option value="Between 1 and 50">Between 1 and 50</option>
<option value="Between 50 and 200">Between 50 and 200</option>
<option value="Between 200 and 500">Between 200 and 500</option>
<option value="Between 500 and 1000">Between 500 and 1000</option>
<option value="1000 or more">1000 or more</option>
</select>
</p>

<p><input type="submit" name="Submit" value=" Submit "></p>
</form>

PHP 脚本:

<?php

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "PI.Marketing@mt.com";
    $email_subject = "New CI-Vision Lead!  PI/IND Lead Sharing Program";

    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['Product'])){$product = " ";}
    else{$product = $_POST['Product'];}

    if(!isset($_POST['Service'])){$service = " ";}
    else{$service = $_POST['Service'];}


    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 = "Please enter lead below.\n\n";

    $email_message .= "Lead Submitted By: $submit_name\n";
    $email_message .= "Company Name: $companyName\n";
    $email_message .= "City: $companyCity\n";
    $email_message .= "State: $companyState\n\n";

    $email_message .= "Purchase Timeframe: $timeframe\n\n";

    $email_message .= "Product Interest: $product\n";
    $email_message .= "Service Interest: $service\n";

    $email_message .= "Customer Information:\nCustomer Application Details and Comments: $customerApplication\n";
    $email_message .= "Salutation: $salutation\n";
    $email_message .= "First Name: $customerFirstName\n";
    $email_message .= "Last Name: $customerLastName\n";    
    $email_message .= "Email: $customerEmail\n";
    $email_message .= "Phone: $customerPhone\n";
    $email_message .= "Fax: $customerFax\n";
    $email_message .= "Job Title: $customerJobTitle\n";
    $email_message .= "Company: $customerCompanyName\n";
    $email_message .= "Department: $customerDepartment\n";
    $email_message .= "Address:\nStreet: $customerStreet\n";
    $email_message .= "City: $customerCity\n";
    $email_message .= "State: $customerState\n";
    $email_message .= "Postal Code: $customerPostalCode\n";
    $email_message .= "Country: $customerCountry\n\n";

    $email_message .= "Contact Workplace: $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

1 回答 1

0

您已将一些字段标记为必填项,但并未检查它们是否已实际填写。例如submit_name,您已将其标记为必填项 (*Name),但在发布表单时,您执行以下操作:

if(!isset($_POST['submit_name'])){$submit_name = " ";}
else{$submit_name = $_POST['submit_name'];}

这段代码实际上给了它一个值" ",即使它没有提供。我想您想要做的是防止在未提供时提交。

//do this check for every required variable
if (empty($_POST['submit_name']) or empty($_POST['companyName']) or empty($_POST['companyLocation']) or empty($_POST['companyCity'])) {
  echo 'Not all required fields are set';

  //now there are several options. You can just end the page using exit and then the user needs to use his backbutton to get back to the form
  //exit();


  //another option is to send him back yourself
  //header('location: /form.html');
  //exit();
}

//the submit code you have to send the mail

边注:

isset即使发布了变量,您正在使用which 也会返回 true,但没有任何值。也许您想检查字符串empty()以确保它们也包含某些内容。但是empty()当你期望一个也可以是 0 的数字时不要使用。

于 2013-05-07T13:23:53.250 回答