You are here

function civicrm_entity_contact_send_email in CiviCRM Entity 7.2

Parameters

$contact:

$subject:

$message_text:

$message_html:

null $from:

1 string reference to 'civicrm_entity_contact_send_email'
civicrm_entity_rules_action_info in ./civicrm_entity.rules.inc
Implements hook_rules_action_info().

File

./civicrm_entity.module, line 3311

Code

function civicrm_entity_contact_send_email($contact, $subject, $message_text, $message_html, $from = NULL) {
  $email = civicrm_api3('email', 'get', array(
    'contact_id' => $contact->id,
    'is_primary' => 1,
    'on_hold' => 0,
    'sequential' => 1,
  ));
  if (!$email['count']) {
    watchdog('civicrm_entity_rules', 'no email could be sent to !contact_id', array(
      '!contact_id' => $contact->id,
    ));
  }
  $params = array();
  $params['from'] = !empty($from) ? str_replace(array(
    "\r",
    "\n",
  ), '', $from) : 'Admin';
  $params['toEmail'] = $email['values'][0]['email'];
  $params['subject'] = $subject;
  $params['text'] = $message_text;
  $params['html'] = $message_html;
  CRM_Utils_Mail::send($params);
  civicrm_api3('activity', 'create', array(
    'activity_type_id' => 'Email',
    'source_contact_id' => $contact->id,
    'target_contact_id' => $contact->id,
    'subject' => $subject,
    'details' => $message_html,
  ));
}