尝试发送带有 pdf 附件的电子邮件,尝试使用 swiftmailer,但没有成功,此代码适用于 zip,但不适用于 PDF :(
$attachment = chunk_split(base64_encode(file_get_contents($filename)));
ob_start(); //Turn on output buffering
?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<?php echo $message."<br /><br />";
?>
--PHP-alt-<?php echo $random_hash; ?>--
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/octet-stream; name="<?php echo $filename?>"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="<?php echo $filename?>"
<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
邮件发送正常,我收到邮件:但附件不存在,并且在邮件中包含电子邮件中的所有 base64 编码,例如:
内容类型:应用程序/八位字节流;name="media.pdf" 内容传输编码:base64 内容处置:附件;文件名="媒体.pdf"