本文整理汇总了PHP中CRM_Core_BAO_MailSettings类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_MailSettings类的具体用法?PHP CRM_Core_BAO_MailSettings怎么用?PHP CRM_Core_BAO_MailSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Core_BAO_MailSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preProcess
/**
* Set variables up before form is built.
*
* @return void
*/
public function preProcess()
{
if (CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG") {
CRM_Core_Error::fatal(ts('The <a href="%1">default mailbox</a> has not been configured. You will find <a href="%2">more info in our online user and administrator guide.</a>', array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', 'reset=1'), 2 => "http://book.civicrm.org/user/advanced-configuration/email-system-configuration/")));
}
$this->_mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL);
// when user come from search context.
$this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context'));
if ($this->_searchBasedMailing) {
$searchParams = $this->controller->exportValues();
// number of records that were selected - All or Few.
$this->_resultSelectOption = $searchParams['radio_ts'];
if (CRM_Utils_Array::value('task', $searchParams) == 20) {
parent::preProcess();
}
}
$session = CRM_Core_Session::singleton();
if ($this->_searchBasedMailing) {
$config = CRM_Core_Config::singleton();
$path = CRM_Utils_Array::value($config->userFrameworkURLVar, $_GET);
$qfKey = CRM_Utils_Array::value('qfKey', $_GET);
if ($qfKey) {
$session->pushUserContext(CRM_Utils_System::url($path, "qfKey={$qfKey}"));
} else {
$session->pushUserContext(CRM_Utils_System::url('civicrm/mailing', 'reset=1'));
}
} elseif (strpos($session->readUserContext(), 'civicrm/mailing') === FALSE) {
// use previous context unless mailing is not schedule, CRM-4290
$session->pushUserContext(CRM_Utils_System::url('civicrm/mailing', 'reset=1'));
}
}
示例2: send
static function send($from, $toDisplayName, $toEmail, $subject, $text_message = null, $cc = null, $bcc = null, $replyTo = null, $html_message = null, $attachments = null)
{
require_once 'CRM/Core/BAO/MailSettings.php';
$returnPath = CRM_Core_BAO_MailSettings::defaultReturnPath();
if (!$returnPath) {
$returnPath = self::pluckEmailFromHeader($from);
}
$headers = array();
$headers['From'] = $from;
$headers['To'] = "{$toDisplayName} <{$toEmail}>";
$headers['Cc'] = $cc;
$headers['Subject'] = $subject;
$headers['Content-Type'] = $html_message ? 'multipart/mixed; charset=utf-8' : 'text/plain; charset=utf-8';
$headers['Content-Disposition'] = 'inline';
$headers['Content-Transfer-Encoding'] = '8bit';
$headers['Return-Path'] = $returnPath;
$headers['Reply-To'] = isset($replyTo) ? $replyTo : $from;
$headers['Date'] = date('r');
$to = array($toEmail);
if ($cc) {
$to[] = $cc;
}
if ($bcc) {
$to[] = $bcc;
}
// 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-4631
require_once 'CRM/Utils/Mail/FixedMailMIME.php';
$msg = new CRM_Utils_Mail_FixedMailMIME("\n");
if ($text_message) {
$msg->setTxtBody($text_message);
}
if ($html_message) {
$msg->setHTMLBody($html_message);
}
if (!empty($attachments)) {
foreach ($attachments as $fileID => $attach) {
$msg->addAttachment($attach['fullPath'], $attach['mime_type'], $attach['cleanName']);
}
}
$message = self::setMimeParams($msg);
$headers =& $msg->headers($headers);
$result = null;
$mailer =& CRM_Core_Config::getMailer();
CRM_Core_Error::ignoreException();
if (is_object($mailer)) {
$result = $mailer->send($to, $headers, $message);
CRM_Core_Error::setCallback();
if (is_a($result, 'PEAR_Error')) {
$message = self::errorMessage($mailer, $result);
CRM_Core_Session::setStatus($message, false);
return false;
}
return true;
}
return false;
}
示例3: testCreateUpdateMailSettings
/**
* Test caches cleared adequately.
*/
public function testCreateUpdateMailSettings()
{
$result = $this->callAPISuccess('MailSettings', 'create', $this->params);
$this->assertEquals('setting.com', CRM_Core_BAO_MailSettings::defaultDomain());
$this->callAPISuccess('mail_settings', 'create', array('id' => $result['id'], 'domain' => 'updated.com'));
$this->assertEquals('updated.com', CRM_Core_BAO_MailSettings::defaultDomain());
$this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
$this->callAPISuccessGetCount('mail_settings', array(), 1);
}
示例4: run
/**
* Run dashboard
*
* @return none
* @access public
*/
function run()
{
$resetCache = CRM_Utils_Request::retrieve('resetCache', 'Positive', CRM_Core_DAO::$_nullObject);
if ($resetCache) {
CRM_Core_BAO_Dashboard::resetDashletCache();
}
CRM_Utils_System::setTitle(ts('CiviCRM Home'));
$session = CRM_Core_Session::singleton();
$contactID = $session->get('userID');
// call hook to get html from other modules
// ignored but needed to prevent warnings
$contentPlacement = CRM_Utils_Hook::DASHBOARD_BELOW;
$html = CRM_Utils_Hook::dashboard($contactID, $contentPlacement);
if (is_array($html)) {
$this->assign_by_ref('hookContent', $html);
$this->assign('hookContentPlacement', $contentPlacement);
}
//check that default FROM email address, owner (domain) organization name and default mailbox are configured.
$fromEmailOK = TRUE;
$ownerOrgOK = TRUE;
$defaultMailboxOK = TRUE;
// Don't put up notices if user doesn't have administer CiviCRM permission
if (CRM_Core_Permission::check('administer CiviCRM')) {
$destination = CRM_Utils_System::url('civicrm/dashboard', 'reset=1', FALSE, NULL, FALSE);
$destination = urlencode($destination);
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
if (!$domainEmailAddress || $domainEmailAddress == 'info@FIXME.ORG') {
$fixEmailUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1&civicrmDestination={$destination}");
$this->assign('fixEmailUrl', $fixEmailUrl);
$fromEmailOK = FALSE;
}
$domain = CRM_Core_BAO_Domain::getDomain();
$domainName = $domain->name;
if (!$domainName || $domainName == 'Default Domain Name') {
$fixOrgUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1&civicrmDestination={$destination}");
$this->assign('fixOrgUrl', $fixOrgUrl);
$ownerOrgOK = FALSE;
}
$config = CRM_Core_Config::singleton();
if (in_array('CiviMail', $config->enableComponents) && CRM_Core_BAO_MailSettings::defaultDomain() == "FIXME.ORG") {
$fixDefaultMailbox = CRM_Utils_System::url('civicrm/admin/mailSettings', "reset=1&civicrmDestination={$destination}");
$this->assign('fixDefaultMailbox', $fixDefaultMailbox);
$defaultMailboxOK = FALSE;
}
}
$this->assign('fromEmailOK', $fromEmailOK);
$this->assign('ownerOrgOK', $ownerOrgOK);
$this->assign('defaultMailboxOK', $defaultMailboxOK);
return parent::run();
}
示例5: preProcess
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess()
{
if (CRM_Core_BAO_MailSettings::defaultDomain() == "FIXME.ORG") {
CRM_Core_Error::fatal(ts('The <a href="%1">default mailbox</a> has not been configured. You will find <a href="%2">more info in our online user and administrator guide.</a>', array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', 'reset=1'), 2 => "http://book.civicrm.org/user/initial-set-up/email-system-configuration")));
}
//when user come from search context.
$this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context'));
if ($this->_searchBasedMailing) {
$searchParams = $this->controller->exportValues();
// number of records that were selected - All or Few.
$this->_resultSelectOption = $searchParams['radio_ts'];
if (CRM_Utils_Array::value('task', $searchParams) == 20) {
parent::preProcess();
}
}
// use previous context unless mailing is not schedule, CRM-4290
$session = CRM_Core_Session::singleton();
if (strpos($session->readUserContext(), 'civicrm/mailing') === FALSE) {
$session->pushUserContext(CRM_Utils_System::url('civicrm/mailing', 'reset=1'));
}
}
示例6: send
/**
* Wrapper function to send mail in CiviCRM. Hooks are called from this function. The input parameter
* is an associateive array which holds the values of field needed to send an email. These are:
*
* from : complete from envelope
* toName : name of person to send email
* toEmail : email address to send to
* cc : email addresses to cc
* bcc : email addresses to bcc
* subject : subject of the email
* text : text of the message
* html : html version of the message
* replyTo : reply-to header in the email
* attachments: an associative array of
* fullPath : complete pathname to the file
* mime_type: mime type of the attachment
* cleanName: the user friendly name of the attachmment
*
* @param array $params (by reference)
*
* @access public
*
* @return boolean true if a mail was sent, else false
*/
static function send(&$params)
{
$returnPath = CRM_Core_BAO_MailSettings::defaultReturnPath();
$includeMessageId = CRM_Core_BAO_MailSettings::includeMessageId();
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$from = CRM_Utils_Array::value('from', $params);
if (!$returnPath) {
$returnPath = self::pluckEmailFromHeader($from);
}
$params['returnPath'] = $returnPath;
// first call the mail alter hook
CRM_Utils_Hook::alterMailParams($params);
// check if any module has aborted mail sending
if (CRM_Utils_Array::value('abortMailSend', $params) || !CRM_Utils_Array::value('toEmail', $params)) {
return FALSE;
}
$textMessage = CRM_Utils_Array::value('text', $params);
$htmlMessage = CRM_Utils_Array::value('html', $params);
$attachments = CRM_Utils_Array::value('attachments', $params);
// CRM-6224
if (trim(CRM_Utils_String::htmlToText($htmlMessage)) == '') {
$htmlMessage = FALSE;
}
$headers = array();
// CRM-10699 support custom email headers
if (CRM_Utils_Array::value('headers', $params)) {
$headers = array_merge($headers, $params['headers']);
}
$headers['From'] = $params['from'];
$headers['To'] = self::formatRFC822Email(CRM_Utils_Array::value('toName', $params), CRM_Utils_Array::value('toEmail', $params), FALSE);
$headers['Cc'] = CRM_Utils_Array::value('cc', $params);
$headers['Bcc'] = CRM_Utils_Array::value('bcc', $params);
$headers['Subject'] = CRM_Utils_Array::value('subject', $params);
$headers['Content-Type'] = $htmlMessage ? 'multipart/mixed; charset=utf-8' : 'text/plain; charset=utf-8';
$headers['Content-Disposition'] = 'inline';
$headers['Content-Transfer-Encoding'] = '8bit';
$headers['Return-Path'] = CRM_Utils_Array::value('returnPath', $params);
// CRM-11295: Omit reply-to headers if empty; this avoids issues with overzealous mailservers
$replyTo = CRM_Utils_Array::value('replyTo', $params, $from);
if (!empty($replyTo)) {
$headers['Reply-To'] = $replyTo;
}
$headers['Date'] = date('r');
if ($includeMessageId) {
$headers['Message-ID'] = '<' . uniqid('civicrm_', TRUE) . "@{$emailDomain}>";
}
if (CRM_Utils_Array::value('autoSubmitted', $params)) {
$headers['Auto-Submitted'] = "Auto-Generated";
}
//make sure we has to have space, CRM-6977
foreach (array('From', 'To', 'Cc', 'Bcc', 'Reply-To', 'Return-Path') as $fld) {
if (isset($headers[$fld])) {
$headers[$fld] = str_replace('"<', '" <', $headers[$fld]);
}
}
// quote FROM, if comma is detected AND is not already quoted. CRM-7053
if (strpos($headers['From'], ',') !== FALSE) {
$from = explode(' <', $headers['From']);
$headers['From'] = self::formatRFC822Email($from[0], substr(trim($from[1]), 0, -1), TRUE);
}
require_once 'Mail/mime.php';
$msg = new Mail_mime("\n");
if ($textMessage) {
$msg->setTxtBody($textMessage);
}
if ($htmlMessage) {
$msg->setHTMLBody($htmlMessage);
}
if (!empty($attachments)) {
foreach ($attachments as $fileID => $attach) {
$msg->addAttachment($attach['fullPath'], $attach['mime_type'], $attach['cleanName']);
}
}
$message = self::setMimeParams($msg);
$headers =& $msg->headers($headers);
$to = array($params['toEmail']);
//.........这里部分代码省略.........
示例7: 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;
}
示例8: run
/**
* Run dashboard
*
* @return void
* @access public
*/
function run()
{
// Add dashboard js and css
$resources = CRM_Core_Resources::singleton();
$resources->addScriptFile('civicrm', 'packages/jquery/plugins/jquery.dashboard.js', 0, 'html-header', FALSE);
$resources->addStyleFile('civicrm', 'packages/jquery/css/dashboard.css');
$config = CRM_Core_Config::singleton();
// Add dashlet-specific js files
// TODO: Need a much better way of managing on-the-fly js requirements. Require.js perhaps?
// Checking if a specific dashlet is enabled is a pain and including the js here sucks anyway
// So here's a compromise:
if (in_array('CiviCase', $config->enableComponents)) {
$resources->addScriptFile('civicrm', 'templates/CRM/Case/Form/ActivityChangeStatus.js');
}
$resetCache = CRM_Utils_Request::retrieve('resetCache', 'Positive', CRM_Core_DAO::$_nullObject);
CRM_Utils_System::setTitle(ts('CiviCRM Home'));
$session = CRM_Core_Session::singleton();
$contactID = $session->get('userID');
if ($resetCache) {
CRM_Core_BAO_Dashboard::resetDashletCache($contactID);
}
// call hook to get html from other modules
// ignored but needed to prevent warnings
$contentPlacement = CRM_Utils_Hook::DASHBOARD_BELOW;
$html = CRM_Utils_Hook::dashboard($contactID, $contentPlacement);
if (is_array($html)) {
$this->assign_by_ref('hookContent', $html);
$this->assign('hookContentPlacement', $contentPlacement);
}
//check that default FROM email address, owner (domain) organization name and default mailbox are configured.
$fromEmailOK = TRUE;
$ownerOrgOK = TRUE;
$defaultMailboxOK = TRUE;
// Don't put up notices if user doesn't have administer CiviCRM permission
if (CRM_Core_Permission::check('administer CiviCRM')) {
$destination = CRM_Utils_System::url('civicrm/dashboard', 'reset=1', FALSE, NULL, FALSE);
$destination = urlencode($destination);
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
$fixEmailUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1&civicrmDestination={$destination}");
$this->assign('fixEmailUrl', $fixEmailUrl);
$fromEmailOK = FALSE;
}
$domain = CRM_Core_BAO_Domain::getDomain();
$domainName = $domain->name;
if (!$domainName || $domainName == 'Default Domain Name') {
$fixOrgUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1&civicrmDestination={$destination}");
$this->assign('fixOrgUrl', $fixOrgUrl);
$ownerOrgOK = FALSE;
}
if (in_array('CiviMail', $config->enableComponents) && CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG") {
$fixDefaultMailbox = CRM_Utils_System::url('civicrm/admin/mailSettings', "reset=1&civicrmDestination={$destination}");
$this->assign('fixDefaultMailbox', $fixDefaultMailbox);
$defaultMailboxOK = FALSE;
}
}
$this->assign('fromEmailOK', $fromEmailOK);
$this->assign('ownerOrgOK', $ownerOrgOK);
$this->assign('defaultMailboxOK', $defaultMailboxOK);
$communityMessages = CRM_Core_CommunityMessages::create();
if ($communityMessages->isEnabled()) {
$message = $communityMessages->pick();
if ($message) {
$this->assign('communityMessages', $communityMessages->evalMarkup($message['markup']));
}
}
return parent::run();
}
示例9: send
static function send(&$params)
{
require_once 'CRM/Core/BAO/MailSettings.php';
$returnPath = CRM_Core_BAO_MailSettings::defaultReturnPath();
$from = CRM_Utils_Array::value('from', $params);
if (!$returnPath) {
$returnPath = self::pluckEmailFromHeader($from);
}
$params['returnPath'] = $returnPath;
// first call the mail alter hook
require_once 'CRM/Utils/Hook.php';
CRM_Utils_Hook::alterMailParams($params);
// check if any module has aborted mail sending
if (CRM_Utils_Array::value('abortMailSend', $params) || !CRM_Utils_Array::value('toEmail', $params)) {
return false;
}
$textMessage = CRM_Utils_Array::value('text', $params);
$htmlMessage = CRM_Utils_Array::value('html', $params);
$attachments = CRM_Utils_Array::value('attachments', $params);
$headers = array();
$headers['From'] = $params['from'];
$headers['To'] = "{$params['toName']} <{$params['toEmail']}>";
$headers['Cc'] = CRM_Utils_Array::value('cc', $params);
$headers['Subject'] = CRM_Utils_Array::value('subject', $params);
$headers['Content-Type'] = $htmlMessage ? 'multipart/mixed; charset=utf-8' : 'text/plain; charset=utf-8';
$headers['Content-Disposition'] = 'inline';
$headers['Content-Transfer-Encoding'] = '8bit';
$headers['Return-Path'] = CRM_Utils_Array::value('returnPath', $params);
$headers['Reply-To'] = CRM_Utils_Array::value('replyTo', $params, $from);
$headers['Date'] = date('r');
$to = array($params['toEmail']);
if (CRM_Utils_Array::value('cc', $params)) {
$to[] = CRM_Utils_Array::value('cc', $params);
}
if (CRM_Utils_Array::value('bcc', $params)) {
$to[] = CRM_Utils_Array::value('bcc', $params);
}
// 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-4631
require_once 'CRM/Utils/Mail/FixedMailMIME.php';
$msg = new CRM_Utils_Mail_FixedMailMIME("\n");
if ($textMessage) {
$msg->setTxtBody($textMessage);
}
if ($htmlMessage) {
$msg->setHTMLBody($htmlMessage);
}
if (!empty($attachments)) {
foreach ($attachments as $fileID => $attach) {
$msg->addAttachment($attach['fullPath'], $attach['mime_type'], $attach['cleanName']);
}
}
$message = self::setMimeParams($msg);
$headers =& $msg->headers($headers);
$result = null;
$mailer =& CRM_Core_Config::getMailer();
CRM_Core_Error::ignoreException();
if (is_object($mailer)) {
$result = $mailer->send($to, $headers, $message);
CRM_Core_Error::setCallback();
if (is_a($result, 'PEAR_Error')) {
$message = self::errorMessage($mailer, $result);
CRM_Core_Session::setStatus($message, false);
return false;
}
return true;
}
return false;
}
示例10: 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)
{
$se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
if (!$se) {
return FALSE;
}
// before we proceed lets just check if this contact is already 'Added'
// if so, we should ignore this request and hence avoid sending multiple
// emails - CRM-11157
$details = CRM_Contact_BAO_GroupContact::getMembershipDetail($contact_id, $se->group_id);
if ($details && $details->status == 'Added') {
// This contact is already subscribed
// lets return the group title
return CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $se->group_id, 'title');
}
$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();
CRM_Contact_BAO_GroupContact::addContactsToGroup(array($contact_id), $se->group_id, 'Email', 'Added', $ce->id);
$transaction->commit();
$config = CRM_Core_Config::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
list($display_name, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($se->contact_id);
$group = new CRM_Contact_DAO_Group();
$group->id = $se->group_id;
$group->find(TRUE);
$component = new CRM_Mailing_BAO_Component();
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Welcome';
$component->find(TRUE);
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$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::replaceWelcomeTokens($html, $group->title, TRUE);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
$text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, FALSE);
$mailParams = array('groupName' => 'Mailing Event ' . $component->component_type, 'subject' => $component->subject, 'from' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'toEmail' => $email, 'toName' => $display_name, 'replyTo' => "do-not-reply@{$emailDomain}", 'returnPath' => "do-not-reply@{$emailDomain}", 'html' => $html, 'text' => $text);
// send - ignore errors because the desired status change has already been successful
$unused_result = CRM_Utils_Mail::send($mailParams);
return $group->title;
}
示例11: send_unsub_response
/**
* Send a reponse email informing the contact of the groups from which he
* has been unsubscribed.
*
* @param string $queue_id The queue event ID
* @param array $groups List of group IDs
* @param bool $is_domain Is this domain-level?
* @param int $job The job ID
* @return void
* @access public
* @static
*/
public static function send_unsub_response($queue_id, $groups, $is_domain = false, $job)
{
$config =& CRM_Core_Config::singleton();
$domain =& CRM_Core_BAO_Domain::getDomain();
$jobTable = CRM_Mailing_BAO_Job::getTableName();
$mailingTable = CRM_Mailing_DAO_Mailing::getTableName();
$contacts = CRM_Contact_DAO_Contact::getTableName();
$email = CRM_Core_DAO_Email::getTableName();
$queue = CRM_Mailing_Event_BAO_Queue::getTableName();
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$dao =& new CRM_Mailing_BAO_Mailing();
$dao->query(" SELECT * FROM {$mailingTable} \n INNER JOIN {$jobTable} ON\n {$jobTable}.mailing_id = {$mailingTable}.id \n WHERE {$jobTable}.id = {$job}");
$dao->fetch();
$component =& new CRM_Mailing_BAO_Component();
if ($is_domain) {
$component->id = $dao->optout_id;
} else {
$component->id = $dao->unsubscribe_id;
}
$component->find(true);
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
$eq =& new CRM_Core_DAO();
$eq->query("SELECT {$contacts}.preferred_mail_format as format,\n {$contacts}.id as contact_id,\n {$email}.email as email,\n {$queue}.hash as hash\n FROM {$contacts}\n INNER JOIN {$queue} ON {$queue}.contact_id = {$contacts}.id\n INNER JOIN {$email} ON {$queue}.email_id = {$email}.id\n WHERE {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
$eq->fetch();
if ($groups) {
foreach ($groups as $key => $value) {
if (!$value) {
unset($groups[$key]);
}
}
}
$message =& new Mail_Mime("\n");
list($addresses, $urls) = CRM_Mailing_BAO_Mailing::getVerpAndUrls($job, $queue_id, $eq->hash, $eq->email);
$bao =& new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
require_once 'CRM/Utils/Token.php';
if ($eq->format == 'HTML' || $eq->format == 'Both') {
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']);
$html = CRM_Utils_Token::replaceUnsubscribeTokens($html, $domain, $groups, true, $eq->contact_id, $eq->hash);
$html = CRM_Utils_Token::replaceActionTokens($html, $addresses, $urls, true, $tokens['html']);
$html = CRM_Utils_Token::replaceMailingTokens($html, $dao, null, $tokens['html']);
$message->setHTMLBody($html);
}
if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false, $tokens['text']);
$text = CRM_Utils_Token::replaceUnsubscribeTokens($text, $domain, $groups, false, $eq->contact_id, $eq->hash);
$text = CRM_Utils_Token::replaceActionTokens($text, $addresses, $urls, false, $tokens['text']);
$text = CRM_Utils_Token::replaceMailingTokens($text, $dao, null, $tokens['text']);
$message->setTxtBody($text);
}
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' => $eq->email, 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}");
$b =& CRM_Utils_Mail::setMimeParams($message);
$h =& $message->headers($headers);
$mailer =& $config->getMailer();
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler'));
if (is_object($mailer)) {
$mailer->send($eq->email, $h, $b);
CRM_Core_Error::setCallback();
}
}
示例12: autoRespond
/**
* Send an automated response
*
* @param object $mailing The mailing object
* @param int $queue_id The queue ID
* @param string $replyto Optional reply-to from the reply
* @return void
* @access private
* @static
*/
private static function autoRespond(&$mailing, $queue_id, $replyto)
{
$config =& CRM_Core_Config::singleton();
$contacts = CRM_Contact_DAO_Contact::getTableName();
$email = CRM_Core_DAO_Email::getTableName();
$queue = CRM_Mailing_Event_DAO_Queue::getTableName();
$eq =& new CRM_Core_DAO();
$eq->query("SELECT {$contacts}.preferred_mail_format as format,\n {$email}.email as email\n FROM {$contacts}\n INNER JOIN {$queue} ON {$queue}.contact_id = {$contacts}.id\n INNER JOIN {$email} ON {$queue}.email_id = {$email}.id\n WHERE {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
$eq->fetch();
$to = empty($replyto) ? $eq->email : $replyto;
$component =& new CRM_Mailing_BAO_Component();
$component->id = $mailing->reply_id;
$component->find(true);
$message =& new Mail_Mime("\n");
require_once 'CRM/Core/BAO/Domain.php';
$domain =& CRM_Core_BAO_Domain::getDomain();
list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
require_once 'CRM/Core/BAO/MailSettings.php';
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$headers = array('Subject' => $component->subject, 'To' => $to, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}");
/* TODO: do we need reply tokens? */
$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();
if ($eq->format == 'HTML' || $eq->format == 'Both') {
require_once 'CRM/Utils/Token.php';
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']);
$html = CRM_Utils_Token::replaceMailingTokens($html, $mailing, null, $tokens['html']);
$message->setHTMLBody($html);
}
if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
require_once 'CRM/Utils/Token.php';
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false, $tokens['text']);
$text = CRM_Utils_Token::replaceMailingTokens($text, $mailing, null, $tokens['text']);
$message->setTxtBody($text);
}
$b =& CRM_Utils_Mail::setMimeParams($message);
$h =& $message->headers($headers);
$mailer =& $config->getMailer();
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler'));
if (is_object($mailer)) {
$mailer->send($to, $h, $b);
CRM_Core_Error::setCallback();
}
}
示例13: checkDefaultMailbox
/**
* Checks if a default bounce handling mailbox is set up
* @return array
*/
public function checkDefaultMailbox()
{
$messages = array();
$config = CRM_Core_Config::singleton();
if (in_array('CiviMail', $config->enableComponents) && CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG") {
$message = new CRM_Utils_Check_Message(__FUNCTION__, ts('Please configure a <a href="%1">default mailbox</a> for CiviMail.', array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', "reset=1"))), ts('Configure Default Mailbox'), \Psr\Log\LogLevel::WARNING, 'fa-envelope');
$message->addHelp(ts('Learn more in the <a href="%1">user guide</a>', array(1 => 'http://book.civicrm.org/user/advanced-configuration/email-system-configuration/')));
$messages[] = $message;
}
return $messages;
}
示例14: sendEmail
/**
* takes an associative array and sends a thank you or email verification email
*
* @param array $params (reference ) an assoc array of name/value pairs
*
* @return
* @access public
* @static
*/
function sendEmail($params, $sendEmailMode)
{
/* sendEmailMode
* CRM_Campaign_Form_Petition_Signature::EMAIL_THANK
* connected user via login/pwd - thank you
* or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you
* or login using fb connect - thank you + click to add msg to fb wall
*
* CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM
* send a confirmation request email
*/
require_once 'CRM/Campaign/Form/Petition/Signature.php';
// define constant CIVICRM_PETITION_CONTACTS, if not exist in civicrm.settings.php
if (!defined('CIVICRM_PETITION_CONTACTS')) {
define('CIVICRM_PETITION_CONTACTS', 'Petition Contacts');
}
// check if the group defined by CIVICRM_PETITION_CONTACTS exists, else create it
require_once 'api/v2/Group.php';
$group_params['title'] = CIVICRM_PETITION_CONTACTS;
$groups = civicrm_group_get($group_params);
if (CRM_Utils_Array::value('is_error', $groups) == 1 && CRM_Utils_Array::value('error_message', $groups) == 'No such group exists') {
$group_params['is_active'] = 1;
$group_params['visibility'] = 'Public Pages';
$newgroup = civicrm_group_add($group_params);
if ($newgroup['is_error'] == 0) {
$group_id[0] = $newgroup['result'];
}
} else {
$group_id = array_keys($groups);
}
// get petition info
$petitionParams['id'] = $params['sid'];
$petitionInfo = array();
CRM_Campaign_BAO_Survey::retrieve($petitionParams, $petitionInfo);
if (empty($petitionInfo)) {
CRM_Core_Error::fatal('Petition doesn\'t exist.');
}
require_once 'CRM/Core/BAO/Domain.php';
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
require_once 'CRM/Core/BAO/MailSettings.php';
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
require_once 'CRM/Contact/BAO/Contact.php';
$toName = CRM_Contact_BAO_Contact::displayName($params['contactId']);
$replyTo = "do-not-reply@{$emailDomain}";
// set additional general message template params (custom tokens to use in email msg templates)
// tokens then available in msg template as {$petition.title}, etc
$petitionTokens['title'] = $petitionInfo['title'];
$petitionTokens['petitionId'] = $params['sid'];
$tplParams['petition'] = $petitionTokens;
switch ($sendEmailMode) {
case CRM_Campaign_Form_Petition_Signature::EMAIL_THANK:
//add this contact to the CIVICRM_PETITION_CONTACTS group
require_once 'api/v2/GroupContact.php';
$params['group_id'] = $group_id[0];
$params['contact_id'] = $params['contactId'];
civicrm_group_contact_add($params);
require_once 'CRM/Core/BAO/MessageTemplates.php';
if ($params['email-Primary']) {
CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_sign', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title']));
}
break;
case CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM:
// create mailing event subscription record for this contact
// this will allow using a hash key to confirm email address by sending a url link
require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
$se = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id[0], $params['email-Primary'], $params['contactId']);
// require_once 'CRM/Core/BAO/Domain.php';
// $domain =& CRM_Core_BAO_Domain::getDomain();
$config = CRM_Core_Config::singleton();
$localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
require_once 'CRM/Utils/Verp.php';
$replyTo = implode($config->verpSeparator, array($localpart . 'c', $se->contact_id, $se->id, $se->hash)) . "@{$emailDomain}";
$confirmUrl = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", true);
$confirmUrlPlainText = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", true, null, false);
// set email specific message template params and assign to tplParams
$petitionTokens['confirmUrl'] = $confirmUrl;
$petitionTokens['confirmUrlPlainText'] = $confirmUrlPlainText;
$tplParams['petition'] = $petitionTokens;
require_once 'CRM/Core/BAO/MessageTemplates.php';
if ($params['email-Primary']) {
CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_confirmation_needed', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'], 'confirmUrl' => $confirmUrl));
}
break;
}
}
示例15: autoRespond
/**
* Send an automated response.
*
* @param object $mailing
* The mailing object.
* @param int $queue_id
* The queue ID.
* @param string $replyto
* Optional reply-to from the reply.
*
* @return void
*/
private static function autoRespond(&$mailing, $queue_id, $replyto)
{
$config = CRM_Core_Config::singleton();
$contacts = CRM_Contact_DAO_Contact::getTableName();
$email = CRM_Core_DAO_Email::getTableName();
$queue = CRM_Mailing_Event_DAO_Queue::getTableName();
$eq = new CRM_Core_DAO();
$eq->query("SELECT {$contacts}.preferred_mail_format as format,\n {$email}.email as email,\n {$queue}.job_id as job_id,\n {$queue}.hash as hash\n FROM {$contacts}\n INNER JOIN {$queue} ON {$queue}.contact_id = {$contacts}.id\n INNER JOIN {$email} ON {$queue}.email_id = {$email}.id\n WHERE {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
$eq->fetch();
$to = empty($replyto) ? $eq->email : $replyto;
$component = new CRM_Mailing_BAO_Component();
$component->id = $mailing->reply_id;
$component->find(TRUE);
$message = new Mail_Mime("\n");
$domain = CRM_Core_BAO_Domain::getDomain();
list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$headers = array('Subject' => $component->subject, 'To' => $to, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}");
/* TODO: do we need reply tokens? */
$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();
if ($eq->format == 'HTML' || $eq->format == 'Both') {
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
$html = CRM_Utils_Token::replaceMailingTokens($html, $mailing, NULL, $tokens['html']);
$message->setHTMLBody($html);
}
if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
$text = CRM_Utils_Token::replaceMailingTokens($text, $mailing, NULL, $tokens['text']);
$message->setTxtBody($text);
}
$b = CRM_Utils_Mail::setMimeParams($message);
$h = $message->headers($headers);
CRM_Mailing_BAO_Mailing::addMessageIdHeader($h, 'a', $eq->job_id, queue_id, $eq->hash);
$mailer = $config->getMailer();
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$mailer->send($to, $h, $b);
unset($errorScope);
}
}