我正在创建的 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 & Ice (wet only)">
20ft Fire & 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>