linux - 发送 fpdf 附件在我的 linux suse 服务器上不起作用,但它在我的共享主机帐户上起作用

标签 linux email attachment vps fpdf

我有一个在 Internet 上开发的 php 程序。到目前为止,我使用的是共享托管包。一切正常,直到我搬到 vps (apache2 suse 9.1 plesk)。我发现某些 php 功能没有被激活。我已经使用互联网解决了大部分问题。

我的主要问题是使用 fpdf 通过电子邮件发送 pdf。即

<?php
// download fpdf class (http://fpdf.org)
require("fpdf.php");

// fpdf object
$pdf = new FPDF();

// generate a simple PDF (for more info, see http://fpdf.org/en/tutorial/)
$pdf->AddPage();
$pdf->SetFont("Arial","B",14);
$pdf->Cell(40,10, "this is a pdf example");

// email stuff (change data below)
$to = "steven@siteaddress.co.uk"; 
$from = "me@domain.com"; 
$subject = "send email with pdf attachment"; 
$message = "<p>Please see the attachment.</p>";

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = "example.pdf";

// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));


// main header (multipart mandatory)
$headers  = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol; 
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;

// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;

// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";

// send message
//mail($to, $subject, "", $headers);
if (@mail($to, $subject, "",$headers)) {  
 echo('<p>Mail sent successfully.</p>');  
} else {  
 echo('<p>Mail could not be sent.</p>');  
}  

?>

上面的文件适用于我的共享主机,但是当涉及到从我的 vps 发送时,我从我的文件中收到此错误消息

Mar 23 19:16:56 h1871885 suhosin[64630]: ALERT - mail() - double newline in headers, possible injection, mail dropped (attacker '86.137.40.199', file '/srv/www/vhosts/sitename.co.uk/httpdocs/main/email.php', line 111)

经过多次尝试,错误就出在这一行

 if (@mail($to, $subject, "",$headers))

如果我删除“”,它会在我的 vps 上发送电子邮件,但没有附件。这也发生在我的共享帐户上。附件最终出现在消息中,其中包含大量字符。 所以我肯定需要他们在那里。有没有人知道如何克服这个问题。

非常感谢

将suhosin.ini设置为0后

Mar 23 20:52:48 h1871885 suhosin[60778]: ALERT - mail() - double newline in headers, possible injection, mail dropped (attacker '86.137.40.199', file '/srv/www/vhosts/sitename.co.uk/httpdocs/main/email1.php', line 56)

最佳答案

您的 $headers 中有大量的 .$eol.$eol,我想 suhosin 在第二次禁止邮件。但我想你已经看够了 RFC2822确切知道消息格式中需要空白行的位置,这样您就可以 turn off suhosin's mail() protection ,假设您确信自己没有任何可远程利用的注入(inject)漏洞。

关于linux - 发送 fpdf 附件在我的 linux suse 服务器上不起作用,但它在我的共享主机帐户上起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5410910/

相关文章:

linux - 使用 Awk 处理每条记录具有不同固定宽度字段的文件

c# - 从 C# 发送带有附件的电子邮件,附件作为 Thunderbird 的第 1.2 部分到达

javascript - 制作电子邮件表格 发送电子邮件

c# - 在 ASP.NET 中以编程方式发送带附件的邮件

php - 从分类法和日期压缩附加图像

Java执行需要su的Linux命令?

java - 在linux上配置多个java

linux - 不支持 mkvmerge linux 命令向后拆分

php - 更改 phpmailer 的发件人地址

vba - 用于在 Gmail 中撰写带有附件的邮件的 URL