繁体   English   中英

电子邮件pdf附件+来自服务器的附件

[英]Email pdf attachment + attachment from server

我想用一封电子邮件发送2个附件。 第一个来自fpdf类。 这很完美。 现在,第二个附件需要来自服务器上的文件夹。 但是我似乎无法正确发送它。

这是我的代码

$to = $email; 
$from = $user_data['email']; 
$subject = $onderwerp; 
$message = $body;

$separator = md5(time());

$eol = PHP_EOL;

$fileatt = $user_data['verklaring'];  // post variable path to the file
$fileatt_type = "application/pdf"; // File Type
$fileatt_name = 'VAR verklaring ' . $user_data['voornaam'] . ' ' .  $user_data['achternaam'];
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$data = chunk_split(base64_encode($data));

$filename = $factuur_data['factuur_nr'] . '.pdf';
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));

$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;

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

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

$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."--";

mail($to, $subject, "", $headers);

我搜索了许多主题,并且尝试将这些解决方案集成到我的代码中,如上面所示,但收效甚微。

乍一看,发送邮件并不容易。 我建议使用像swiftmailer这样的功能强大的库,而不要自己实现:

看看: http : //swiftmailer.org/docs/messages.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM