发送电子邮件并插入表格

时间:2013-05-27 16:18:01

标签: php email sendmail

我创建了一个表单,一旦人们提交它应该转到电子邮件并插入到表中,第二部分正在运行,但它没有配置电子邮件。代码如下,我做错了什么?顺便说一句,我没有收到任何错误。

<?php
include"connect.php";

if(isset($_POST['email'])) {

$email_to = "myemail@gmail.com"; 
$email_subject = "Here is a message for you"; 


function died($error) { 
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(); 
} 


if(!isset($_POST['name']) || 
!isset($_POST['vehicleN']) || 
!isset($_POST['pickup']) || 
!isset($_POST['pickup_date']) || 
!isset($_POST['pickup_time']) || 
!isset($_POST['return']) || 
!isset($_POST['return_date']) || 
!isset($_POST['return_time']) ||
!isset($_POST['email']) ||  
!isset($_POST['mobile']) || 
!isset($_POST['message'])) { 
died('We are sorry, but there appears to be a problem with the form you submitted.');
} 

$vehitype=$_POST['vehicleN'];
$pickup=$_POST['pickup'];
$pdate=$_POST['pickup_date'];
$ptime=$_POST['pickup_time'];
$return=$_POST['return'];
$rdate=$_POST['return_date'];
$rtime=$_POST['return_time']; 
$name = $_POST['name']; 
$email_from = $_POST['email']; 
$mobile = $_POST['mobile']; 
$message = $_POST['message']; 
$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,$name)) { 
$error_message .= 'The Name you entered does not appear to be valid.<br />'; 
}   
if(strlen($message) < 2) {
$error_message .= 'The Message 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 .= "Vehicle: ".clean_string($vehicleN)."\n"; 
$email_message .= "pickup: ".clean_string($pickup)."\n"; 
$email_message .= "pickup-date: ".clean_string($pickup_date)."\n"; 
$email_message .= "pickup-time: ".clean_string($pickup_time)."\n"; 
$email_message .= "return: ".clean_string($return)."\n"; 
$email_message .= "return-date: ".clean_string($return_date)."\n"; 
$email_message .= "return-time: ".clean_string($return_time)."\n"; 
$email_message .= "Name: ".clean_string($name)."\n"; 
$email_message .= "Email: ".clean_string($email_from)."\n"; 
$email_message .= "Telephone: ".clean_string($mobile)."\n"; 
$email_message .= "Message: ".clean_string($message)."\n"; 

$headers = 'From: '.$email_from."\r\n". 
'Reply-To: '.$email_from."\r\n" . 
'X-Mailer: PHP/' . phpversion(); 
@mail($email_to, $email_subject, $email_message, $headers);

$query="insert into booking set vehiType='$vehitype', datePick='$pdate',timePick='$ptime',dateRet='$rdate',timeRet='$rtime', name='$name', email='$email_from', mob='$mobile', message='$message', areaPick='$pickup', areaRet='$return' ";

mysql_query ($query) or die ('could not updated:'.mysql_error());
header ('Location:sucess.php');
exit()
}
?>

1 个答案:

答案 0 :(得分:0)

不确定这是否是问题的原因,但PHP中没有“death()”函数;尝试将{died())替换为die()exit()