// dev/core#357 User Emails are keyed by their id so that the Signature is able to be added
// If we have had a contact email used here the value returned from the line above will be the
// numerical key where as $from for use in the sendEmail in Activity needs to be of format of "To Name" <toemailaddress>
- if (is_numeric($from)) {
- $result = civicrm_api3('Email', 'get', [
- 'id' => $from,
- 'return' => ['contact_id.display_name', 'email'],
- ]);
- $from = '"' . $result['values'][$from]['contact_id.display_name'] . '" <' . $result['values'][$from]['email'] . '>';
- }
+ $from = CRM_Utils_Mail::mailboxHeader($from);
$subject = $formValues['subject'];
// CRM-13378: Append CC and BCC information at the end of Activity Details and format cc and bcc fields
if (!empty($this->_params['send_receipt'])) {
- $receiptFrom = $this->_params['from_email_address'];
+ $receiptFrom = CRM_Utils_Mail::mailboxHeader($this->_params['from_email_address']);
if (!empty($this->_params['payment_instrument_id'])) {
$paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
return $formattedEmail;
}
+ /**
+ * When passed a value, returns the value if it's non-numeric.
+ * If it's numeric, look up the display name and email of the corresponding
+ * contact ID in RFC822 format.
+ *
+ * @param string $header
+ * @return string
+ * The RFC822-formatted email header (display name + address)
+ */
+ public static function mailboxHeader($header) {
+ if (is_numeric($header)) {
+ $result = civicrm_api3('Email', 'get', [
+ 'id' => $header,
+ 'return' => ['contact_id.display_name', 'email'],
+ 'sequential' => 1,
+ ])['values'][0];
+ $header = '"' . $result['contact_id.display_name'] . '" <' . $result['email'] . '>';
+ }
+ return $header;
+ }
+
}