首页 > 解决方案 > 如何在电子邮件中发送嵌入的pdf

问题描述

我正在尝试在电子邮件中嵌入 pdf。不是链接。我的邮件功能正在运行,我可以回显 pdf,但 pdf 没有出现在电子邮件中。这是我到目前为止所拥有的:

邮件功能:

function mailerExpressBlueHostSWAGpdf(array $mailInputs){
   
   chdir('../');       
   require_once '../includes/phpmailer/PHPMailerAutoload.php';

   $mail = new PHPMailer();
   $mail->IsMail();   
   $mail->SetFrom('swag@sustainablewestonma.org');
   $mail->addAddress($mailInputs['addAddress']);   

   $body = $mailInputs['body'] ;
   
   $mail->Subject = "SWAG Fall Newsletter" ;
   $mail->Body    = $body;
   $mail->IsHTML(true);
   $mail->ContentType="text/HTML";  
      
   if(!$mail->send()) {
      // echo 'mail not sent <br>' ;
      $mail->ClearAddresses();
      return 'Message could not be sent.' . 'Mailer Error: ' . $mail->ErrorInfo;
   }else{
      // echo 'mail sent 2<br>';
      echo $body;
      $mail->ClearAddresses();
      return 'Message has been sent';
   }
}

电子邮件的 HTML (email-embed-pdf.html)

<!DOCTYPE html>
<html>
    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title></title>
    </head>
    <body>
        <div>
            <iframe src="https://www.sustainablewestonma.org/newsletter-fall2021.pdf"></iframe>
        </div>
    </body>
</html>

发送电子邮件的程序 (embed-pdf.php)

<?php

require ("../../includes/functions.php");
require ("../../includes/newConstants.php");


$body = file_get_contents('../../vhtml/email-embed-pdf.html');


$mailerInputs['body'] = $body;
$mailerInputs['addAddress'] = "abc123@gmail.com";
mailerExpressBlueHostSWAGpdf($mailerInputs);

?>

标签: phpemailpdfembed

解决方案


推荐阅读