我有一个表单,我试图根据下拉选项发送到不同的电子邮件地址,我知道没有PHP。我把几个表格拼凑在一起所以我可能有相互矛盾的数据。我得到它表现得像它正在工作,在我点击提交后,它将我带到我的PHP页面,但页面显示空白,电子邮件不会最终发送。我试图删除多余的不必要的信息,但我不知道我做错了什么。
HTML
<p><form name="htmlform" method="post" action="html_form_send-quote.php">
<table width="100%" border="0" cellspacing="10px" cellpadding="10px">
<tbody>
<tr>
<td>Nearest Location*</td>
<td><select id="mailTo" name"mailTo" onchange="changeVal()">
<option value="loc1">Location 1</option>
<option value="loc2">Location 2</option>
<option value="loc3">Location 3</option>
</select></td>
</tr>
<tr>
<td>Name*</td>
<td><input type="text" name="name" size="60" value=""></td>
</tr>
<tr>
<td>E-Mail*</td>
<td><input type="text" name="email" size="60" value=""></td>
</tr>
<tr>
<td>I'm interested in* </td>
<td><textarea name="comments" cols="60" rows="5"></textarea></td>
</tr>
我的PHP
// CHANGE THE TWO LINES BELOW
switch($mailTo) {
case 'loc1':
$to = "email1@example.com";
break;
case 'loc2':
$to = "email2@example.com";
break;
case 'loc3':
$to = "email3@example.com";
break;
}
$result = mail($name, $email, $phone, $address, $city, $state, $zip, $calltime, $comments);
$email_subject = "Website Quote Request";
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['name']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // 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,$name)) {
$error_message .= 'Please enter your name<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'Please describe your requst.<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 .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\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);
?>
<html>...</html>
<?php
}
die();
?>