我是一个想要做一些看似简单但事实证明非常复杂的新手。我尝试使用hostgator转发电子邮件功能转发带有指向一个电子邮件地址的附件的电子邮件,并将电子邮件,附件和所有内容转发到另一个电子邮件地址,同时删除&中的原始电子邮件地址#34;至"标题部分,并将其替换为转发它的电子邮件地址。
使用独立功能,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));
?>