发送 fpdf 附件在我的 linux suse 服务器上不起作用,但在我的共享托管帐户上起作用
我有一个在互联网上开发的 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 = "[email protected]";
$from = "[email protected]";
$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 上发送电子邮件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)
I have a php program i have developed on the internet. So far i have used a shared hosting package. Everything worked until i moved to a vps (apache2 suse 9.1 plesk) . I have found certain php functions have not been activated. I have solved most of them by using the internet.
My main problem is emailing pdfs with fpdf. i.e
<?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 = "[email protected]";
$from = "[email protected]";
$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>');
}
?>
The file above works on my share hosting , but when it comes to sending from my vps i get this error message from my file
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)
after much trial, the error is from this line
if (@mail($to, $subject, "",$headers))
If i remove the "", it sends the email on my vps but there is no attachment. this also happens on my shared account. The attachment ends up in the message with a hole load of chars'.
So i def need them in there. does anyone have a clue how to overcome this problem.
many thanks
after setting suhosin.ini to 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
$headers
中有大量的.$eol.$eol
,我想 suhosin 会禁止第二个实例的邮件。但我想您已经足够了解 RFC2822 来确切知道在哪里需要空行您的消息格式,因此您可以关闭suhosin的邮件( )
保护,假设您确信自己没有任何可远程利用的注入漏洞。You have an awful lot of
.$eol.$eol
in your$headers
, and I imagine suhosin is forbidding the mail on the second instance. But I presume you've looked enough at RFC2822 to know exactly where you need blank lines in your message formatting, so you can turn off suhosin'smail()
protection, assuming you're confident that you don't have any remotely exploitable injection vulnerabilities.