无法使用php将我的选项值发布到电子邮件

时间:2012-03-22 23:59:06

标签: php select

大家好我似乎无法让这个工作......

这是html

<form id="quotesform" method="POST" action="quotes.php">
Name:
<input type="text" name="name"><br>
<br>
E-Mail:
<input type="text" name="email" size="19"><br>
<br>
Contact Number:
<input type="text" name="number" size="19"><br>
<br>

<label>What type of website?</label>
<select id="websitetype" name="websitetype">
<option value="1">Simple brochure website</option>
<option value="2">ecommerce/shopping website</option>
<option value="3">CMS website</option>
<option value="4">other</option>
</select><br /><br />

<label>How many pages?</label>
<select id="webpages" name="webpages">
<option value="1">1</option>
<option value="2">2-5</option>
<option value="3">5-10</option>
<option value="4">10-20</option>
<option value="5">20+</option>
</select><br /><br />

Brief description of your project<br>
<textarea rows="9" name="message" cols="30"></textarea><br>
<br>
<input type="submit" value="Submit" name="submit">

</form>

继承人的PHP

$emailSubject = 'quoteformprocess!'; 
$webMaster = 'admin@wheretogetawebsite.co.uk';


$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$websitetype = array(1 => "brochure", 2 => "ecommerce", 3=>"cms", 4=>"other");
$websitetype = $agents[(int) $_POST['agents']];
$webpages = array(1 => "1", 2 => "2-5", 3=>"5-10", 4=>"10-20", 5=>"20+");
$webpages = $webpages[(int) $_POST['webpages']];



$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Number: $number <br>
Websitetype: $websitetype <br>
Webpages: $Webpages <br>


EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);


/* Results rendered as HTML */
$theResults = <<<EOD
<html>
<head>
<title>sent message</title>
<meta http-equiv="refresh" content="3;URL=http://www.wheretogetawebsite.co.uk">
<style type="text/css">
<!--
body {
background-color: #444; /* You can edit this CSS to match your website*/
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #fec001;
text-decoration: none;
padding-top: 200px;
margin-left: 150px;
width: 800px;
}
-->
</style>
</head>
<div align="center">Put your message in here letting the sender know the message has      been successfully sent</div>
</div>
</body>
</html>
EOD;
echo "$theResults";
?>

这是电子邮件的样子

姓名:加里 电子邮件:garyjr25@hotmail.co.uk 人数:123 Websitetype: 网页:

我确定答案很简单,但我不熟悉php,似乎无法理解它,感谢任何帮助,非常感谢

4 个答案:

答案 0 :(得分:2)

这是你想要的吗

$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$agents = array(1 => "brochure", 2 => "ecommerce", 3=>"cms", 4=>"other");
$websitetype = $agents[(int) $_POST['websitetype']];
$webpages = array(1 => "1", 2 => "2-5", 3=>"5-10", 4=>"10-20", 5=>"20+");
$webpages = $webpages[(int) $_POST['webpages']];

当我认为你想要websitetype

时,你在POST数组中使用了agents

答案 1 :(得分:1)

$websitetype = $agents[(int) $_POST['agents']];

应该是

$websitetype = $websitetype[(int) $_POST['websitetype']];

看起来你只是忘了从旧版本或其他东西改变它。而且,PHP变量区分大小写,所以

Webpages: $Webpages <br>

应该是

Webpages: $webpages <br>

答案 2 :(得分:0)

1)这里有一个拼写错误(?):

$websitetype = array(1 => "brochure", 2 => "ecommerce", 3=>"cms", 4=>"other");
$websitetype = $agents[(int) $_POST['agents']];
  • 显然你想要...... $websitetype[$_POST['websitetype']];

2)这里有另一个错字:

$Webpages(打印var时)

  • 将其替换为$webpages(所有小写 - 没有首都首字母)

干杯; - )

答案 3 :(得分:0)

看起来像websitetype和代理混在一起。

PHP变量名称区分大小写,所以$ Webpages不是$ webpages。