联系表格不拉值

时间:2013-10-24 15:04:27

标签: php forms contact-form

我正在创建我正在创建的php联系表单的问题。表单成功提交,但是当电子邮件通过时,它不会显示任何选定的值。以下是我的代码。

非常感谢任何帮助!!

PHP:

    <?php
/* Include PHPMailer Class */
require("class.phpmailer.php");

if (isset($_POST['inflatable'])) {
    $inflatable = $_POST['inflatable'];
    // $service is an array of selected values
}

if (isset($_POST['supplies'])) {
    $supplies = $_POST['supplies'];
    // $service is an array of selected values
}

$to = "me@me.com";
$subject = "url.net - Website Contact";
$from = "info@url.net";
$fromName = "url.net";
$name = $_POST["name"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$address = $_POST["address"];
$time = $_POST["time"];
$date = $_POST["date"];
$event = $_POST["event"];
$comments = $_POST["comments"];


$bodyHTML = "<b>Name:</b> " . $name .  "<br><b>Phone:</b> " . $phone . "<br><b>Email:</b> " . $email . "<br><b>Address of Event: </b>" . $address . "<br><b>Time of Event: </b>" . $time . "<br><b>Date: </b>" . $date . "<br><b>Selected Package: </b>" . $event . "<br><b>Selected Inflatables: </b>" . implode(", " ,$inflatable) . "<br><b>Additional Supplies: </b>" . implode(", " ,$supplies). "<br><b>Comments: </b>" . nl2br(stripslashes($comments));

$bodyPlain = "Name: " . $name . "\nPhone: " . $phone . "\nEmail: " . $email . "\nAddress: " . $address . "\nTime of Event: " . $time . "\nDate of Event: " . $date . "\nSelected Package: " . $event . "\nSelected Inflatable: " . implode(", " ,$inflatable) . "\nAdditional Supplies: " . implode(", " ,$supplies) . "\nComments: " . nl2br(stripslashes($comments));

/* - and email it - */
$mail = new PHPMailer();
$mail->From = $from;
$mail->FromName = $fromName;
$mail->AddAddress($to); // The email to be sent to..
$mail->Subject = $subject;
$mail->IsHTML(true); // This tell's the PhPMailer that the messages uses HTML.
$mail->Body = $bodyHTML;
$mail->AltBody = $bodyPlain;
if(!$mail->Send()) // Now we send the email and check if it was send or not.
{

   header('Location: ../error.html');
}
else
{
   header('Location: ../thankyou.html');
}



?>

HTML:

<form class="contact" action="php/contactus.php">
    <h2>Party Reservation Form</h2>
    <div id="info" align="left">
      Full name: <input type="text" name="name">
      <br>
      Phone number: <input type="text" name="phone">
      <br>
      Email address: <input type="text" name="email">
      <br>
      Address of event: <input type="text" name="address">
      <br>
      Time of event: <input type="text" name="time">
      <br>
      Date of event: <input type="text" maxlength="10" name="date" placeholder="mm/dd/yyyy">
      <br>
      Event Package: <select name="event">
        <option value="None" selected>None</option>
        <option value="Package 1: Nice and Easy">Package 1: Nice and Easy</option>
        <option value="Package 2: All in One">Package 2: All in One</option>
        <option value="Package 3: Bring On The Fun">Package 3: Bring On The Fun</option>
        <option value="Package 4: The More The Marrier">Package 4: The More The Marrier</option>
      </select></div><div class="clear"></div>
      <br><div id="checkwrap1"><p style="font-weight:bold;">Desired Inflatable(s):</p>
      <div id="check">
        <input type="checkbox" name="inflatable" value="Castle Bouncer">
        Castle Bouncer<br>
        <input type="checkbox" name="inflatable" value="Hello Kitty Bouncer">
        Hello Kitty Bouncer<br>
        <input type="checkbox" name="inflatable" value="Disney Princess Bouncer">
        Disney Princess Bouncer<br>
        <input type="checkbox" name="inflatable" value="Its a Girl Thing Bouncer">
        It's a Girl Thing<br>
        <input type="checkbox" name="inflatable" value="Dora-Diego Bouncer">
        Dora-Diego Bouncer<br>
        <input type="checkbox" name="inflatable" value="Sponge Bob Bouncer">
        Sponge Bob</div>
      <div id="check">
        <input type="checkbox" name="inflatable" value="Batman Bouncer">
        Batman Bouncer<br>
        <input type="checkbox" name="inflatable" value="Stock Race Cars">
        Stock Race Cars<br>
        <input type="checkbox" name="inflatable" value="Plain Bouncer">
        Plain Bouncer<br>
        <input type="checkbox" name="inflatable" value="30ft Obstacle Course">
        30 ft Obstacle Course<br>
        <input type="checkbox" name="inflatable" value="Castle Combo (wet or dry)">
        Castle Combo (wet or dry)<br>
        <input type="checkbox" name="inflatable" value="Tropical Combo (wet or dry)">
        Tropical Combo (wet or dry)</div>
      <div id="check">
        <input type="checkbox" name="inflatable" value="16ft rainbow (wet only)">
        16ft Rainbow (wet only)<br>
        <input type="checkbox" name="inflatable" value="18ft Rajun Cajun (wet or dry)">
        18ft Rajun Cajun (wet or dry)<br>
        <input type="checkbox" name="inflatable" value="20ft Fire &amp; Ice (wet only)">
        20ft Fire &amp; Ice (wet only)<br>
        <input type="checkbox" name="inflatable" value="Dunk Tank (wet only)">
        Dunk Tank (wet only)</div></div>
        <div class="clear"></div>
        <div id="checkwrap2">
      <p style="font-weight:bold;">Desired Party Supplies:</p>
      <div id="check">
        <input type="checkbox" name="supplies" value="Cotton Candy Machine">
        Cotton Candy Machine<br>
        <input type="checkbox" name="supplies" value="Snow Cone Machine">
        Snow Cone Machine<br>
        <input type="checkbox" name="supplies" value="Pop Corn Machine">
        Pop Corn Machine
      </div>
      <div id="check">
        <input type="checkbox" name="supplies" value="Add Tables">
        Add Tables<br>
        <input type="checkbox" name="supplies" value="Add Chairs">
        Add Chairs<br>
        <input type="checkbox" name="supplies" value="Add Facepainting">
        Add Face Painting
        </div>
      <div id="check">
        <input type="checkbox" name="supplies" value="Add Glitter Tattoos">
        Add Glitter Tattoos<br>
        <input type="checkbox" name="supplies" value="Add Games Package">
        Add Games Package</div></div>
        <div class="clear"></div>
      <textarea placeholder="Additional Comments" name="comments"></textarea>
      <br>
      <input type="submit" value="send message">
    </form>

1 个答案:

答案 0 :(得分:1)

您的表单缺少method属性,因此默认情况下会回退到GET。您的PHP代码正在查找$_POST变量,只有在表单具有POST方法时才会出现这些变量。

更改为:

<form class="contact" action="php/contactus.php" method="post">

另外,正如@Daniel在评论中指出的那样,您需要更改复选框名称以使用[]后缀,以便PHP将它们转换为数组。

<input type="checkbox" name="inflatable[]" value="Batman Bouncer">
                                       ^^ here