当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Activity_BAO_Activity::sendEmail方法代码示例

本文整理汇总了PHP中CRM_Activity_BAO_Activity::sendEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Activity_BAO_Activity::sendEmail方法的具体用法?PHP CRM_Activity_BAO_Activity::sendEmail怎么用?PHP CRM_Activity_BAO_Activity::sendEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Activity_BAO_Activity的用法示例。


在下文中一共展示了CRM_Activity_BAO_Activity::sendEmail方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: postProcess

 /**
  * Process the form after the input has been submitted and validated.
  *
  * @param CRM_Core_Form $form
  */
 public static function postProcess(&$form)
 {
     if (count($form->_contactIds) > self::MAX_EMAILS_KILL_SWITCH) {
         CRM_Core_Error::fatal(ts('Please do not use this task to send a lot of emails (greater than %1). We recommend using CiviMail instead.', array(1 => self::MAX_EMAILS_KILL_SWITCH)));
     }
     // check and ensure that
     $formValues = $form->controller->exportValues($form->getName());
     $fromEmail = $formValues['fromEmailAddress'];
     $from = CRM_Utils_Array::value($fromEmail, $form->_emails);
     $subject = $formValues['subject'];
     // CRM-13378: Append CC and BCC information at the end of Activity Details and format cc and bcc fields
     $elements = array('cc_id', 'bcc_id');
     $additionalDetails = NULL;
     $ccValues = $bccValues = array();
     foreach ($elements as $element) {
         if (!empty($formValues[$element])) {
             $allEmails = explode(',', $formValues[$element]);
             foreach ($allEmails as $value) {
                 list($contactId, $email) = explode('::', $value);
                 $contactURL = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$contactId}", TRUE);
                 switch ($element) {
                     case 'cc_id':
                         $ccValues['email'][] = '"' . $form->_contactDetails[$contactId]['sort_name'] . '" <' . $email . '>';
                         $ccValues['details'][] = "<a href='{$contactURL}'>" . $form->_contactDetails[$contactId]['display_name'] . "</a>";
                         break;
                     case 'bcc_id':
                         $bccValues['email'][] = '"' . $form->_contactDetails[$contactId]['sort_name'] . '" <' . $email . '>';
                         $bccValues['details'][] = "<a href='{$contactURL}'>" . $form->_contactDetails[$contactId]['display_name'] . "</a>";
                         break;
                 }
             }
         }
     }
     $cc = $bcc = '';
     if (!empty($ccValues)) {
         $cc = implode(',', $ccValues['email']);
         $additionalDetails .= "\ncc : " . implode(", ", $ccValues['details']);
     }
     if (!empty($bccValues)) {
         $bcc = implode(',', $bccValues['email']);
         $additionalDetails .= "\nbcc : " . implode(", ", $bccValues['details']);
     }
     // CRM-5916: prepend case id hash to CiviCase-originating emails’ subjects
     if (isset($form->_caseId) && is_numeric($form->_caseId)) {
         $hash = substr(sha1(CIVICRM_SITE_KEY . $form->_caseId), 0, 7);
         $subject = "[case #{$hash}] {$subject}";
     }
     // process message template
     if (!empty($formValues['saveTemplate']) || !empty($formValues['updateTemplate'])) {
         $messageTemplate = array('msg_text' => $formValues['text_message'], 'msg_html' => $formValues['html_message'], 'msg_subject' => $formValues['subject'], 'is_active' => TRUE);
         if (!empty($formValues['saveTemplate'])) {
             $messageTemplate['msg_title'] = $formValues['saveTemplateName'];
             CRM_Core_BAO_MessageTemplate::add($messageTemplate);
         }
         if (!empty($formValues['template']) && !empty($formValues['updateTemplate'])) {
             $messageTemplate['id'] = $formValues['template'];
             unset($messageTemplate['msg_title']);
             CRM_Core_BAO_MessageTemplate::add($messageTemplate);
         }
     }
     $attachments = array();
     CRM_Core_BAO_File::formatAttachment($formValues, $attachments, NULL, NULL);
     // format contact details array to handle multiple emails from same contact
     $formattedContactDetails = array();
     $tempEmails = array();
     foreach ($form->_contactIds as $key => $contactId) {
         // if we dont have details on this contactID, we should ignore
         // potentially this is due to the contact not wanting to receive email
         if (!isset($form->_contactDetails[$contactId])) {
             continue;
         }
         $email = $form->_toContactEmails[$key];
         // prevent duplicate emails if same email address is selected CRM-4067
         // we should allow same emails for different contacts
         $emailKey = "{$contactId}::{$email}";
         if (!in_array($emailKey, $tempEmails)) {
             $tempEmails[] = $emailKey;
             $details = $form->_contactDetails[$contactId];
             $details['email'] = $email;
             unset($details['email_id']);
             $formattedContactDetails[] = $details;
         }
     }
     // send the mail
     list($sent, $activityId) = CRM_Activity_BAO_Activity::sendEmail($formattedContactDetails, $subject, $formValues['text_message'], $formValues['html_message'], NULL, NULL, $from, $attachments, $cc, $bcc, array_keys($form->_toContactDetails), $additionalDetails);
     $followupStatus = '';
     if ($sent) {
         $followupActivity = NULL;
         if (!empty($formValues['followup_activity_type_id'])) {
             $params['followup_activity_type_id'] = $formValues['followup_activity_type_id'];
             $params['followup_activity_subject'] = $formValues['followup_activity_subject'];
             $params['followup_date'] = $formValues['followup_date'];
             $params['followup_date_time'] = $formValues['followup_date_time'];
             $params['target_contact_id'] = $form->_contactIds;
             $params['followup_assignee_contact_id'] = explode(',', $formValues['followup_assignee_contact_id']);
//.........这里部分代码省略.........
开发者ID:saurabhbatra96,项目名称:civicrm-core,代码行数:101,代码来源:EmailCommon.php

示例2: postProcess

 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 static function postProcess(&$form)
 {
     if (count($form->_contactIds) > self::MAX_EMAILS_KILL_SWITCH) {
         CRM_Core_Error::fatal(ts('Please do not use this task to send a lot of emails (greater than %1). We recommend using CiviMail instead.', array(1 => self::MAX_EMAILS_KILL_SWITCH)));
     }
     // check and ensure that
     $formValues = $form->controller->exportValues($form->getName());
     $fromEmail = $formValues['fromEmailAddress'];
     $from = CRM_Utils_Array::value($fromEmail, $form->_fromEmails);
     $cc = CRM_Utils_Array::value('cc_id', $formValues);
     $bcc = CRM_Utils_Array::value('bcc_id', $formValues);
     $subject = $formValues['subject'];
     // process message template
     require_once 'CRM/Core/BAO/MessageTemplates.php';
     if (CRM_Utils_Array::value('saveTemplate', $formValues) || CRM_Utils_Array::value('updateTemplate', $formValues)) {
         $messageTemplate = array('msg_text' => $formValues['text_message'], 'msg_html' => $formValues['html_message'], 'msg_subject' => $formValues['subject'], 'is_active' => true);
         if ($formValues['saveTemplate']) {
             $messageTemplate['msg_title'] = $formValues['saveTemplateName'];
             CRM_Core_BAO_MessageTemplates::add($messageTemplate);
         }
         if ($formValues['template'] && $formValues['updateTemplate']) {
             $messageTemplate['id'] = $formValues['template'];
             unset($messageTemplate['msg_title']);
             CRM_Core_BAO_MessageTemplates::add($messageTemplate);
         }
     }
     $attachments = array();
     CRM_Core_BAO_File::formatAttachment($formValues, $attachments, null, null);
     // format contact details array to handle multiple emails from same contact
     $formattedContactDetails = array();
     $tempEmails = array();
     foreach ($form->_contactIds as $key => $contactId) {
         $email = $form->_toContactEmails[$key];
         // prevent duplicate emails if same email address is selected CRM-4067
         // we should allow same emails for different contacts
         $emailKey = "{$contactId}::{$email}";
         if (!in_array($emailKey, $tempEmails)) {
             $tempEmails[] = $emailKey;
             $details = $form->_contactDetails[$contactId];
             $details['email'] = $email;
             unset($details['email_id']);
             $formattedContactDetails[] = $details;
         }
     }
     // send the mail
     require_once 'CRM/Activity/BAO/Activity.php';
     list($sent, $activityId) = CRM_Activity_BAO_Activity::sendEmail($formattedContactDetails, $subject, $formValues['text_message'], $formValues['html_message'], null, null, $from, $attachments, $cc, $bcc, array_keys($form->_contactDetails));
     if ($sent) {
         $status = array('', ts('Your message has been sent.'));
     }
     //Display the name and number of contacts for those email is not sent.
     $emailsNotSent = array_diff_assoc($form->_allContactDetails, $form->_contactDetails);
     if (!empty($emailsNotSent)) {
         $statusOnHold = '';
         $statusDisplay = ts('Email not sent to contact(s) (no email address on file or communication preferences specify DO NOT EMAIL or Contact is deceased or Primary email address is On Hold): %1', array(1 => count($emailsNotSent))) . '<br />' . ts('Details') . ': ';
         foreach ($emailsNotSent as $contactId => $values) {
             $displayName = $values['display_name'];
             $email = $values['email'];
             $contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$contactId}");
             $statusDisplay .= "<a href='{$contactViewUrl}'>{$displayName}</a>, ";
             // build separate status for on hold messages
             if ($values['on_hold']) {
                 $statusOnHold .= ts('Email was not sent to %1 because primary email address (%2) is On Hold.', array(1 => "<a href='{$contactViewUrl}'>{$displayName}</a>", 2 => "<strong>{$email}</strong>")) . '<br />';
             }
         }
         $status[] = $statusDisplay;
     }
     if ($form->_caseId) {
         // if case-id is found in the url, create case activity record
         $caseParams = array('activity_id' => $activityId, 'case_id' => $form->_caseId);
         require_once 'CRM/Case/BAO/Case.php';
         CRM_Case_BAO_Case::processCaseActivity($caseParams);
     }
     if (strlen($statusOnHold)) {
         $status[] = $statusOnHold;
     }
     CRM_Core_Session::setStatus($status);
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:84,代码来源:EmailCommon.php


注:本文中的CRM_Activity_BAO_Activity::sendEmail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。