PHP-仅在Chrome上发送邮件

PHP-仅在Chrome上发送邮件,php,google-chrome,sendmail,Php,Google Chrome,Sendmail,我遇到了一个奇怪的问题,PHPmail函数只能从Chrome发送电子邮件。以下是HTML格式: 我已经检查了HTML的验证,但我可以验证只有在用户使用Chrome时才能接收电子邮件。以下是验证代码: if (isset($_POST['email_from']) && isset($_POST['contact-name'])) { function set_email_recipent($contact_name) { $result = "";

我遇到了一个奇怪的问题,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>";
}
if(isset($\u POST['email\u from'])和&isset($\u POST['contact-name']))
{
功能集\u电子邮件\u收件人($contact\u name){
$result=“”;
交换机($contact\u name){
违约:
$result=”info@mysite.com";
打破
}
返回$result;
}
$email_to=设置_email_recipient($_POST['contact-name']);
$email\u subject=“联系人查询”;
函数失效($error)
{
echo“非常抱歉,您提交的表单存在错误。”;
echo“这些错误出现在下面。”;
echo$错误;
echo“请返回并修复这些错误。”;
模具();
}
//验证预期数据存在
如果(!isset($_POST['name'])| |!isset($_POST['email\u from'])| |!isset($_POST['phone'])| |!isset($_POST['comments'))
{
死亡('很抱歉,您提交的表格似乎有问题');
}
$name=$\u POST['name'];//必需
$email\u from=$\u POST['email\u from'];//必需
如果(isset($\u POST['email\u subject'])){
$email\u subject=“mysite.com联系人查询”。$\u POST['email\u subject';
}
$telephone=$_POST['phone'];//不需要
$comments=$_POST['comments'];//必需
$company\u name=$\u POST['company-name'];//不需要
$error_message=“”;
$email_exp='/^[A-Za-z0-9.[U%-]+@[A-Za-z0-9.-]+\[A-Za-z]{2,4}$/';
如果(!preg_match($email_exp,$email_from))
{
$error_message.=“您输入的电子邮件地址似乎无效。”;
}
$string_exp=“/^[A-Za-z.-]+$/”;
如果(!preg_match($string_exp,$name))
{
$error_message.=“您输入的名字似乎无效。”;
}
if(strlen($comments)<2)
{
$error_message.=“请键入一条长度超过两个字符的消息。”;
}
如果(strlen($error_message)>0)
{
死亡($error_message);
}
$email\u message=“有客户在mysite.com上查询。用户的表单详细信息如下:\n\n”;
函数clean_string($string)
{
$bad=数组(“内容类型”,“密件抄送:”、“收件人:”、“抄送:”、“href”);
返回str_replace($bad,“,$string);
}
$email\u message.=“名称:”.clean\u字符串($Name)。“\n”;
$email\u message.=“主题:”.clean\u字符串($email\u主题)。“\n”;
$email\u message.=“公司名称:”.clean\u字符串($Company\u name)。“\n”;
$email\u message.=“email:”.clean\u字符串($email\u from)。“\n”;
$email\u message.=“电话:”.clean\u字符串($Telephone)。“\n”;
$email_message.=“注释:”.clean_字符串($Comments);
//创建电子邮件标题
$headers='From:'.$email\u From.\r\n'.'回复:'.$email\u From.\r\n'.'X-Mailer:PHP/'.phpversion();
如果(邮件($email\u to、$email\u subject、$email\u message、$headers)){
?>

您的查询已成功发送。我们将很快与您联系。Recipent was,message was,Header was错误!请重试…Recipent was,message was,Header was经过严格测试,我们确定是客户端的邮件服务器出现故障。请联系他们的技术支持和请求通过设置邮件服务器日志的副本,我们可以确定有大量电子邮件被拒绝为垃圾邮件


其他遇到类似问题的用户应咨询其客户负责管理相应邮件服务器的技术部门,以便在浏览器端出现任何问题之前,首先确定是否正确接收了电子邮件。

mail()根本不在乎用户使用的是什么浏览器。它的工作是发送电子邮件,而不是因为有人在使用Chrome而不是IE或Firefox而改变它的行为。如果它在不同的浏览器中表现不同,那么是你的代码造成了这种差异,而不是邮件本身。是什么让你认为用户必须在Chrome上才能使用script to work?PHP是一种服务器端语言。添加了HTML。我很清楚,
mail
是跨浏览器的,但我发现其他人也有类似的问题:只是在Browserstack中运行了一些测试:在IE中工作,FF for Windows,FF Mobile for Android…但不是在我的本地机器或Safari上的FF…想法?你的PHP输出是什么?
<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>