1 最后由 syoueiwa (2010-07-06 21:48:51) 编辑

主题: php自动发信的邮件头问题

使用PHP的发信函数mail()的邮件发现邮件头有些不太合适。
首先邮件头如下:

Delivered-To: zhen@gmail.com
Received: by 10.229.214.67 with SMTP id gz3cs96219qcb;
        Mon, 5 Jul 2010 21:26:22 -0700 (PDT)
Received: by 10.142.187.19 with SMTP id k19mr4536774wff.135.1278390380064;
        Mon, 05 Jul 2010 21:26:20 -0700 (PDT)
Return-Path: <apache@www.syou.com>
Received: from www.syou.com (syou.com [31.120.56.220])
        by mx.google.com with ESMTP id k11si9934667wfa.149.2010.07.05.21.26.18;
        Mon, 05 Jul 2010 21:26:19 -0700 (PDT)
Received-SPF: pass (google.com: domain of apache@www.syou.com designates 31.120.56.220 as permitted sender) client-ip=31.120.56.220;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of apache@www.syou.com designates 31.120.56.220 as permitted sender) smtp.mail=apache@www.syou.com
Received: by www.syou.com (Postfix, from userid 48)
    id 8D9F79E8255; Tue,  6 Jul 2010 13:25:03 +0900 (JST)
X-DKIM: Sendmail DKIM Filter v2.8.3 www.syou.com 8D9F79E8255
To: zhen@gmail.com
Subject: =?UTF-8?B?44GU5rOo5paH44KS44GC44KK44GM44Go44GG44GU44GW44GE44G+44GZ44CC?=
X-PHP-Originating-Script: 501:class-phpmailer.php
Date: Tue, 6 Jul 2010 13:25:03 +0900
From: =?UTF-8?Q?OK_INTERNATIONAL=28=E6=A0=AA=29?= <info@shopup.com>
Message-ID: <4fcd606becaa5cb6da24b6c4b831a5bf@www.shopup.com>
X-Priority: 3
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/html; charset="UTF-8"
....

上面的邮件我是用我是在mail()函数中设置发信人为 info@shopup.com,收信人为zhen@gmail.com
但信发出去后,发现Return-Path为apache@www.syou.com(www.syou.com是我的服务器hostname),并不是我想要的info@shopup.com

我应该怎么设置使得发出去的信Return-Path和发信人From一致呢?


而且邮送域也不对,我不希望是服务器hostname(www.syou.com),而应该是自动发信用的shopup.com

好晕呀,邮箱设置就是问题多多呀。

斑竹哥哥和各位帮帮看看,拜托了。

回复: php自动发信的邮件头问题

自已找到解决办法了,跟大家分享一下吧。



发信PHP代码类似如下就可以了。

$old_from = ini_get("sendmail_from");
ini_set("sendmail_from", $this->From);
$params = sprintf("-oi -f %s", $this->From);
@mail($to, $this->EncodeHeader($this->Subject), $body, $header, $params);

回复: php自动发信的邮件头问题

谢谢分享