You are here

function mandrill_from in Mandrill 7.2

Same name and namespace in other branches
  1. 8 mandrill.module \mandrill_from()
  2. 7 mandrill.module \mandrill_from()

Returns an array containing the from information for a Mandrill message.

Parameters

string $from: (Optional) An optional string representing a specific e-mail address from which a message should be sent. This will be merged in with defaults. It can be of the form "Name <email@example.com>"

Return value

array array( 'email' => 'admin@example.com', 'name' => 'My Site', )

2 calls to mandrill_from()
MandrillMailSystem::mail in lib/mandrill.mail.inc
Send the email message.
mandrill_admin_settings in ./mandrill.admin.inc
Administrative settings.
1 string reference to 'mandrill_from'
mandrill_uninstall in ./mandrill.install
Implements hook_uninstall().

File

./mandrill.module, line 709
Enables Drupal to send email directly through Mandrill.

Code

function mandrill_from($from = '') {
  $default = array();
  $provided = array();

  // Parse out the default "from" details.
  $default_from = variable_get('site_mail', ini_get('sendmail_from'));
  $default['email'] = variable_get('mandrill_from', $default_from);
  $default['name'] = variable_get('mandrill_from_name', variable_get('site_name'));

  // If a "from" string was explicitly provided, parse out the details.
  if (preg_match_all('/(?:"?([^"]*)"?\\s)?(?:<?(.+@[^>]+)>?)/', $from, $matches)) {
    if (isset($matches[1][0]) && !empty($matches[1][0])) {
      $provided['name'] = trim($matches[1][0]);
    }
    if (isset($matches[2][0]) && !empty($matches[2][0])) {
      $provided['email'] = $matches[2][0];
    }
  }
  return array_merge($default, $provided);
}