我遇到一个奇怪的问题,即PHP mail
功能只会从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而非其他浏览器?我该如何解决这个问题?
答案 0 :(得分:0)
经过一些严格的测试后,我们确定是客户端的邮件服务器正在运行。联系他们的技术支持并请求邮件服务器日志的副本,我们可以确定一些大量的电子邮件被拒绝为垃圾邮件。
遇到类似问题的其他人应咨询负责管理相应邮件服务器的客户技术部门,以便在浏览器方面承担任何问题之前首先确定是否正确接收了电子邮件。