“来自”的问题通过 PHP mail() 函数发送短信时的标头

发布于 2025-01-04 04:20:49 字数 4488 浏览 1 评论 0 原文

我正在使用 PHP 的 mail() 函数发送 SMS 消息。它工作正常,除了消息显示为来自 '[电子邮件受保护]' 当我希望它显示为“[电子邮件受保护]'。这是相关的代码:

//Set headers and send mail.
$headers = "From: " . "[email protected]" . "\r\n";
$headers .= "Reply-To: ". "[email protected]" . "\r\n";

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

我知道这个问题之前已经被问过,但到目前为止没有任何帮助我。我尝试将标头设置为 '-f [email protected]' 。运气不好。

顺便说一句,如果我发送到电子邮件地址而不是电话号码,标题就可以正常工作。

我不知道这是否与它有关,但我的脚本是从我在 cpanel 中设置的电子邮件转发器调用的,例如:

Address                 Forward To
[email protected]       |/home/myuser/public_html/handler.php

另外,这里是发送到电子邮件地址的电子邮件的完整标头:

Return-Path: <[email protected]>
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 <[email protected]>; 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 <[email protected]>; Wed,  8 Feb 2012 19:25:55 -0600 (CST)
Received: from itch3 by mr2.websitewelcome.com with local (Exim 4.69)
    (envelope-from <[email protected]>)
    id 1RvIln-0003AQ-Cv
    for [email protected]; Wed, 08 Feb 2012 19:25:55 -0600
To: [email protected]
Subject: subject
From: "[email protected]" <[email protected]>
Reply-To: [email protected]
Message-Id: <[email protected]>
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

I'm using PHP's mail() function to send SMS messages. It works fine, except that the message shows as coming from '[email protected]' when I want it to show as '[email protected]'. Here's the relevant code:

//Set headers and send mail.
$headers = "From: " . "[email protected]" . "\r\n";
$headers .= "Reply-To: ". "[email protected]" . "\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 [email protected]'. 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
[email protected]       |/home/myuser/public_html/handler.php

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

Return-Path: <[email protected]>
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 <[email protected]>; 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 <[email protected]>; Wed,  8 Feb 2012 19:25:55 -0600 (CST)
Received: from itch3 by mr2.websitewelcome.com with local (Exim 4.69)
    (envelope-from <[email protected]>)
    id 1RvIln-0003AQ-Cv
    for [email protected]; Wed, 08 Feb 2012 19:25:55 -0600
To: [email protected]
Subject: subject
From: "[email protected]" <[email protected]>
Reply-To: [email protected]
Message-Id: <[email protected]>
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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无力看清 2025-01-11 04:20:49

您可以使用附加参数来(再次)声明发件人地址吗?

mail('[email protected]', 'the subject', 'the message',
"From: [email protected]\r\n", '[email protected]');

我通常在使用 mail() 时添加附加参数,它往往可以解决我遇到的大多数问题。

Can you use the additional parameters argument to (again) declare the from address?

mail('[email protected]', 'the subject', 'the message',
"From: [email protected]\r\n", '[email protected]');

I generally add on the additional parameter when using mail() and it tends to fix most issues I've experienced.

何必那么矫情 2025-01-11 04:20:49

您可以将返回路径设置为[电子邮件受保护]< /code>,如下所示:(

mail( $from, '', $message, $headers, '[email protected]');

注意 -f 后面缺少空格)

You can set the Return-Path to [email protected], like so:

mail( $from, '', $message, $headers, '[email protected]');

(note the lack of space after -f)

撩人痒 2025-01-11 04:20:49

变量 $from 未设置,因此它是默认值。你的代码应该是:

//Set headers and send mail.
$headers = "From: " . "[email protected]" . "\r\n";
$headers .= "Reply-To: ". "[email protected]" . "\r\n";

$from = "[email protected]";

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

The variable $from is not set, so it defaults. Your code should be:

//Set headers and send mail.
$headers = "From: " . "[email protected]" . "\r\n";
$headers .= "Reply-To: ". "[email protected]" . "\r\n";

$from = "[email protected]";

mail( $from, '', $message, $headers );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文