在HTML和PHP方面,我有点像菜鸟。无论如何,我做了一个html表单,然后我从网上获得了一个PHP邮件脚本并编辑了PHP代码,以便它与我的HTML匹配。表单实际上有效,它会向我发送电子邮件。问题是,填写的表单中的某些内容在发送给我的电子邮件中显示为空。在下面的代码中,您可以看到我的表单是:
当填写并提交整个表格时,当我收到电子邮件时,我得到的就是姓名和电话。
下面是代码:
HTML
<!DOCTYPE HTML>
<html>
<head>
<title>SpaceCommand - Order Now</title>
<link rel="icon" type="image/png" href="http://cdn.directv.com/images/common/favicon.ico">
<link rel="stylesheet" type="text/css" href="ostyle.css" />
</head>
<body>
<div id="top"></div>
<div id="st"><img src="dimages/nflst.png" width="1021" height="550"/></div>
<div id="Every">Every Sunday. Every Game.</div>
<div id="tbox"></div>
<div id="tbox_2"></div>
<div id="Every_2">NFL SUNDAY TICKET included</div>
<div id="Every_3">at no extra charge!</div>
<div id="Every_4">Only on DIRECTV.</div>
<div id="logo"><img src="dimages/logof.png" width="400" height="51" /></div>
<div id="stylized" class="myform">
<form id="form1" action="mail.php" method="POST">
<label>Name
<span class="small">Add your name</span>
</label>
<input type="text" name="name">
<label>Address
<span class="small">Enter your address</span>
</label>
<input type="text" name="address">
<label>Phone
<span class="small">Add a Phone Number</span>
</label>
<input type="text" name="phone">
<label>Email
<span class="small">Enter your email</span>
</label>
<input type="text" name="email">
<br />
<label>Residence:
</label>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div id="radio">
House<input type="radio" value="house" name="house">
</div>
<div id="radio2">
Condo<input type="radio" value="condo" name="condo">
</div>
<div id="radio3">
Apartment<input type="radio" value="apartment" name="apartment">
</div>
<br />
<br/>
<label>If apartment or condo, do you have roof availability or a balcony facing south?
<span class="small"><i>*if applicable</i></span>
</label>
<br />
<br />
<input type="text" name="applicable">
<br />
<br />
<br />
<br />
<button type="submit" value="Send" style="margin-top:15px;">Submit</button>
<div class="spacer"></div>
</div>
</form>
<div id="ont">
<img src="dpimages/ont.png" />
</div>
</body>
</html>
PHP
<?php
//Cusomer Name
$name = $_POST['name'];
//Address
$address = $_POST['address'];
//Phone
$phone = $_POST['phone'];
//Email
$email = $_POST['email'];
//Residence
$residence = $_POST['residence'];
//Residence Type
$house = $_POST['house'];
$condo = $_POST['condo'];
$apartment = $_POST['apartment'];
//Applicable
$applicable = $_POST['applicable'];
//Contetnt
$formcontent= "Customer Name: $name \n Address: $address \n Phone Number: $phone \n Email: $email \n Residence: $residence $house $condo $apartment \n Do they have roof access or a baclony facing south? (if applicable): $applicable";
$recipient = "gizmo@themvnt.com";
$subject = "DIRECTV Order - SpaceCommand";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You for contacting us. We'll get back to you as soon as possible." . " -" . "<a href='order.html' style='text-decoration:none;color:#ff0099;'> Return to SpaceCommand</a>";
?>
如果你们可以为我修复代码,那将非常感激。
编辑:var_dump($_POST)
结果。
Array ( [name] => Test Name
[Address] => Test Address
[phone] => Tes Phome
[Email] => Test Email
[call] => House
[Applicable] =>
Test ) Thank You for contacting us. We'll get back to you as soon as possible. - Return to SpaceCommand
答案 0 :(得分:0)
你的单选按钮应该有三个相同的名称,除非你想让他们同时选择这三个。
也试试这个
$formcontent= "Customer Name: {$name} \n Address: {$address} \n Phone Number: {$phone} \n Email: {$email} \n Residence: {$residence} $house {$condo} {$apartment} \n Do they have roof access or a baclony facing south? (if applicable): {$applicable}";
我测试了表单,所有值都正确传递。
答案 1 :(得分:-1)
$ _POST键中的大小写与代码中的大小写不同。
即。在帖子中它显示为电子邮件,但您正在访问它作为$ _POST ['email']而不是$ _POST ['电子邮件']
然而,这与您在原始问题中发布的html代码不匹配。您确定问题中的html代码与您正在运行的代码相同吗?
[更新在评论中打印不好:] 根据您打印的结果,您的PHP代码应如下所示:
//Cusomer Name
$name = $_POST['name'];
//Address
$address = $_POST['Address'];
//Phone
$phone = $_POST['phone'];
//Email
$email = $_POST['Email'];
//Applicable
$applicable = $_POST['Applicable'];