简体   繁体   English

ajax php邮件功能不适用于hotmail地址

[英]ajax php mail function not working for hotmail addresses

I am having a problem with my contact form and the php mail() function. 我的联系表单和php mail()函数有问题。 For some reason, they work for every email address (@gmail, @yahoo, @outlook and even @facebook!) except the old dreaded hotmail. 由于某些原因,它们适用于每个电子邮件地址(@ gmail,@ yahoo,@ outlook甚至@facebook!),但旧的可怕Hotmail除外。 I am just curious as to where my code is missing something. 我只是对我的代码缺少什么感到好奇。 I have checked the mail servers and there is apparently no issue with hotmail addresses. 我已经检查了邮件服务器,并且Hotmail地址显然没有问题。

The email does not even get delivered to the spam/junk folder (it does not reach hotmail). 该电子邮件甚至没有发送到垃圾邮件/垃圾文件夹(它不会到达hotmail)。 I had a look online and some say to change the headers to avoid being caught in the spam filter. 我在网上看了一眼,有人说要更改标题,以免被垃圾邮件过滤器捕获。 Any pointers to this? 有任何指示吗?

PHP CODE PHP代码

<?php
    header('Content-Type: application/json charset=utf-8');
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'companyname@mail.com'; 
    $to = 'myemail@hotmail.com'; 
    $subject = $name . ' has sent you a message';
    $human = $_POST['antispam'];

    $body = "From: $name\n E-Mail: $email\n Message:\n $message";

    if (isset($_POST['name']) && $human == '4') {                
        if (mail ($to, $subject, $body, $from)) { 
            echo '{"status":"1"}';
        } else { 
            echo '{"status":"0"}';
        } 
    } 
    else 
    {
        echo '{"status":"2"}';
    }
?>

The if statements is just a check if all forms are valid and the anti spam (2+2) is correctly entered. if语句只是检查所有表单是否有效以及是否正确输入了反垃圾邮件(2 + 2)。 nothing much to do in this part. 这部分没什么大不了的。 The issue I guess is somewhere in the header 我猜这个问题在标题中

Try using these changes: 尝试使用以下更改:

<?php
    header('Content-Type: application/json; charset=utf-8');
    ...
    $from = 'companyname@mail.com'; 
    $headers = 'From: '. $from. "\r\n";
    ...
        if (mail ($to, $subject, $body, $headers)) { 
    ...
?>

4th parameter of mail function is expected to be additional_headers, not just from address. 邮件功能的第4个参数应该是extra_headers,而不仅仅是地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM