本文整理汇总了PHP中CRM_Utils_Mail类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Mail类的具体用法?PHP CRM_Utils_Mail怎么用?PHP CRM_Utils_Mail使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Utils_Mail类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHookAlterMailer
public function testHookAlterMailer()
{
$test = $this;
$mockMailer = new CRM_Utils_FakeObject(array('send' => function ($recipients, $headers, $body) use($test) {
$test->calls['send']++;
$test->assertEquals(array('to@example.org'), $recipients);
$test->assertEquals('Subject Example', $headers['Subject']);
}));
CRM_Utils_Hook::singleton()->setHook('civicrm_alterMailer', function (&$mailer, $driver, $params) use($test, $mockMailer) {
$test->calls['civicrm_alterMailer']++;
$test->assertTrue(is_string($driver) && !empty($driver));
$test->assertTrue(is_array($params));
$test->assertTrue(is_callable(array($mailer, 'send')));
$mailer = $mockMailer;
});
$params = array();
$params['groupName'] = 'CRM_Core_Config_MailerTest';
$params['from'] = 'From Example <from@example.com>';
$params['toName'] = 'To Example';
$params['toEmail'] = 'to@example.org';
$params['subject'] = 'Subject Example';
$params['text'] = 'Example text';
$params['html'] = '<p>Example HTML</p>';
CRM_Utils_Mail::send($params);
$this->assertEquals(1, $this->calls['civicrm_alterMailer']);
$this->assertEquals(1, $this->calls['send']);
// once more, just to make sure the hooks are called right #times
CRM_Utils_Mail::send($params);
CRM_Utils_Mail::send($params);
$this->assertEquals(1, $this->calls['civicrm_alterMailer']);
$this->assertEquals(3, $this->calls['send']);
}
示例2: testFormatRFC822
/**
* test case for add( )
* test with empty params.
*/
function testFormatRFC822()
{
$values = array(array('name' => "Test User", 'email' => "foo@bar.com", 'result' => "Test User <foo@bar.com>"), array('name' => '"Test User"', 'email' => "foo@bar.com", 'result' => "Test User <foo@bar.com>"), array('name' => "User, Test", 'email' => "foo@bar.com", 'result' => '"User, Test" <foo@bar.com>'), array('name' => '"User, Test"', 'email' => "foo@bar.com", 'result' => '"User, Test" <foo@bar.com>'), array('name' => '"Test User"', 'email' => "foo@bar.com", 'result' => '"Test User" <foo@bar.com>', 'useQuote' => TRUE), array('name' => "User, Test", 'email' => "foo@bar.com", 'result' => '"User, Test" <foo@bar.com>', 'useQuote' => TRUE));
foreach ($values as $value) {
$result = CRM_Utils_Mail::formatRFC822Email($value['name'], $value['email'], CRM_Utils_Array::value('useQuote', $value, FALSE));
$this->assertEquals($result, $value['result'], 'Expected encoding does not match');
}
}
示例3: sendMailToParents
static function sendMailToParents($childID, $subjectTPL, $messageTPL, $templateVars, $additionalCC = null)
{
require_once 'SFS/Utils/Relationship.php';
$parentInfo = array();
SFS_Utils_Relationship::getParents($childID, $parentInfo, false);
// make sure we unset the older parents
for ($count = 1; $count < 5; $count++) {
$templateVars["parent_{$count}_Name"] = null;
}
$count = 1;
$toDisplayName = $toEmail = $cc = null;
foreach ($parentInfo as $parent) {
$templateVars["parent_{$count}_Name"] = $parent['name'];
if ($parent['email']) {
if (!$toEmail) {
$toDisplayName = $parent['name'];
$toEmail = $parent['email'];
} else {
if (!empty($cc)) {
$cc .= ", ";
}
$cc .= $parent['email'];
}
}
$count++;
}
if ($additionalCC) {
if (!empty($cc)) {
$cc .= ", ";
}
$cc .= $additionalCC;
}
// return if we dont have a toEmail
if (!$toEmail) {
return;
}
require_once 'SFS/Utils/Query.php';
list($templateVars['childName'], $templateVars['childEmail']) = SFS_Utils_Query::getNameAndEmail($childID);
$template = CRM_Core_Smarty::singleton();
$template->assign($templateVars);
require_once 'CRM/Utils/Mail.php';
require_once 'CRM/Utils/String.php';
$params = array('from' => self::SFS_FROM_EMAIL, 'toName' => $toDisplayName, 'toEmail' => $toEmail, 'subject' => $template->fetch($subjectTPL), 'text' => $template->fetch($messageTPL), 'cc' => $cc, 'bcc' => self::SFS_BCC_EMAIL);
CRM_Utils_Mail::send($params);
}
示例4: commonBuildQuickForm
/**
* @param $self
*/
public static function commonBuildQuickForm($self)
{
$contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $self);
if (!$contactId) {
$contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST);
}
$urlParams = "action=add&reset=1&cid={$contactId}&selectedChild=activity&atype=";
$activityTypes = $urls = array();
$emailTypeId = CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name');
$letterTypeId = CRM_Core_OptionGroup::getValue('activity_type', 'Print PDF Letter', 'name');
$SMSId = CRM_Core_OptionGroup::getValue('activity_type', 'Text Message (SMS)', 'label');
if (CRM_Utils_Mail::validOutBoundMail() && $contactId) {
list($name, $email, $doNotEmail, $onHold, $isDeseased) = CRM_Contact_BAO_Contact::getContactDetails($contactId);
if (!$doNotEmail && $email && !$isDeseased) {
$activityTypes = array($emailTypeId => ts('Send an Email'));
}
}
if ($contactId && CRM_SMS_BAO_Provider::activeProviderCount()) {
// Check for existence of a mobile phone and ! do not SMS privacy setting
$mobileTypeID = CRM_Core_OptionGroup::getValue('phone_type', 'Mobile', 'name');
list($name, $phone, $doNotSMS) = CRM_Contact_BAO_Contact_Location::getPhoneDetails($contactId, $mobileTypeID);
if (!$doNotSMS && $phone) {
$sendSMS = array($SMSId => ts('Send SMS'));
$activityTypes += $sendSMS;
}
}
// this returns activity types sorted by weight
$otherTypes = CRM_Core_PseudoConstant::activityType(FALSE);
$activityTypes += $otherTypes;
foreach (array_keys($activityTypes) as $typeId) {
if ($typeId == $emailTypeId) {
$urls[$typeId] = CRM_Utils_System::url('civicrm/activity/email/add', "{$urlParams}{$typeId}", FALSE, NULL, FALSE);
} elseif ($typeId == $SMSId) {
$urls[$typeId] = CRM_Utils_System::url('civicrm/activity/sms/add', "{$urlParams}{$typeId}", FALSE, NULL, FALSE);
} elseif ($typeId == $letterTypeId) {
$urls[$typeId] = CRM_Utils_System::url('civicrm/activity/pdf/add', "{$urlParams}{$typeId}", FALSE, NULL, FALSE);
} else {
$urls[$typeId] = CRM_Utils_System::url('civicrm/activity/add', "{$urlParams}{$typeId}", FALSE, NULL, FALSE);
}
}
$self->assign('activityTypes', $activityTypes);
$self->assign('urls', $urls);
$self->assign('suppressForm', TRUE);
}
示例5: testSend
/**
* Basic send.
*/
public function testSend()
{
$contact_params_1 = array('first_name' => substr(sha1(rand()), 0, 7), 'last_name' => 'Anderson', 'email' => substr(sha1(rand()), 0, 7) . '@example.org', 'contact_type' => 'Individual');
$contact_id_1 = $this->individualCreate($contact_params_1);
$contact_params_2 = array('first_name' => substr(sha1(rand()), 0, 7), 'last_name' => 'Xylophone', 'email' => substr(sha1(rand()), 0, 7) . '@example.org', 'contact_type' => 'Individual');
$contact_id_2 = $this->individualCreate($contact_params_2);
$subject = 'Test spool';
$params = array('from' => CRM_Utils_Mail::formatRFC822Email($contact_params_1['first_name'] . " " . $contact_params_1['last_name'], $contact_params_1['email']), 'toName' => $contact_params_2['first_name'] . " " . $contact_params_2['last_name'], 'toEmail' => $contact_params_2['email'], 'subject' => $subject, 'text' => self::$bodytext, 'html' => "<p>\n" . self::$bodytext . '</p>');
CRM_Utils_Mail::send($params);
$mail = $this->_mut->getMostRecentEmail('raw');
$this->assertContains("Subject: {$subject}", $mail);
$this->assertContains(self::$bodytext, $mail);
$mail = $this->_mut->getMostRecentEmail('ezc');
$this->assertEquals($subject, $mail->subject);
$this->assertContains($contact_params_1['email'], $mail->from->email, 'From address incorrect.');
$this->assertContains($contact_params_2['email'], $mail->to[0]->email, 'Recipient incorrect.');
$context = new ezcMailPartWalkContext(array(get_class($this), 'mailWalkCallback'));
$mail->walkParts($context, $mail);
}
示例6: processSignature
/**
* Take the signature form and send an email to the recipient.
*
* @param CRM_Campaign_Form_Petition_Signature $form
* The petition form.
*/
public function processSignature($form)
{
// Get the message.
$messageField = $this->findMessageField();
if ($messageField === FALSE) {
return;
}
$message = empty($form->_submitValues[$messageField]) ? $this->petitionEmailVal[$this->fields['Default_Message']] : $form->_submitValues[$messageField];
// If message is left empty and no default message, don't send anything.
if (empty($message)) {
return;
}
// Setup email message:
$mailParams = array('groupName' => 'Activity Email Sender', 'from' => $this->getSenderLine($form->_contactId), 'toName' => $this->petitionEmailVal[$this->fields['Recipient_Name']], 'toEmail' => $this->petitionEmailVal[$this->fields['Recipient_Email']], 'subject' => $this->petitionEmailVal[$this->fields['Subject']], 'text' => $message);
if (!CRM_Utils_Mail::send($mailParams)) {
CRM_Core_Session::setStatus(ts('Error sending message to %1', array('domain' => 'com.aghstrategies.petitionemail', 1 => $mailParams['toName'])));
} else {
CRM_Core_Session::setStatus(ts('Message sent successfully to %1', array('domain' => 'com.aghstrategies.petitionemail', 1 => $mailParams['toName'])));
}
parent::processSignature($form);
}
示例7: buildQuickForm
public function buildQuickForm()
{
$contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
$urlParams = "action=add&reset=1&cid={$contactId}&selectedChild=activity&atype=";
$url = CRM_Utils_System::url('civicrm/contact/view/activity', $urlParams, false, null, false);
$activityTypes = array();
require_once 'CRM/Utils/Mail.php';
if (CRM_Utils_Mail::validOutBoundMail() && $contactId) {
require_once 'CRM/Contact/BAO/Contact.php';
list($name, $email, $doNotEmail, $onHold, $isDeseased) = CRM_Contact_BAO_Contact::getContactDetails($contactId);
if (!$doNotEmail && $email && !$isDeseased) {
$activityTypes = array('3' => ts('Send an Email'));
}
}
// this returns activity types sorted by weight
$otherTypes = CRM_Core_PseudoConstant::activityType(false);
$activityTypes += $otherTypes;
$this->assign('activityTypes', $activityTypes);
$this->assign('url', $url);
$this->assign('suppressForm', true);
}
示例8: buildQuickForm
public function buildQuickForm()
{
$this->applyFilter('__ALL__', 'trim');
$contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
$urlParams = "action=add&reset=1&cid={$contactId}&selectedChild=activity&atype=";
$url = CRM_Utils_System::url('civicrm/contact/view/activity', $urlParams, false, null, false);
$activityType = CRM_Core_PseudoConstant::activityType(false);
$this->assign('emailSetting', false);
require_once 'CRM/Utils/Mail.php';
if (CRM_Utils_Mail::validOutBoundMail() && $contactId) {
$this->assign('emailSetting', true);
require_once 'CRM/Contact/BAO/Contact.php';
list($name, $email, $doNotEmail, $onHold, $isDeseased) = CRM_Contact_BAO_Contact::getContactDetails($contactId);
if (!$doNotEmail && $email && !$isDeseased) {
$activityType += array('3' => ts('Send an Email'));
}
}
$this->applyFilter('__ALL__', 'trim');
$this->add('select', 'other_activity', ts('Other Activities'), array('' => ts('- new activity -')) + $activityType, false, array('onchange' => "if (this.value) window.location='{$url}'+ this.value; else return false"));
$this->assign('suppressForm', true);
}
示例9: civicrm_api3_speakcivi_sendconfirm
function civicrm_api3_speakcivi_sendconfirm($params)
{
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
WHERE mt.id = %1 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['messageTemplateID'], 'String'));
$dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
$dao->fetch();
if (!$dao->N) {
CRM_Core_Error::fatal(ts('No such message template: id=%1.', array(1 => $params['messageTemplateID'])));
}
$confirmation_block_html = '';
$confirmation_block_text = '';
$language = $params['language'];
if ($params['confirmation_block']) {
$cgid = $params['contact_id'];
$aid = $params['activity_id'];
$campaign_id = $params['campaign_id'];
$hash = sha1(CIVICRM_SITE_KEY . $cgid);
$url_confirm_and_keep = CRM_Utils_System::url('civicrm/speakcivi/confirm', "id={$cgid}&aid={$aid}&cid={$campaign_id}&hash={$hash}&utm_source=civicrm&utm_medium=email&utm_campaign=speakout_confirm", true);
$url_confirm_and_not_receive = CRM_Utils_System::url('civicrm/speakcivi/optout', "id={$cgid}&aid={$aid}&cid={$campaign_id}&hash={$hash}&utm_source=civicrm&utm_medium=email&utm_campaign=speakout_optout", true);
$template = CRM_Core_Smarty::singleton();
$template->assign('url_confirm_and_keep', $url_confirm_and_keep);
$template->assign('url_confirm_and_not_receive', $url_confirm_and_not_receive);
$confirmation_block_html = $template->fetch('../templates/CRM/Speakcivi/Page/ConfirmationBlock.' . $language . '.html.tpl');
$confirmation_block_text = $template->fetch('../templates/CRM/Speakcivi/Page/ConfirmationBlock.' . $language . '.text.tpl');
$params['subject'] = getSubjectConfirm($language);
} else {
$params['subject'] = getSubjectImpact($language);
}
$params['html'] = str_replace("#CONFIRMATION_BLOCK", $confirmation_block_html, $dao->html);
$params['text'] = str_replace("#CONFIRMATION_BLOCK", $confirmation_block_text, $dao->text);
$params['format'] = $dao->format;
$dao->free();
$sent = CRM_Utils_Mail::send($params);
return civicrm_api3_create_success($sent, $params);
}
示例10: send
/**
* Implements Mail::send() function using the sendmail
* command-line binary.
*
* @param mixed $recipients Either a comma-seperated list of recipients
* (RFC822 compliant), or an array of recipients,
* each RFC822 valid. This may contain recipients not
* specified in the headers, for Bcc:, resending
* messages, etc.
*
* @param array $headers The array of headers to send with the mail, in an
* associative array, where the array key is the
* header name (ie, 'Subject'), and the array value
* is the header value (ie, 'test'). The header
* produced from those values would be 'Subject:
* test'.
*
* @param string $body The full text of the message body, including any
* Mime parts, etc.
*
* @return mixed Returns true on success, or a PEAR_Error
* containing a descriptive error message on
* failure.
* @access public
*/
function send($recipients, $headers, $body)
{
if (defined('CIVICRM_MAIL_LOG')) {
require_once 'CRM/Utils/Mail.php';
CRM_Utils_Mail::logger($recipients, $headers, $body);
return true;
}
if (!is_array($headers)) {
return PEAR::raiseError('$headers must be an array');
}
$result = $this->_sanitizeHeaders($headers);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
$recipients = $this->parseRecipients($recipients);
if (is_a($recipients, 'PEAR_Error')) {
return $recipients;
}
$recipients = implode(' ', array_map('escapeshellarg', $recipients));
$headerElements = $this->prepareHeaders($headers);
if (is_a($headerElements, 'PEAR_Error')) {
return $headerElements;
}
list($from, $text_headers) = $headerElements;
/* Since few MTAs are going to allow this header to be forged
* unless it's in the MAIL FROM: exchange, we'll use
* Return-Path instead of From: if it's set. */
if (!empty($headers['Return-Path'])) {
$from = $headers['Return-Path'];
}
if (!isset($from)) {
return PEAR::raiseError('No from address given.');
} elseif (strpos($from, ' ') !== false || strpos($from, ';') !== false || strpos($from, '&') !== false || strpos($from, '`') !== false) {
return PEAR::raiseError('From address specified with dangerous characters.');
}
$from = escapeshellarg($from);
// Security bug #16200
$mail = @popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f{$from} -- {$recipients}", 'w');
if (!$mail) {
return PEAR::raiseError('Failed to open sendmail [' . $this->sendmail_path . '] for execution.');
}
// Write the headers following by two newlines: one to end the headers
// section and a second to separate the headers block from the body.
fputs($mail, $text_headers . $this->sep . $this->sep);
fputs($mail, $body);
$result = pclose($mail);
if (version_compare(phpversion(), '4.2.3') == -1) {
// With older php versions, we need to shift the pclose
// result to get the exit code.
$result = $result >> 8 & 0xff;
}
if ($result != 0) {
return PEAR::raiseError('sendmail returned error code ' . $result, $result);
}
return true;
}
示例11: send_confirm_request
/**
* Ask a contact for subscription confirmation (opt-in)
*
* @param string $email
* The email address.
*
* @return void
*/
public function send_confirm_request($email)
{
$config = CRM_Core_Config::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$confirm = implode($config->verpSeparator, array($localpart . 'c', $this->contact_id, $this->id, $this->hash)) . "@{$emailDomain}";
$group = new CRM_Contact_BAO_Group();
$group->id = $this->group_id;
$group->find(TRUE);
$component = new CRM_Mailing_BAO_Component();
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Subscribe';
$component->find(TRUE);
$headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'To' => $email, 'Reply-To' => $confirm, 'Return-Path' => "do-not-reply@{$emailDomain}");
$url = CRM_Utils_System::url('civicrm/mailing/confirm', "reset=1&cid={$this->contact_id}&sid={$this->id}&h={$this->hash}", TRUE);
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
$bao = new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
$html = CRM_Utils_Token::replaceSubscribeTokens($html, $group->title, $url, TRUE);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
$text = CRM_Utils_Token::replaceSubscribeTokens($text, $group->title, $url, FALSE);
// render the & entities in text mode, so that the links work
$text = str_replace('&', '&', $text);
$message = new Mail_mime("\n");
$message->setHTMLBody($html);
$message->setTxtBody($text);
$b = CRM_Utils_Mail::setMimeParams($message);
$h = $message->headers($headers);
CRM_Mailing_BAO_Mailing::addMessageIdHeader($h, 's', $this->contact_id, $this->id, $this->hash);
$mailer = \Civi::service('pear_mail');
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$mailer->send($email, $h, $b);
unset($errorScope);
}
}
示例12: civicrm_api3_speakcivi_sendconfirm
function civicrm_api3_speakcivi_sendconfirm($params)
{
$confirmationBlock = $params['confirmation_block'];
$contactId = $params['contact_id'];
$campaignId = $params['campaign_id'];
$activityId = $params['activity_id'];
$campaignObj = new CRM_Speakcivi_Logic_Campaign($campaignId);
$locale = $campaignObj->getLanguage();
$params['from'] = $campaignObj->getSenderMail();
$params['format'] = null;
if ($confirmationBlock) {
$params['subject'] = $campaignObj->getSubjectNew();
$message = $campaignObj->getMessageNew();
} else {
$params['subject'] = $campaignObj->getSubjectCurrent();
$message = $campaignObj->getMessageCurrent();
}
if (!$message) {
if ($confirmationBlock) {
$message = CRM_Speakcivi_Tools_Dictionary::getMessageNew($locale);
$campaignObj->setCustomFieldBySQL($campaignId, $campaignObj->fieldMessageNew, $message);
} else {
$message = CRM_Speakcivi_Tools_Dictionary::getMessageCurrent($locale);
$campaignObj->setCustomFieldBySQL($campaignId, $campaignObj->fieldMessageCurrent, $message);
}
}
$contact = array();
$params_contact = array('id' => $contactId, 'sequential' => 1);
$result = civicrm_api3('Contact', 'get', $params_contact);
if ($result['count'] == 1) {
$contact = $result['values'][0];
}
/* CONFIRMATION_BLOCK */
$hash = sha1(CIVICRM_SITE_KEY . $contactId);
$utm_content = 'version_' . $contactId % 2;
$utm_campaign = $campaignObj->getUtmCampaign();
$url_confirm_and_keep = CRM_Utils_System::url('civicrm/speakcivi/confirm', "id={$contactId}&aid={$activityId}&cid={$campaignId}&hash={$hash}&utm_source=civicrm&utm_medium=email&utm_campaign={$utm_campaign}&utm_content={$utm_content}", true);
$url_confirm_and_not_receive = CRM_Utils_System::url('civicrm/speakcivi/optout', "id={$contactId}&aid={$activityId}&cid={$campaignId}&hash={$hash}&utm_source=civicrm&utm_medium=email&utm_campaign={$utm_campaign}&utm_content={$utm_content}", true);
$template = CRM_Core_Smarty::singleton();
$template->assign('url_confirm_and_keep', $url_confirm_and_keep);
$template->assign('url_confirm_and_not_receive', $url_confirm_and_not_receive);
$locales = getLocale($locale);
$confirmation_block_html = $template->fetch('../templates/CRM/Speakcivi/Page/ConfirmationBlock.' . $locales['html'] . '.html.tpl');
$confirmation_block_text = $template->fetch('../templates/CRM/Speakcivi/Page/ConfirmationBlock.' . $locales['text'] . '.text.tpl');
/* SHARING_BLOCK */
$template->clearTemplateVars();
$template->assign('url_campaign', $campaignObj->getUrlCampaign());
$template->assign('url_campaign_fb', prepareCleanUrl($campaignObj->getUrlCampaign()));
$template->assign('utm_campaign', $campaignObj->getUtmCampaign());
$template->assign('share_facebook', CRM_Speakcivi_Tools_Dictionary::getShareFacebook($locale));
$template->assign('share_twitter', CRM_Speakcivi_Tools_Dictionary::getShareTwitter($locale));
$template->assign('twitter_share_text', urlencode($campaignObj->getTwitterShareText()));
$sharing_block_html = $template->fetch('../templates/CRM/Speakcivi/Page/SharingBlock.html.tpl');
$template->clearTemplateVars();
$template->assign('contact', $contact);
$message = $template->fetch('string:' . $message);
$message_html = str_replace("#CONFIRMATION_BLOCK", html_entity_decode($confirmation_block_html), $message);
$message_text = str_replace("#CONFIRMATION_BLOCK", html_entity_decode($confirmation_block_text), $message);
$message_html = str_replace("#SHARING_BLOCK", html_entity_decode($sharing_block_html), $message_html);
$message_text = str_replace("#SHARING_BLOCK", html_entity_decode($sharing_block_html), $message_text);
$params['html'] = $message_html;
$params['text'] = convertHtmlToText($message_text);
$sent = CRM_Utils_Mail::send($params);
return civicrm_api3_create_success($sent, $params);
}
示例13: 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;
}
}
示例14: formRule
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param array $self
* Current form object.
*
* @return array
* array of errors / empty array.
*/
public static function formRule($fields, $files, $self)
{
$errors = array();
if ($self->_gName == 'case_status' && empty($fields['grouping'])) {
$errors['grouping'] = ts('Status class is a required field');
}
if (in_array($self->_gName, array('email_greeting', 'postal_greeting', 'addressee')) && empty($self->_defaultValues['is_reserved'])) {
$label = $fields['label'];
$condition = " AND v.label = '{$label}' ";
$values = CRM_Core_OptionGroup::values($self->_gName, FALSE, FALSE, FALSE, $condition, 'filter');
$checkContactOptions = TRUE;
if ($self->_id && $self->_defaultValues['contactOptions'] == $fields['contactOptions']) {
$checkContactOptions = FALSE;
}
if ($checkContactOptions && in_array($fields['contactOptions'], $values)) {
$errors['label'] = ts('This Label already exists in the database for the selected contact type.');
}
}
if ($self->_gName == 'from_email_address') {
$formEmail = CRM_Utils_Mail::pluckEmailFromHeader($fields['label']);
if (!CRM_Utils_Rule::email($formEmail)) {
$errors['label'] = ts('Please enter a valid email address.');
}
$formName = explode('"', $fields['label']);
if (empty($formName[1]) || count($formName) != 3) {
$errors['label'] = ts('Please follow the proper format for From Email Address');
}
}
$dataType = self::getOptionGroupDataType($self->_gName);
if ($dataType && $self->_gName !== 'activity_type') {
$validate = CRM_Utils_Type::validate($fields['value'], $dataType, FALSE);
if (!$validate) {
CRM_Core_Session::setStatus(ts('Data Type of the value field for this option value does not match ' . $dataType), ts('Value field Data Type mismatch'));
}
}
return $errors;
}
示例15: confirm
/**
* Confirm a pending subscription
*
* @param int $contact_id The id of the contact
* @param int $subscribe_id The id of the subscription event
* @param string $hash The hash
* @return boolean True on success
* @access public
* @static
*/
public static function confirm($contact_id, $subscribe_id, $hash)
{
require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
$se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
if (!$se) {
return false;
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$ce =& new CRM_Mailing_Event_BAO_Confirm();
$ce->event_subscribe_id = $se->id;
$ce->time_stamp = date('YmdHis');
$ce->save();
require_once 'CRM/Contact/BAO/GroupContact.php';
CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $ce->id);
$transaction->commit();
$config =& CRM_Core_Config::singleton();
require_once 'CRM/Core/BAO/Domain.php';
$domain =& CRM_Core_BAO_Domain::getDomain();
list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
require_once 'CRM/Contact/BAO/Contact/Location.php';
list($display_name, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($se->contact_id);
require_once 'CRM/Contact/DAO/Group.php';
$group =& new CRM_Contact_DAO_Group();
$group->id = $se->group_id;
$group->find(true);
require_once 'CRM/Mailing/BAO/Component.php';
$component =& new CRM_Mailing_BAO_Component();
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Welcome';
$component->find(true);
require_once 'CRM/Core/BAO/MailSettings.php';
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'To' => $email, 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}");
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
require_once 'CRM/Mailing/BAO/Mailing.php';
$bao =& new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
require_once 'CRM/Utils/Token.php';
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']);
$html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->title, true);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false, $tokens['text']);
$text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, false);
// we need to wrap Mail_mime because PEAR is apparently unable to fix
// a six-year-old bug (PEAR bug #30) in Mail_mime::_encodeHeaders()
// this fixes CRM-5466
require_once 'CRM/Utils/Mail/FixedMailMIME.php';
$message =& new CRM_Utils_Mail_FixedMailMIME("\n");
$message->setHTMLBody($html);
$message->setTxtBody($text);
$b =& CRM_Utils_Mail::setMimeParams($message);
$h =& $message->headers($headers);
$mailer =& $config->getMailer();
require_once 'CRM/Mailing/BAO/Mailing.php';
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler'));
if (is_object($mailer)) {
$mailer->send($email, $h, $b);
CRM_Core_Error::setCallback();
}
return $group->title;
}