简体   繁体   English

动态附件山d

[英]Dynamic attachments mandrill

I am new to mandrill and just wondering can I use mandrill to create templates that I can send to recipients as attachments. 我是刚开始使用mandrill的人,只是想知道我是否可以使用mandrill创建可以作为附件发送给收件人的模板。 For instance if I wanted to send a downloadable event ticket with dynamic content. 例如,如果我想发送带有动态内容的可下载事件单。 I was thinking of designing the event ticket as a template in mandrill. 我当时正在考虑将活动票证设计为山d的模板。

My code: 我的代码:

$template_name = 'eventTicket';
$template_content = array(
    array(
        'name' => 'example name',
        'content' => 'example content'
         )
);

You can return HTML results using render then use a library like tcpdf to convert the html to pdf which you can then send as an attachment 您可以使用render返回HTML结果,然后使用tcpdf之类的库将html转换为pdf,然后将其作为附件发送

<?php
try {
$mandrill = new Mandrill('YOUR_API_KEY');
$template_name = 'Example Template';
$template_content = array(
    array(
        'name' => 'editable',
        'content' => '<div>content to inject *|MERGE1|*</div>'
    )
);
$merge_vars = array(
    array(
        'name' => 'merge1',
        'content' => 'merge1 content'
    )
);
$result = $mandrill->templates->render($template_name, $template_content, $merge_vars);
print_r($result);

// create new PDF document
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        // set font
        $pdf->SetFont('helvetica', '', 10);
        // set image scale factor
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

        // add a page
        $pdf->AddPage();
        // output the HTML content
        $pdf->writeHTML($result['html'], true, false, true, false, '');
        $file_name = 'filename.pdf';
        $path = $your_upload_path.$file_name;
        $pdf->Output($path,'F');


/*
Array
(
    [html] => content to inject merge1 content
)
*/
} catch(Mandrill_Error $e) {
// Mandrill errors are thrown as exceptions
echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
// A mandrill error occurred: Mandrill_Invalid_Key - Invalid API key
 throw $e;
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM