简体   繁体   English

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

[英]Issue with 'From' header when sending SMS via PHP mail() function

I'm using PHP's mail() function to send SMS messages. 我正在使用PHP的mail()函数发送短信。 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'. 它的工作正常,但是当我希望它显示为'test@mydomain.com'时,消息显示为来自'myuser@mr2.websitewelcome.com'。 Here's the relevant code: 这是相关的代码:

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

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'. 我已经尝试将标题设置为'-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: Idk如果这与它有关,但我的脚本是从我在cpanel中设置的电子邮件转发器调用的,如:

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

Can you use the additional parameters argument to (again) declare the from address? 你能使用附加参数参数(再次)声明来自地址吗?

mail('nobody@example.com', 'the subject', 'the message',
"From: webmaster@example.com\r\n", '-fwebmaster@example.com');

I generally add on the additional parameter when using mail() and it tends to fix most issues I've experienced. 我通常在使用mail()时添加附加参数,它可以解决我遇到的大多数问题。

You can set the Return-Path to test@mydomain.com , like so: 您可以将Return-Path设置为test@mydomain.com ,如下所示:

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

(note the lack of space after -f ) (注意-f之后空间不足)

The variable $from is not set, so it defaults. 变量$ from未设置,因此默认为。 Your code should be: 你的代码应该是:

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

$from = "test@mydomain.com";

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

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

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