You are here

function _simplenews_set_from in Simplenews 6

Same name and namespace in other branches
  1. 6.2 includes/simplenews.mail.inc \_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 (serie; 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

4 calls to _simplenews_set_from()
simplenews_mail_mail in ./simplenews.module
Send a node to an email address.
simplenews_send_node in ./simplenews.module
Send newsletter node to subcribers.
simplenews_subscribe_user in ./simplenews.module
Subscribe a user to a newsletter or send a confirmation mail.
simplenews_unsubscribe_user in ./simplenews.module
Unsubscribe a user from a newsletter or send a confirmation mail.

File

./simplenews.module, line 2027
Simplnews node handling, sent email, newsletter block and general hooks

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 emails.
  $formatted_address = drupal_substr(PHP_OS, 0, 3) == 'WIN' ? $address : '"' . addslashes(mime_header_encode($name)) . '" <' . $address . '>';
  return array(
    'address' => $address,
    'formatted' => $formatted_address,
  );
}