getVars($options, "CRM_Mailing_Controller_Send_$qfKey"); //get the options if control come from search context, CRM-3711 if (empty($options)) { $session->getVars($options, "CRM_Contact_Controller_Search_$qfKey"); } // FIXME: the below and CRM_Mailing_Form_Test::testMail() // should be refactored $fromEmail = NULL; $mailing = new CRM_Mailing_BAO_Mailing(); if (!empty($options)) { $mailing->id = $options['mailing_id']; $fromEmail = CRM_Utils_Array::value('from_email', $options); } $mailing->find(TRUE); CRM_Mailing_BAO_Mailing::tokenReplace($mailing); // get and format attachments $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id ); //get details of contact with token value including Custom Field Token Values.CRM-3734 $returnProperties = $mailing->getReturnProperties(); $params = array('contact_id' => $session->get('userID')); $details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens(), get_class($this) ); $mime = &$mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, TRUE, $details[0][$session->get('userID')], $attachments ); if ($type == 'html') { header('Content-Type: text/html; charset=utf-8'); print $mime->getHTMLBody(); } else { header('Content-Type: text/plain; charset=utf-8'); print $mime->getTXTBody(); } CRM_Utils_System::civiExit(); } }