Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用mpdf发送pdf电子邮件?_Php_Pdf Generation_Email_Mpdf - Fatal编程技术网

Php 如何使用mpdf发送pdf电子邮件?

Php 如何使用mpdf发送pdf电子邮件?,php,pdf-generation,email,mpdf,Php,Pdf Generation,Email,Mpdf,我使用mpdf创建pdf的示例代码是(它工作正常) 发送电子邮件的示例编码: $em =//email address ; $subject = //subject; $message = //message; mail($em, $subject, $message, "From: MyDomain Webmaster<admin@mydomain.com>\nX-Mailer: PHP/" . phpversion()); $em=//电子

我使用mpdf创建pdf的示例代码是(它工作正常)


发送电子邮件的示例编码:

    $em =//email address ;
    $subject = //subject;
    $message = //message;

    mail($em, $subject, $message, "From: MyDomain Webmaster<admin@mydomain.com>\nX-Mailer: PHP/" . phpversion());
$em=//电子邮件地址;
$subject=//主题;
$message=//消息;
邮件($em,$subject,$message,“From:MyDomain-Webmaster\nX-Mailer:PHP/”.phpversion());
我的问题是pdf是直接在浏览器中创建和打开的,如何将pdf文件作为电子邮件附件发送

如果可能的话,请帮助我的代码或只是帮我一些建议,我会自己编码

谢谢

从回程机器(上面的链接):


    $em =//email address ;
    $subject = //subject;
    $message = //message;

    mail($em, $subject, $message, "From: MyDomain Webmaster<admin@mydomain.com>\nX-Mailer: PHP/" . phpversion());
<?php

include("../mpdf.php"); //Include mPDF Class 

$mpdf=new mPDF(); // Create new mPDF Document

//Beginning Buffer to save PHP variables and HTML tags
ob_start(); 

// Function Date
$day = date('d');
$month = date('m');
$year = date('Y');

switch ($month)
{ 
case 1: $month = "January"; break;
case 2: $month = "February"; break;
case 3: $month = "March"; break;
case 4: $month = "April"; break;
case 5: $month = "May"; break;
case 6: $month = "June"; break;
case 7: $month = "July"; break;
case 8: $month = "August"; break;
case 9: $month = "September"; break;
case 10: $month = "October"; break;
case 11: $month = "November"; break;
case 12: $month = "December"; break;
}

echo "Hello World
Today is $month $day, $year";

$html = ob_get_contents();
ob_end_clean();
//Here convert the encode for UTF-8, if you prefer the ISO-8859-1 just change for $mpdf->WriteHTML($html);
$mpdf->WriteHTML(utf8_encode($html)); 

$content = $mpdf->Output('', 'S');

$content = chunk_split(base64_encode($content));
$mailto = 'mailto@mailto.com'; //Mailto here
$from_name = 'ACME Corps Ltd'; //Name of sender mail
$from_mail = 'mailfrom@mailfrom.com'; //Mailfrom here
$subject = 'subjecthere'; 
$message = 'mailmessage';
$filename = "yourfilename-".date("d-m-Y_H-i",time()); //Your Filename with local date and time

//Headers of PDF and e-mail
$boundary = "XYZ-" . date("dmYis") . "-ZYX"; 

$header = "--$boundary\r\n"; 
$header .= "Content-Transfer-Encoding: 8bits\r\n"; 
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n\r\n"; // or utf-8
$header .= "$message\r\n";
$header .= "--$boundary\r\n";
$header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n\r\n";
$header .= "$content\r\n"; 
$header .= "--$boundary--\r\n";

$header2 = "MIME-Version: 1.0\r\n";
$header2 .= "From: ".$from_name." \r\n"; 
$header2 .= "Return-Path: $from_mail\r\n";
$header2 .= "Content-type: multipart/mixed; boundary=\"$boundary\"\r\n";
$header2 .= "$boundary\r\n";

mail($mailto,$subject,$header,$header2, "-r".$from_mail);

$mpdf->Output($filename ,'I');
exit;

?>