PHP联系表单只会发送一次

时间:2014-07-25 13:49:39

标签: php forms contact

首先,我不是网页设计师 - 我是平面设计师,所以我不是PHP专家。

这是我的问题:我有一个为网页构建的简单联系表单。此表单具有多个收件人,这些收件人基于在第一个表单选择中选择的主题。此表单正确显示在网站上,工作和发送 - 但仅限ONCE。在我将一个新的.php文件重新加载到我的服务器后,它只会发送一次。我去了不同的计算机,使用不同的IP,因为我读它可能是一个cookie问题(这不在我的代码中),仍然只发送一次。我已经研究过,我开始只看到相同的答案,所以我想我会问。我按照建议删除了不需要的空格,没有帮助。我尝试在提交按钮上添加一个虚假陈述(就像我说没有php专业人士,请原谅我的措辞),没有帮助。我已经将“From”更改为@mywebsite类型的条目,而不是像“网站用户”这样的内容,因为建议进行验证,没有运气。任何帮助将不胜感激。

我的PHP文件:

<?php
$name = $_POST['name'];
$yourEmail = $_POST['yourEmail'];
$businessName = $_POST['businessName'];
$businessType = $_POST['businessType'];
$address = $_POST['address'];
$city = $_POST['city'];
$stateProvince = $_POST['stateProvince'];
$country = $_POST['country'];
$zipPostalcode = $_POST['zipPostalcode'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$contactPref = $_POST['contactPref'];
$message = $_POST['message'];

switch ($sendTo)
{
case "aftermarketCustomerservice":
$sendTo="email1@ipa.net";
break;

case "technicalAssistance":
$sendTo="email2@ipa.net";
break;

case "aftermarketSales":
$sendTo="email3@ipa.net";
break;

case "performanceProducts":
$sendTo="email4@ipa.net";
break;

case "oemSales":
$sendTo="email5@ipa.net";
break;

case "exportSales":
$sendTo="email6@ipa.net";
break;

case "generalFeedback":
$sendTo="email7@ipa.net";
break;

default:
$sendTo="email8@ipa.net";
}

$subject="Website Contact Form";
$message="From: $name  \r \n Reply to: $yourEmail  \r \n Message: $message \r \n Business Name:         
$businessName \r \n Business Type: $businessType \r \n Address: $address, $city, $stateProvince, 
$zipPostalcode,$country \r \n Phone: $phone \r \n Fax: $fax \r \n Contact Preference: 
$contactPref ";

$send=mail($sendTo, $subject, $message, "From: websiteuser@website.com");

$todayis=date("l, F j, Y");
echo "Email succesfully sent to Company Name on $todayis";

?>

1 个答案:

答案 0 :(得分:0)

你应该做的是改变这些界限:

$send=mail($sendTo, $subject, $message, "From: websiteuser@website.com");

$todayis=date("l, F j, Y");
echo "Email succesfully sent to Company Name on $todayis";

成:

$send=mail($sendTo, $subject, $message, "From: websiteuser@website.com");

if ($send) {
  $todayis=date("l, F j, Y");
  echo "Email succesfully sent to Company Name on $todayis";
}
else {
  echo "Email couldn't be sent";
}

并告诉我们结果是什么。

你也可以改变:

<?php

<?php

ini_set('display_errors','1');
error_reporting(E_ALL);

确保不会出现任何其他错误。当然,当您的应用程序将在生产服务器上时,应该删除这两行显示错误。