php在提交时发送邮件表单空白

时间:2017-03-16 10:13:48

标签: php forms sendmail

我希望你能帮忙,所以我不会变得更加灰心。

提交后的表单只显示空白屏幕,只有在我添加选择选项时才会显示。当我输入详细信息并提交时,会转到quote.php但显示空白页。

感谢您的帮助:)。

<?php     
if(isset($_POST['email'])) {
$email_to = "rbsteele68@gmail.com";
$email_subject = "Enquiry from Bright gardens website";

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['first_name']) ||

!isset($_POST['last_name']) ||

!isset($_POST['email']) ||

!isset($_POST['service']) ||

!isset($_POST['telephone']) ||

!isset($_POST['comments'])) {

died('We are sorry, but there appears to be a problem with the form you submitted.');       

}

$first_name = $_POST['first_name']; // required

$last_name = $_POST['last_name']; // required

$email_from = $_POST['email']; // required

$service = $_POST['service']; //  not required

$telephone = $_POST['telephone']; // not required

$comments = $_POST['comments']; // 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,$first_name)) {

$error_message .= 'The First Name you entered does not appear to be valid.<br />';

}

if(!preg_match($string_exp,$last_name)) {

$error_message .= 'The Last Name you entered does not appear to be valid.<br />';

}

if(strlen($comments) < 2) {

$error_message .= 'The Comments you entered do 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 .= "First Name: ".clean_string($first_name)."\n";

$email_message .= "Last Name: ".clean_string($last_name)."\n";

$email_message .= "Email: ".clean_string($email_from)."\n";

$email_message .= "Service: ".clean_string($service)."\n";

$email_message .= "Telephone: ".clean_string($telephone)."\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);  

?>

My main html form code is below ////////////

我很可能错过了一些小事:(

<form id="contact-form" method="post" action="quote.php">
<div class="messages"></div>
<div class="form-group request_group">
<label>Name:</label>
<input id="form_name" type="text" name="first_name" class="form-control">
<div class="help-block with-errors"></div>
</div>
<div class="form-group request_group">
<label>Email:</label>
<input id="form_lastname" type="text" name="last_name" class="form-control">
<div class="help-block with-errors"></div>
</div>
<div class="form-group request_group">
<label>Phone:</label>
<input id="form_text" type="text" name="telephone" class="form-control">
<div class="help-block with-errors"></div>
</div>


<div class="row">
<div class="col-md-12">
<div class="form-group request_group">
<select name="service" data-bv-field="state" class="form-control quick_form_control selectpicker">
<option value="Lawns & hedging">Lawns & hedging</option>
<option value="Fencing, decking & slabbing">Fencing, decking & slabbing</option>
<option value="Garden makeovers">Garden makeovers</option>
<option value="Garden maintenance">Garden maintenance</option>
<option value="Tree work">Tree work</option>
<option value="Pest control">Pest control</option>
<option value="Garden clearing & clearup">Garden clearing & clearup</option>
</select>
<div class="help-block with-errors"></div>
</div>
</div>
</div>


<div class="form-group request_group">
<label>Message:</label>
<textarea id="var4form_mess1" name="comments" class="form-control"></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="form-group request_group">
<label></label>
<input type="submit" value="Get a quote" class="btn submit_now get-a-quote_btn">
</div>
</form>

1 个答案:

答案 0 :(得分:0)

使用die而不是death()

请检查。