douzhun4124 2012-02-08 23:30
浏览 94
已采纳

通过PHP mail()函数发送SMS时出现'From'标题

I'm using PHP's mail() function to send SMS messages. It works fine, except that the message shows as coming from 'myuser@mr2.websitewelcome.com' when I want it to show as 'test@mydomain.com'. Here's the relevant code:

//Set headers and send mail.
$headers = "From: " . "test@mydomain.com" . "
";
$headers .= "Reply-To: ". "test@mydomain.com" . "
";

mail( $from, '', $message, $headers );

I know this question has been asked before, but nothing has helped me so far. I've tried setting the header as '-f test@mydomain.com'. No luck.

Btw, if I send to an email address rather than a phone number, the headers work just fine.

Idk if this has anything to do with it, but my script gets called from an email forwarder that I set up in cpanel like:

Address                 Forward To
test@mydomain.com       |/home/myuser/public_html/handler.php

Also, here are the full headers of an email send to an email address:

Return-Path: <itch3@mr2.websitewelcome.com>
Received: from gateway01.websitewelcome.com (gateway01.websitewelcome.com [67.18.65.19])
    by mtain-mk01.r1000.mx.aol.com (Internet Inbound) with ESMTP id 1B28B3800008B
    for <myemail@me.com>; Wed,  8 Feb 2012 20:25:56 -0500 (EST)
Received: by gateway01.websitewelcome.com (Postfix, from userid 5007)
    id A69B35C21D4BD; Wed,  8 Feb 2012 19:25:55 -0600 (CST)
Received: from mr2.websitewelcome.com (mr2.websitewelcome.com [74.53.229.178])
    by gateway01.websitewelcome.com (Postfix) with ESMTP id 9CBAF5C21D49D
    for <myemail@me.com>; Wed,  8 Feb 2012 19:25:55 -0600 (CST)
Received: from itch3 by mr2.websitewelcome.com with local (Exim 4.69)
    (envelope-from <itch3@mr2.websitewelcome.com>)
    id 1RvIln-0003AQ-Cv
    for myemail@me.com; Wed, 08 Feb 2012 19:25:55 -0600
To: myemail@me.com
Subject: subject
From: "test@mydomain.com" <test@mydomain.com>
Reply-To: test@mydomain.com
Message-Id: <E1RvIln-0003AQ-Cv@mr2.websitewelcome.com>
Date: Wed, 08 Feb 2012 19:25:55 -0600
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - mr2.websitewelcome.com
X-AntiAbuse: Original Domain - aol.com
X-AntiAbuse: Originator/Caller UID/GID - [2146 32003] / [47 12]
X-AntiAbuse: Sender Address Domain - mr2.websitewelcome.com
X-BWhitelist: no
X-Source: /usr/bin/php
X-Source-Args: /usr/bin/php -q /home/itch3/public_html/handler.php 
X-Source-Dir: switchon3.com:/public_html
X-Source-Sender: 
X-Source-Auth: itch3
X-Email-Count: 2
X-Source-Cap: aXRjaDM7Y3ZncnViYnM7bXIyLndlYnNpdGV3ZWxjb21lLmNvbQ==
x-aol-global-disposition: G
X-AOL-SCOLL-SCORE: 0:2:199012208:93952408  
X-AOL-SCOLL-URL_COUNT: 0  
x-aol-sid: 3039ac1d61854f3320a4018d
X-AOL-IP: 67.18.65.19
X-AOL-SPF: domain : mr2.websitewelcome.com SPF : none
  • 写回答

3条回答 默认 最新

  • douchongzhang9267 2012-02-09 02:09
    关注

    You can set the Return-Path to test@mydomain.com, like so:

    mail( $from, '', $message, $headers, '-ftest@mydomain.com');
    

    (note the lack of space after -f)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 链接问题 C++LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接