我是一个新手,试图做一些看似简单但结果却相当复杂的事情。我正在尝试使用 hostgator 转发电子邮件功能将带有附件的电子邮件转发到一个电子邮件地址,并将电子邮件、附件和所有内容转发到另一个电子邮件地址,同时删除“收件人”中的原始电子邮件地址标题部分并将其替换为要转发到的电子邮件地址。
借助独立功能,hostgator 中的 cpanel 允许转发带有附件的电子邮件,但原始电子邮件在转发到最终接收电子邮件时可见。这有点像 hostgator 将其作为密件抄送发送给最终收件人。
cpanel 有另一个功能,它允许将电子邮件通过管道传输到 php 脚本,我能够使用邮件功能和其他几行代码将原始电子邮件转发到 php,但它看起来很糟糕,附件只是一堆base64 中的代码。最终收件人也需要数小时才能收到。
我已经在互联网上搜寻了将不同代码片段拼凑在一起的最终解决方案,并在下面解决了这个问题,但它似乎不起作用,所以我希望你们中的一些更有经验的开发人员可以就此传授一些智慧可怜的新人。对于冗长的提示,我深表歉意。
#!/usr/bin/php -q
<?php
ini_set("include_path", '/home#/username/php:' . ini_get("include_path") );
require_once 'Mail/mimeDecode.php';
var $raw = '';
var $decoded;
$src = 'php://stdin';
$fd = fopen($src,'r');
while(!feof($fd)){ $this->raw .= fread($fd,1024); }
fclose($fd);
$decoder = new Mail_mimeDecode($this->raw);
$this->decoded = $decoder->decode(
Array(
'decode_headers' => TRUE,
'include_bodies' => TRUE,
'decode_bodies' => TRUE,
)
);
$this->subject = $this->decoded->headers['subject'];
$getHead[] = $this->decoded->headers['Received'];
$getHead[] = $this->decoded->headers['From'];
$getHead[] = $this->decoded->headers['Reply-To'];
$getHead[] = $this->decoded->headers['X-Mailer'];
$getHead[] = $this->decoded->headers['Date'];
$getHead[] = $this->decoded->headers['MIME-Version'];
$getHead[] = $this->decoded->headers['Content-Type'];
$getHead[] = $this->decoded->headers['Content-Transfer-Encoding'];
$getHead[] = $this->decoded->headers['Return-Path'];
$getHead[] = $this->decoded->headers['X-OriginalArrivalTime'];
$getHead[] = $this->decoded->headers['Thread-Topic'];
$getHead[] = $this->decoded->headers['Thread-Index'];
$getHead[] = $this->decoded->headers['Message-ID'];
$getHead[] = $this->decoded->headers['Accept-Language'];
$getHead[] = $this->decoded->headers['Content-Language'];
$getHead[] = $this->decoded->headers['X-MS-Has-Attach'];
$getHead[] = $this->decoded->headers['X-MS-TNEF-Correlator'];
$getHead[] = $this->decoded->headers['x-ms-exchange-transport-fromentityheader'];
$getHead[] = $this->decoded->headers['x-originating-ip'];
$getHead[] = $this->decoded->headers['Content-Disposition'];
$getHead[] = $this->decoded->headers['X-MS-Exchange-Organization-AuthSource'];
$getHead[] = $this->decoded->headers['X-MS-Exchange-Organization-AuthAs'];
$getHead[] = $this->decoded->headers['X-MS-Exchange-Organization-AuthMechanism'];
$getHead[] = $this->decoded->headers['X-MS-Exchange-Organization-Network-Message-Id'];
$getHead[] = $this->decoded->headers['X-MS-Exchange-Organization-AVStamp-Enterprise'];
$this->body = $this->decoded->body;
$email_to = "username@domainname.com";
mail($email_to, $this->subject, $this->body, implode("\r\n", $getHead));
?>