2013-10-24 39 views
1

我遇到了一個與我創建的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 = "[email protected]"; 
$subject = "url.net - Website Contact"; 
$from = "[email protected]"; 
$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

您的形式缺少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 
+1

此外,在這裏看到:http://stackoverflow.com/questions/17304420/adding-checkboxes-to-php-post-email-form –

+0

@DanielDawes感謝,這將是下一個問題OP跑進確定方法後。加入回答:) – MrCode