我已经完成了之前的问题,但没有找到答案。
我想简单地从我的表格中发送信息,然后通过电子邮件发送给我。我的表格代码也是如此。
<form action="http://bikesnwines.com/html_form_send.php" method="post" name="form1"> <strong>Your Details:</strong>Full name:
<input type="text" maxlength="50" name="fullname" size="30" />
E-mail Address:
<input type="text" maxlength="50" name="email_from" size="30" />Date of Visit:
<input type="text" maxlength="50" name="date" size="30" />
<strong>Accomodation:</strong>
<a href="http://www.bikesnwines.com/wp-content/uploads/2013/07/val-du-charron- 12+-1.jpg"><img class="size-medium wp-image-1382 alignnone" alt="val-du-charron-12+ (1)" src="http://www.bikesnwines.com/wp-content/uploads/2013/07/val-du-charron-12+-1- 300x125.jpg" width="400" height="170" /></a>
<p style="text-align: left;"><strong><a title="Val Du Charron" href="http://vdcwines.com/" target="_blank">Val Du Charron Wine Estate</a></strong></p>
<p style="text-align: left;"><strong>Length of Stay:</strong>1 Night Stay only<strong></strong></p>
<p style="text-align: left;"><strong>Optional Extra's:</strong></p>
<p style="text-align: left;"><input type="checkbox" name="extra1" value="MTB" />Mountain Biking Tours<input type="checkbox" name="extra1" value="Spa" />Spa Treatements<input type="checkbox" name="extra1" value="Olive" />Olive Grove Tour and Tasting<input type="checkbox" name="extra1" value="Fishing" />Bass Fishing<input type="checkbox" name="extra1" value="HorseRide" />Horse Riding</p>
<strong>Cycling Levels:</strong>
<input type="radio" name="difficulty" value="Relaxed" />Relaxed
<input type="radio" name="difficulty" value="Moderate" />Moderate
<input type="radio" name="difficulty" value="Challenging" />Challenging
<strong>Transport:</strong>
<input type="radio" name="transport" value="Car Hire" />Car Hire
<input type="radio" name="transport" value="Transfers" />Airport or other Transfers
<input type="radio" name="transport" value="Self Drive" />Self Drive
Comments:
<textarea cols="25" maxlength="1000" name="comments" rows="6"></textarea>
<input type="submit" value="Enquire Now" />
</form>
和我正在使用的php
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "bookings@bikesnwines.com";
$email_subject = "Wellington Overnight Requests";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['fullname']) ||
isset($_POST['email_from']) ||
isset($_POST['date']) ||
isset($_POST['extra1']) ||
!isset($_POST['difficulty']) ||
!isset($_POST['transport']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$fullname = $_POST['fullname']; // required
$email_from = $_POST['email_from']; // required
$date = $_POST['date']; // required
$extra1 = $_POST['extra1']; // not required
$difficulty = $_POST['difficulty']; // required
$transport = $_POST['transport']; // required
$comments = $_POST['comments']; // not required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$fullname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Full Name: ".clean_string($fullname)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Date of Stay: ".clean_string($date)."\n";
$email_message .= "Optional Extra's: ".clean_string($extra1)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
//redirect to thank for registering page
header( 'Location: http://raceinterface.co.za/thank-you-for-registering/' ) ;
}
?>
当你提交它时只打开一个空白页面.. 我有点金发女郎..但是超级卡住..
由于
答案 0 :(得分:6)
首先,您没有名为'email'的字段。尝试将if(isset($_POST['email'])) {
更改为if(isset($_POST['email_from'])) {
答案 1 :(得分:0)
输入电子邮件表单中的名称是'email_from',在php代码中,你写了'if(!isset($ _ POST ['email'])'。这是拼写错误吗?
答案 2 :(得分:0)
我在表单中看不到可变电子邮件。 因此,如果您在PHP中查看$ _POST ['email'],则永远不会设置它。
你应该在你的.php中构建一个“else”。