You are here

function _simplenews_set_from in Simplenews 6.2

Same name and namespace in other branches
  1. 6 simplenews.module \_simplenews_set_from()
  2. 7.2 includes/simplenews.mail.inc \_simplenews_set_from()
  3. 7 includes/simplenews.mail.inc \_simplenews_set_from()

Build formatted from-name and email for a mail object.

Each newsletter (series; tid) can have a different from address. The from name and address depend on the newsletter term tid which is included in the $node object

Parameters

object $node Node object of a simplenews newsletter:

Return value

array [address] = from address; [formatted] = formatted from name and address

5 calls to _simplenews_set_from()
simplenews_mail_mail in includes/simplenews.mail.inc
Send a node to an email address.
simplenews_send_node in includes/simplenews.mail.inc
Send newsletter node to subscribers.
simplenews_subscribe_user in ./simplenews.module
Subscribe a user to a newsletter or send a confirmation mail.
simplenews_token_values in ./simplenews.module
Implementation of hook_token_value().
simplenews_unsubscribe_user in ./simplenews.module
Unsubscribe a user from a newsletter or send a confirmation mail.

File

includes/simplenews.mail.inc, line 689
Simplenews email send and spool handling

Code

function _simplenews_set_from($node = NULL) {
  $address_default = variable_get('site_mail', ini_get('sendmail_from'));
  $name_default = variable_get('site_name', 'Drupal');
  if (isset($node->simplenews['tid'])) {
    $address = variable_get('simplenews_from_address_' . $node->simplenews['tid'], variable_get('simplenews_from_address', $address_default));
    $name = variable_get('simplenews_from_name_' . $node->simplenews['tid'], variable_get('simplenews_from_name', $name_default));
  }
  else {
    $address = variable_get('simplenews_from_address', $address_default);
    $name = variable_get('simplenews_from_name', $name_default);
  }

  // Windows based PHP systems don't accept formatted email addresses.
  $formatted_address = drupal_substr(PHP_OS, 0, 3) == 'WIN' ? $address : '"' . addslashes(mime_header_encode($name)) . '" <' . $address . '>';
  return array(
    'address' => $address,
    'formatted' => $formatted_address,
  );
}