PHP联系表格帮助


PHP Contact Form Assistance

当涉及到HTML和PHP时,我有点像个傻瓜。无论如何,我制作了一个html表单,然后从网上获得了一个PHP邮件脚本,并编辑了PHP代码,使其与我的html相匹配。这个表格确实有效,它会给我发电子邮件。问题是,填写的表格中的一些内容在发送给我的电子邮件中显示为空。在下面的代码中,你可以看到我的表格是:

  • 名称
  • 地址
  • 电话
  • 电子邮件
  • 住宅(3个单选按钮,有三种不同选项)
  • 适用文本字段

当填写并提交完整的表格时,当我收到电子邮件时,我得到的只是姓名和电话。

这是代码:

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 

您的单选按钮应该具有相同的名称,除非您希望允许它们同时选择这三个按钮。

也试试这个

$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}";

我测试了表单,所有的值都通过了。

$_POST键的大小写与代码中的大小写不同。

也就是说,在帖子中,它显示为电子邮件,但您访问它时使用的是$_post['Email'],而不是$_post[Eemail']

然而,这与您在原始问题中发布的html代码不匹配。你确定问题中的html代码与你正在运行的代码相同吗?

[评论中打印不好的更新:]根据您打印的结果,您的php代码应该是这样的:

//Cusomer Name
$name = $_POST['name'];
//Address
$address = $_POST['Address'];
//Phone
$phone = $_POST['phone'];
//Email
$email = $_POST['Email'];
//Applicable 
$applicable = $_POST['Applicable'];