当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Utils_Mail::appendPDF方法代码示例

本文整理汇总了PHP中CRM_Utils_Mail::appendPDF方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Mail::appendPDF方法的具体用法?PHP CRM_Utils_Mail::appendPDF怎么用?PHP CRM_Utils_Mail::appendPDF使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Utils_Mail的用法示例。


在下文中一共展示了CRM_Utils_Mail::appendPDF方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: emailLetter

 /**
  * Send pdf by email.
  *
  * @param array $contact
  * @param string $html
  *
  * @param $is_pdf
  * @param array $format
  * @param array $params
  *
  * @return bool
  */
 public static function emailLetter($contact, $html, $is_pdf, $format = array(), $params = array())
 {
     try {
         if (empty($contact['email'])) {
             return FALSE;
         }
         $mustBeEmpty = array('do_not_email', 'is_deceased', 'on_hold');
         foreach ($mustBeEmpty as $emptyField) {
             if (!empty($contact[$emptyField])) {
                 return FALSE;
             }
         }
         $defaults = array('toName' => $contact['display_name'], 'toEmail' => $contact['email'], 'text' => '', 'html' => $html);
         if (empty($params['from'])) {
             $emails = CRM_Core_BAO_Email::getFromEmail();
             $emails = array_keys($emails);
             $defaults['from'] = array_pop($emails);
         }
         if (!empty($params['subject'])) {
             $defaults['subject'] = $params['subject'];
         } else {
             $defaults['subject'] = ts('Thank you for your contribution/s');
         }
         if ($is_pdf) {
             $defaults['html'] = ts('Please see attached');
             $defaults['attachments'] = array(CRM_Utils_Mail::appendPDF('ThankYou.pdf', $html, $format));
         }
         $params = array_merge($defaults);
         return CRM_Utils_Mail::send($params);
     } catch (CRM_Core_Exception $e) {
         return FALSE;
     }
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:45,代码来源:PDFLetterCommon.php

示例2: sendTemplate


//.........这里部分代码省略.........
     $hookTokens = array();
     $mailing = new CRM_Mailing_BAO_Mailing();
     $mailing->subject = $mailContent['subject'];
     $mailing->body_text = $mailContent['text'];
     $mailing->body_html = $mailContent['html'];
     $tokens = $mailing->getTokens();
     CRM_Utils_Hook::tokens($hookTokens);
     $categories = array_keys($hookTokens);
     $contactID = CRM_Utils_Array::value('contactId', $params);
     if ($contactID) {
         $contactParams = array('contact_id' => $contactID);
         $returnProperties = array();
         if (isset($tokens['subject']['contact'])) {
             foreach ($tokens['subject']['contact'] as $name) {
                 $returnProperties[$name] = 1;
             }
         }
         if (isset($tokens['text']['contact'])) {
             foreach ($tokens['text']['contact'] as $name) {
                 $returnProperties[$name] = 1;
             }
         }
         if (isset($tokens['html']['contact'])) {
             foreach ($tokens['html']['contact'] as $name) {
                 $returnProperties[$name] = 1;
             }
         }
         // @todo CRM-17253 don't resolve contact details if there are no tokens
         // effectively comment out this next (performance-expensive) line
         // but unfortunately testing is a bit think on the ground to that needs to
         // be added.
         list($contact) = CRM_Utils_Token::getTokenDetails($contactParams, $returnProperties, FALSE, FALSE, NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
         $contact = $contact[$contactID];
     }
     $mailContent['subject'] = CRM_Utils_Token::replaceDomainTokens($mailContent['subject'], $domain, FALSE, $tokens['text'], TRUE);
     $mailContent['text'] = CRM_Utils_Token::replaceDomainTokens($mailContent['text'], $domain, FALSE, $tokens['text'], TRUE);
     $mailContent['html'] = CRM_Utils_Token::replaceDomainTokens($mailContent['html'], $domain, TRUE, $tokens['html'], TRUE);
     if ($contactID) {
         $mailContent['subject'] = CRM_Utils_Token::replaceContactTokens($mailContent['subject'], $contact, FALSE, $tokens['text'], FALSE, TRUE);
         $mailContent['text'] = CRM_Utils_Token::replaceContactTokens($mailContent['text'], $contact, FALSE, $tokens['text'], FALSE, TRUE);
         $mailContent['html'] = CRM_Utils_Token::replaceContactTokens($mailContent['html'], $contact, FALSE, $tokens['html'], FALSE, TRUE);
         $contactArray = array($contactID => $contact);
         CRM_Utils_Hook::tokenValues($contactArray, array($contactID), NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
         $contact = $contactArray[$contactID];
         $mailContent['subject'] = CRM_Utils_Token::replaceHookTokens($mailContent['subject'], $contact, $categories, TRUE);
         $mailContent['text'] = CRM_Utils_Token::replaceHookTokens($mailContent['text'], $contact, $categories, TRUE);
         $mailContent['html'] = CRM_Utils_Token::replaceHookTokens($mailContent['html'], $contact, $categories, TRUE);
     }
     // strip whitespace from ends and turn into a single line
     $mailContent['subject'] = "{strip}{$mailContent['subject']}{/strip}";
     // parse the three elements with Smarty
     $smarty = CRM_Core_Smarty::singleton();
     foreach ($params['tplParams'] as $name => $value) {
         $smarty->assign($name, $value);
     }
     foreach (array('subject', 'text', 'html') as $elem) {
         $mailContent[$elem] = $smarty->fetch("string:{$mailContent[$elem]}");
     }
     // send the template, honouring the target user’s preferences (if any)
     $sent = FALSE;
     // create the params array
     $params['subject'] = $mailContent['subject'];
     $params['text'] = $mailContent['text'];
     $params['html'] = $mailContent['html'];
     if ($params['toEmail']) {
         $contactParams = array(array('email', 'LIKE', $params['toEmail'], 0, 1));
         list($contact, $_) = CRM_Contact_BAO_Query::apiQuery($contactParams);
         $prefs = array_pop($contact);
         if (isset($prefs['preferred_mail_format']) and $prefs['preferred_mail_format'] == 'HTML') {
             $params['text'] = NULL;
         }
         if (isset($prefs['preferred_mail_format']) and $prefs['preferred_mail_format'] == 'Text') {
             $params['html'] = NULL;
         }
         $config = CRM_Core_Config::singleton();
         if (isset($params['isEmailPdf']) && $params['isEmailPdf'] == 1) {
             $pdfHtml = CRM_Contribute_BAO_ContributionPage::addInvoicePdfToEmail($params['contributionId'], $params['contactId']);
             if (empty($params['attachments'])) {
                 $params['attachments'] = array();
             }
             $params['attachments'][] = CRM_Utils_Mail::appendPDF('Invoice.pdf', $pdfHtml, $mailContent['format']);
         }
         $pdf_filename = '';
         if ($config->doNotAttachPDFReceipt && $params['PDFFilename'] && $params['html']) {
             if (empty($params['attachments'])) {
                 $params['attachments'] = array();
             }
             $params['attachments'][] = CRM_Utils_Mail::appendPDF($params['PDFFilename'], $params['html'], $mailContent['format']);
             if (isset($params['tplParams']['email_comment'])) {
                 $params['html'] = $params['tplParams']['email_comment'];
                 $params['text'] = strip_tags($params['tplParams']['email_comment']);
             }
         }
         $sent = CRM_Utils_Mail::send($params);
         if ($pdf_filename) {
             unlink($pdf_filename);
         }
     }
     return array($sent, $mailContent['subject'], $mailContent['text'], $mailContent['html']);
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:101,代码来源:MessageTemplate.php


注:本文中的CRM_Utils_Mail::appendPDF方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。