随时随地创建一个pdf并通过swiftmailer发送

时间:2017-05-01 08:10:10

标签: php drupal tcpdf swiftmailer

我正在尝试使用TCPDF创建PDF并通过SwiftMailer发送,因为Drupal Mail不允许附件。这是我当前的代码:

public function getPdfReport($document){
    $html = '<head>'.document["body"].'</head>'.'<body>'.document["head"].'</body>';
    $tcpdf = tcpdf_get_instance();
    $tcpdf->DrupalInitialize(array(
  'footer' => array(
    'html' => 'This is a test!! <em>Bottom of the page</em>',
  ),
  'header' => array(
    'callback' => array(
      'function' => 'tcpdf_example_default_header',
      'context' => array(
        'welcome_message' => 'Hello, tcpdf example!',
      ),
    ),
  ),
));
$tcpdf->writeHTML($document);

    return  $pdf->Output('', 'S');
}
public function sendReportEmail($name,$to, $langcode,$attachment){
    $mailManager = \Drupal::service('plugin.manager.mail');
    $send = true;
    $module = 'order';
    $key = 'updated_password';

    $result = $mailManager->mail($module, $key, $to, $langcode, $this->getEmail($langcode, $name, $attachment), NULL, true);
}
private function getEmail($lang, $name,$attachment){
    $message = null;
    $pdfFile = new stdClass();
    $pdfFile->uri = $this->getPdfReport($attachment);
    $pdfFile->filename = 'EVG_invoice.pdf';
    $pdfFile->filemime = 'application/pdf';
    $message["files"] = $pdfFile;
    if($lang=="en"){
        $message["message"] = "
Dear ".$name.",

You successfully completed your online order.
Attached you can find a summary of your order.
Please print attached file and send it with your samples.";

$message["title"] = "order summary";}
return $message;
}

我在这里遗漏了什么吗? SwiftMailer在Drupal中设置为默认值。钥匙和模块也很好。

0 个答案:

没有答案