2016-10-25 3 views
0

저는 맨드릴을 처음 사용하고 있습니다. 맨드릴을 사용하여받는 사람에게 첨부 파일로 보낼 수있는 템플릿을 만들 수 있는지 궁금합니다. 예를 들어 동적 콘텐츠가 포함 된 다운로드 가능한 이벤트 티켓을 보내고 싶습니다. 나는 mandrill의 템플릿으로 이벤트 티켓을 디자인 할 생각이었습니다.동적 첨부 파일 맨드릴

내 코드 :

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

답변

0

당신은 다음의 첨부

<?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; 
} 
?> 
로 보낼 수 있습니다 PDF로 HTML을 변환 할 TCPDF 같은 라이브러리를 사용해서 렌더링 사용하여 HTML 결과를 반환 할 수 있습니다
관련 문제