本文整理汇总了PHP中CRM_Core_BAO_MailSettings::defaultDomain方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_MailSettings::defaultDomain方法的具体用法?PHP CRM_Core_BAO_MailSettings::defaultDomain怎么用?PHP CRM_Core_BAO_MailSettings::defaultDomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_MailSettings
的用法示例。
在下文中一共展示了CRM_Core_BAO_MailSettings::defaultDomain方法的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: 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);
}
示例3: 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();
}
示例4: 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'));
}
}
示例5: processQueue
/**
* @param null $mode
*
* @return bool
* @throws Exception
*/
public static function processQueue($mode = NULL)
{
$config = CRM_Core_Config::singleton();
if ($mode == NULL && CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG") {
throw new CRM_Core_Exception(ts('The <a href="%1">default mailbox</a> has not been configured. You will find <a href="%2">more info in the 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/")));
}
// check if we are enforcing number of parallel cron jobs
// CRM-8460
$gotCronLock = FALSE;
if (property_exists($config, 'mailerJobsMax') && $config->mailerJobsMax && $config->mailerJobsMax > 0) {
$lockArray = range(1, $config->mailerJobsMax);
shuffle($lockArray);
// check if we are using global locks
foreach ($lockArray as $lockID) {
$cronLock = Civi\Core\Container::singleton()->get('lockManager')->acquire("worker.mailing.send.{$lockID}");
if ($cronLock->isAcquired()) {
$gotCronLock = TRUE;
break;
}
}
// exit here since we have enuf cronjobs running
if (!$gotCronLock) {
CRM_Core_Error::debug_log_message('Returning early, since max number of cronjobs running');
return TRUE;
}
if (getenv('CIVICRM_CRON_HOLD')) {
// In testing, we may need to simulate some slow activities.
sleep(getenv('CIVICRM_CRON_HOLD'));
}
}
// load bootstrap to call hooks
// Split up the parent jobs into multiple child jobs
$mailerJobSize = property_exists($config, 'mailerJobSize') ? $config->mailerJobSize : NULL;
CRM_Mailing_BAO_MailingJob::runJobs_pre($mailerJobSize, $mode);
CRM_Mailing_BAO_MailingJob::runJobs(NULL, $mode);
CRM_Mailing_BAO_MailingJob::runJobs_post($mode);
// lets release the global cron lock if we do have one
if ($gotCronLock) {
$cronLock->release();
}
return TRUE;
}
示例6: 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);
}
}
示例7: 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']);
//.........这里部分代码省略.........
示例8: 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;
}
示例9: getVerpAndUrlsAndHeaders
/**
* get verp, urls and headers
*
* @param int $job_id ID of the Job associated with this message
* @param int $event_queue_id ID of the EventQueue
* @param string $hash Hash of the EventQueue
* @param string $email Destination address
* @return (reference) array array ref that hold array refs to the verp info, urls, and headers
* @access private
*/
private function getVerpAndUrlsAndHeaders($job_id, $event_queue_id, $hash, $email, $isForward = false)
{
$config = CRM_Core_Config::singleton();
/**
* Inbound VERP keys:
* reply: user replied to mailing
* bounce: email address bounced
* unsubscribe: contact opts out of all target lists for the mailing
* resubscribe: contact opts back into all target lists for the mailing
* optOut: contact unsubscribes from the domain
*/
$verp = array();
$verpTokens = array('reply' => 'r', 'bounce' => 'b', 'unsubscribe' => 'u', 'resubscribe' => 'e', 'optOut' => 'o');
require_once 'CRM/Core/BAO/MailSettings.php';
$localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
foreach ($verpTokens as $key => $value) {
$verp[$key] = implode($config->verpSeparator, array($localpart . $value, $job_id, $event_queue_id, $hash)) . "@{$emailDomain}";
}
//handle should override VERP address.
$skipEncode = false;
$query = "\nSELECT override_verp \nFROM civicrm_mailing, civicrm_mailing_job \nWHERE civicrm_mailing_job.id = {$job_id} \nAND civicrm_mailing.id = civicrm_mailing_job.mailing_id";
if ($job_id && CRM_Core_DAO::singleValueQuery($query)) {
$verp['reply'] = "\"{$this->from_name}\" <{$this->from_email}>";
}
$urls = array('forward' => CRM_Utils_System::url('civicrm/mailing/forward', "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}", true, null, true, true), 'unsubscribeUrl' => CRM_Utils_System::url('civicrm/mailing/unsubscribe', "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}", true, null, true, true), 'resubscribeUrl' => CRM_Utils_System::url('civicrm/mailing/resubscribe', "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}", true, null, true, true), 'optOutUrl' => CRM_Utils_System::url('civicrm/mailing/optout', "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}", true, null, true, true), 'subscribeUrl' => CRM_Utils_System::url('civicrm/mailing/subscribe', 'reset=1', true, null, true, true));
$headers = array('Reply-To' => $verp['reply'], 'Return-Path' => $verp['bounce'], 'From' => "\"{$this->from_name}\" <{$this->from_email}>", 'Subject' => $this->subject, 'List-Unsubscribe' => "<mailto:{$verp['unsubscribe']}>");
if ($isForward) {
$headers['Subject'] = "[Fwd:{$this->subject}]";
}
return array(&$verp, &$urls, &$headers);
}
示例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_confirm_request
/**
* Ask a contact for subscription confirmation (opt-in)
*
* @param string $email The email address
* @return void
* @access public
*/
public function send_confirm_request($email)
{
$config =& CRM_Core_Config::singleton();
require_once 'CRM/Core/BAO/Domain.php';
$domain =& CRM_Core_BAO_Domain::getDomain();
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
require_once 'CRM/Core/BAO/MailSettings.php';
$localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
require_once 'CRM/Utils/Verp.php';
$confirm = implode($config->verpSeparator, array($localpart . 'c', $this->contact_id, $this->id, $this->hash)) . "@{$emailDomain}";
require_once 'CRM/Contact/BAO/Group.php';
$group =& new CRM_Contact_BAO_Group();
$group->id = $this->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 = '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);
}
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::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);
// 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();
}
}
示例12: 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;
}
示例13: 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;
}
}
示例14: 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);
}
}
示例15: 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');
$docUrl = 'target="_blank" href="' . CRM_Utils_System::docURL(array('page' => 'user/advanced-configuration/email-system-configuration/', 'URLonly' => TRUE)) . '""';
$message->addHelp(ts('A default mailbox must be configured for email bounce processing.') . '<br />' . ts("Learn more in the <a %1>online documentation</a>.", array(1 => $docUrl)));
$messages[] = $message;
}
return $messages;
}