douyun8901 2012-08-11 14:11
浏览 69

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

I am having a problem with my contact form and the php mail() function. For some reason, they work for every email address (@gmail, @yahoo, @outlook and even @facebook!) except the old dreaded 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.

The email does not even get delivered to the spam/junk folder (it does not reach 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
    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
 E-Mail: $email
 Message:
 $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. nothing much to do in this part. The issue I guess is somewhere in the header

  • 写回答

1条回答 默认 最新

  • dongpanshi2839 2012-08-11 14:59
    关注

    Try using these changes:

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

    4th parameter of mail function is expected to be additional_headers, not just from address.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP