3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * a page for mailing preview
21 class CRM_Mailing_Page_Preview
extends CRM_Core_Page
{
24 * Run this page (figure out the action needed and perform it).
26 public function run() {
28 $session = CRM_Core_Session
::singleton();
30 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', CRM_Core_DAO
::$_nullObject, FALSE, 'text');
31 $type = CRM_Utils_Request
::retrieve('type', 'String', CRM_Core_DAO
::$_nullObject, FALSE, 'text');
34 $session->getVars($options, "CRM_Mailing_Controller_Send_$qfKey");
36 // get the options if control come from search context, CRM-3711
37 if (empty($options)) {
38 $session->getVars($options, "CRM_Contact_Controller_Search_$qfKey");
41 // FIXME: the below and CRM_Mailing_Form_Test::testMail()
42 // should be refactored
44 $mailing = new CRM_Mailing_BAO_Mailing();
45 if (!empty($options)) {
46 $mailing->id
= $options['mailing_id'];
47 $fromEmail = $options['from_email'] ??
NULL;
52 CRM_Mailing_BAO_Mailing
::tokenReplace($mailing);
54 // get and format attachments
55 $attachments = CRM_Core_BAO_File
::getEntityFile('civicrm_mailing',
59 // get details of contact with token value including Custom Field Token Values.CRM-3734
60 $returnProperties = $mailing->getReturnProperties();
61 $params = ['contact_id' => $session->get('userID')];
63 $details = CRM_Utils_Token
::getTokenDetails($params,
66 $mailing->getFlattenedTokens(),
69 // $details[0] is an array of [ contactID => contactDetails ]
70 $mime = &$mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail,
71 TRUE, $details[0][$session->get('userID')], $attachments
74 if ($type == 'html') {
75 CRM_Utils_System
::setHttpHeader('Content-Type', 'text/html; charset=utf-8');
76 print $mime->getHTMLBody();
79 CRM_Utils_System
::setHttpHeader('Content-Type', 'text/plain; charset=utf-8');
80 print $mime->getTXTBody();
82 CRM_Utils_System
::civiExit();