PHP电子邮件拦截不发送带附件的电子邮件
问题描述:
我在我的服务器上设置了电子邮件拦截。PHP电子邮件拦截不发送带附件的电子邮件
以下是我的电子邮件转发服务器上
[email protected], “/家庭/服务器/ php_pipe_mail.php”
以下设置是我php_pipe_mail.php代码
#!/usr/bin/php -q
<?php
require_once('mimeDecode.php');
include('sql-connect.php');
error_reporting(E_ALL);
ob_start();
$raw_email = '';
if (!$stdin = fopen("php://stdin", "R"))
{
echo "ERROR: UNABLE TO OPEN php://stdin \n";
}
// ABLE TO READ THE MAIL
else
{
while (!feof($stdin))
{
$raw_email .= fread($stdin, 4096);
}
fclose($stdin);
}
$raw_email = preg_replace('/ +/', ' ', $raw_email);
var_dump($raw_email);
$buf = ob_get_contents();
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$params['input'] = $buf;
$params['crlf'] = "\r\n";
//Creating temp file on server
$myFile = "amail.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $buf);
fclose($fh);
//Generating mail structure in object format
$structure = Mail_mimeDecode::decode($params);
$attachment = array();
$mail_date= date('Y-m-d H:i:s', strtotime($structure->headers['date']));
$from = $structure->headers['from'];
$to = $structure->headers['to'];
$subject = htmlentities($structure->headers['subject'],ENT_QUOTES);
if($structure->ctype_primary == "multipart")
{
$body_text = $structure->parts[0]->parts[0]->body;
$body_html = $structure->parts[0]->parts[1]->body;
$x = 0;
//fetch attachment
foreach ($structure->parts as $part) {
// only save if an attachment
if (isset($part->disposition) and ($part->disposition=='attachment')) {
$attachment[$x]["filename"] = $part->d_parameters['filename'];
$attachment[$x]["content_type"] = $part->ctype_primary . "/" . $part->ctype_secondary;
$attachment[$x]["body"] = addslashes($part->body);
$x++;
}
}
}
else
{
$body_text = $structure->parts[0]->body;
$body_html = $structure->parts[1]->body;
}
$qry1 = "insert into mail_buffer(mail_date,mail_from, mail_to,mail_subject,mail_text_body,mail_html_body) Values('". $mail_date ."','".$from."','".$to."','".$subject."','".$body_text."','".$body_html."')";
mysql_query($qry1) or die(mysql_error($con));
$last_id = mysql_insert_id();
if(count($attachment) > 0)
{
for($i=0; $i < count($attachment); $i++)
{
$qry = "insert into mail_attachment(email_id,content_type, file_name,body) Values('". $last_id ."','".$attachment[$i]['content_type']."','".$attachment[$i]['filename']."','".$attachment[$i]['body']."')";
mysql_query($qry) or die(mysql_error($con));
}
}
mysql_close($con);
ob_end_clean();
?>
现在上面的脚本工作得很好。
我可以去取邮件标题,正文和附件,可以将它们在数据库中存储没有任何问题。
当不带附件的电子邮件来一切工作正常,将电子邮件发送到电子邮件地址,我拦截。
但下面不工作。
当附件的邮件来比电子邮件的内容被存储在数据库中,但电子邮件没有提供电子邮件地址,我拦截和我在反弹电子邮件收到以下错误消息。
您发送无法交付给一个或多个其 收件人的消息。这是一个永久性错误。下面的地址(ES)失败:以
管| /home/server/php_pipe_mail.php 通过[email protected]产生
谁能帮助我关于此事。
谢谢。
答
难道说,当附件存在,你的脚本是呼应的东西吗?我之前遇到过管道电子邮件问题,并且看到故障消息返回给发件人,并且它们是由于管道脚本产生某种输出。也许你的error_reporting(E_ALL);
允许脚本产生一个输出 - 试试
考虑使用http://swiftmailer.org/ – 2011-05-28 10:55:01
丹尼斯,你能给我一些关于它如何帮助我解决我的问题的想法。代码中有什么不对吗? – amar4u 2011-05-28 10:58:27