我正在使用邮件中的PDF附件任务。邮件正在为我工作,但我无法附上邮件的PDF。
PDF路径没有问题,因为我尝试将PNG和JPG图像作为附件,并且它们正在工作。我尝试了很多,但仍然没有得到任何解决方案。
任何人都可以查看代码并为我提供解决方案吗?
这是我的代码
$html2pdf = new HTML2PDF('P', 'A4', 'fr');
//$html2pdf->setModeDebug();
$html2pdf->setDefaultFont('Arial');
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
$pdfName = time().'.pdf';
$invoicePath = WP_CONTENT_DIR.'/uploads/invoice/'.$pdfName;
$html2pdf->Output($invoicePath,'F');
$userInfo = wp_get_current_user();
$userEmail = $userInfo->data->user_email;
$userID = $userInfo->data->ID;
$attachments = $invoicePath; //array("C:\xampp\htdocs\moca_website\wp-content\uploads\invoice\1482234745.pdf");
$separator = md5(time());
$eol = PHP_EOL;
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers[] = 'From: '.get_option( 'blogname' ).' <'.get_option( 'admin_email' ).'>'.PHP_EOL;
$headers[]= "MIME-Version: 1.0".PHP_EOL;
$headers[]= "Content-Type: multipart/mixed; boundary= '".$mime_boundary."' ".PHP_EOL; // see below
$headers[]= "Content-Transfer-Encoding: 7bit".PHP_EOL;
$subject = "Invoice";
$content = 'Please <a href="'.$attachmentLink.'">click</a> here for invoice';
wp_mail( $userEmail,$subject, $content, $headers, $attachments="" );
$message = "Your invoice sent to your email";