将带有自定义名称的pdf附加到电子邮件并使用dompdf和phpmailer发送

时间:2019-11-07 19:21:08

标签: php phpmailer dompdf

我需要使用phpmailer将使用自定义名称dompdf创建的pdf附加到电子邮件。我无法弄清楚如何用自定义名称附加pdf。该名称是使用表格和当前日期中的申请人名称生成的。因此,每次创建新的pdf时,它都会使用不同的名称。如果他们都被保存了  使用相同的名称我可以使它正常工作

    $dompdf->setPaper('letter', 'portrait');
    $dompdf->render();
    $dompdf->get_canvas()->get_cpdf()->setEncryption("slick1", "slick1");
    $output = $dompdf->output();
    //$name = $_POST['name'].date('m-d-Y_h:i:sa');
    $name = $_POST['applicant-name'].date('m-d-Y');
    file_put_contents($name, $output);
    // file_put_contents('Application.pdf', $output);
    // $dompdf->stream("",array("Attachment" => false));
    // exit(0);
}

$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPAuth = true;
$mail->Username = 'email@gmail.com';
$mail->Password = 'password';
$mail->setFrom('info@hpaoffice.com');
$mail->addReplyTo('office@hpaoffice.com', '$name');
$mail->addAddress('stratton@officecomputer.com', 'Stratton Weekley');
$mail->Subject = 'Rental Application';
$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
$mail->AltBody = 'Notifying you that an application has been filled and and is included as an attachment in this email';
$mail->addAttachment('$name.pdf');

if (!$mail->send()) {
    echo 'Mailer Error: '.$mail->ErrorInfo;
} else {
    echo 'Message Sent!';
}

0 个答案:

没有答案