簡體   English   中英

使用dompdf將文件附加到php電子郵件中

[英]Attach file in php email using dompdf

我正在生成dpf並將其發送到電子郵件中,並且對我來說工作正常,但我只想附加上載到我的html表單中的文件。 我正在使用dompdf。

這是我的代碼:

$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];

$target = "uploads/"; 
$target1 = $target . basename($_FILES['pass_doc']['name']); 
//Here we check that $ok was not set to 0 by an error 
move_uploaded_file($_FILES['pass_doc']['tmp_name'], $target1);
$pass_doc = $_FILES['pass_doc']['name'];

$dir = dirname(__FILE__);

$pdf_html = "Name: $title $fname";

require_once($dir.'/dompdf/dompdf_config.inc.php');

        $dompdf = new DOMPDF(); // Create new instance of dompdf
        $dompdf->load_html($pdf_html); // Load the html
        $dompdf->render(); // Parse the html, convert to PDF
        $pdf_content = $dompdf->output(); // Put contents of pdf into variable for later

        // Get the contents of the HTML email into a variable for later
        ob_start();
        require_once($dir.'/html.php');
        $html_message = ob_get_contents();
        ob_end_clean();

        // Load the SwiftMailer files
        require_once($dir.'/swift/swift_required.php');

        $mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer

        $message = Swift_Message::newInstance()
                       ->setSubject('Student Inquiry from lsbuk.com') // Message subject
                       ->setTo(array('myemail@example.com')) // Array of people to send to
                       ->setFrom(array('no-reply@example.com' => 'LSBUK')) // From:
                       ->setBody($html_message, 'text/html') // Attach that HTML message from earlier
                       ->attach(Swift_Attachment::newInstance($pdf_content, 'studentadmission.pdf', 'newstudent/pdf')); // Attach the generated PDF from earlier

        // Send the email, and show user message
        if ($mailer->send($message))
            $success = true;
        else
            $error = true;

只想知道我還可以附加$ pass_doc嗎? 生成的pdf可以正常工作並且可以通過電子郵件發送,但不能通過$ pass_doc

謝謝

我已經把下面的代碼解決了:

->attach(Swift_Attachment::fromPath($pass_doc_path))

還是謝謝你

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM