我有一个奇怪的问题,PHPmail
函数只会从 Chrome 发送电子邮件。这是 HTML 表单:
我已经检查了 HTML 的验证,但我可以验证只有在用户使用 Chrome 时才能接收电子邮件。这是验证代码:
if (isset($_POST['email_from']) && isset($_POST['contact-name']))
{
function set_email_recipent($contact_name) {
$result = "";
switch ($contact_name) {
default:
$result = "info@mysite.com";
break;
}
return $result;
}
$email_to = set_email_recipent($_POST['contact-name']);
$email_subject = "Contact Inquiry";
function died($error)
{
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.";
echo $error;
echo "Please go back and fix these errors.";
die();
}
// validation-expected data exists
if (!isset($_POST['name']) || !isset($_POST['email_from']) || !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_from']; // required
if (isset($_POST['email_subject'])) {
$email_subject = "mysite.com Contact Inquiry" . $_POST['email_subject'];
}
$telephone = $_POST['phone']; // not required
$comments = $_POST['comments']; // required
$company_name = $_POST['company-name']; //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.';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if (!preg_match($string_exp, $name))
{
$error_message .= 'The First Name you entered does not appear to be valid.';
}
if (strlen($comments) < 2)
{
$error_message .= 'Please type in a message longer than two characters.';
}
if (strlen($error_message) > 0)
{
died($error_message);
}
$email_message = "There has been an inquiry from a customer at mysite.com. The user's form details are included 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 .= "Subject: " . clean_string($email_subject) . "\n";
$email_message .= "Company name: " . clean_string($company_name) . "\n";
$email_message .= "Email: " . clean_string($email_from) . "\n";
$email_message .= "Telephone: " . clean_string($telephone) . "\n";
$email_message .= "Comments: " . clean_string($comments);
// create email headers
$headers = 'From: ' . $email_from . "\r\n" . 'Reply-To: ' . $email_from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
if (mail($email_to, $email_subject, $email_message, $headers)) {
?>
Your inquiry has been successfully sent. We will be in touch with you shortly. Recipent was <?php echo $email_to ?>, message was <?php echo $email_message; ?>, headers were <?php echo $headers;
}
else {
?> Error! Please try again... Recipent was <?php echo $email_to ?>, message was <?php echo $email_message; ?>, headers were <?php echo $headers;
}
}
else {
echo "<h1>Error</h1><p>There was an error.</p>";
}
这是我的 HTML:
<form id = "contact" action = "validation.php" method = "post">
<fieldset>
<legend>Contact Info</legend>
<label for = "contact-name">Contact:<em>*</em></label>
<select name = "contact-name" required = "required" title = "Contact" id = "contact-name" autofocus = "autofocus">
<option value = "" selected = "">Choose one:</option>
<optgroup label = "Sales">
<option value = "justin">Justin - Account Rep</option>
<option value = "sherri">Sherri - Account Rep</option>
<option value = "sean">Sean - Account Rep</option>
</optgroup>
<optgroup label = "Accounting">
<option value = "shauna">Shauna - Accounts Payable</option>
<option value = "kristi">Kristi - Accounts Receivable</option>
</optgroup>
<optgroup label = "Administration">
<option value = "matt">Matt - Operations Manager</option>
</optgroup>
<optgroup label = "Art Department">
<option value = "cassidy">Cassidy - Graphic Designer</option>
</optgroup>
</select>
<label for = "name">Name:<em>*</em></label>
<input type = "text" name = "name" id = "name" title = "Name" required = "required" placeholder = "Your Name">
<label for = "company-name">Company:</label>
<input type = "text" name = "company-name" id = "company-name" title = "Company" placeholder = "Your company name - ex. My Company Inc.">
<label for = "email_from">Email:<em>*</em></label>
<input type = "email" name = "email_from" id = "email_from" title = "Email" required = "required" placeholder = "Your Email - ex. yourname@gmail.com">
<label for = "phone">Phone:<em>*</em></label>
<input type = "tel" name = "phone" id = "phone" title = "Phone" required = "required" placeholder = "(403) 555-5555">
<label for = "email_subject">Subject:<em>*</em></label>
<input type = "text" name = "email_subject" id = "email_subject" title = "Subject" required = "required" placeholder = "Subject - ex. 555 Main Street, Graffiti, etc.">
<label for = "comments">Comments:<em>*</em></label>
<textarea name = "comments" cols = "10" rows = "15" id = "comments" title = "Comments" required = "required" placeholder = "Got anything you want to tell us? Put it here."></textarea>
</fieldset>
<div class = "row form-actions">
<button class = "btn large" type = "submit" id = "validate">Send <i class = "icon-mail"></i></button>
</div>
</form>
为什么这适用于 Chrome 而不是其他浏览器?我怎样才能解决这个问题?