You are here

function invite_send_invite in Invite 5

Same name and namespace in other branches
  1. 5.2 invite.module \invite_send_invite()

Sends an invite to the specified e-mail address.

Parameters

$recipient: The recipient's e-mail address.

$subject: The e-mail subject.

$body: The e-mail body.

1 call to invite_send_invite()
invite_form_submit in ./invite.module
Forms API callback; processes the incoming form data.

File

./invite.module, line 989
Allows your users to send and track invitations to join your site.

Code

function invite_send_invite($recipient, $subject, $body) {
  global $user;
  $headers = array();

  // Prevent e-mail looking like spam to SPF-enabled MTAs
  // see http://drupal.org/node/133789
  $from_site = variable_get('site_mail', ini_get('sendmail_from'));
  if ($from_site) {
    $headers['Sender'] = $headers['Return-Path'] = $headers['Errors-To'] = $from_site;
  }

  // Manual settings override custom settings below
  // Note: default value must be NULL to comply with legacy Drupal versions
  $from = variable_get('invite_manual_from', NULL);
  $reply_to = variable_get('invite_manual_reply_to', NULL);

  // Set custom From and Reply-To headers
  if (!$from) {
    if ($user->uid && variable_get('invite_use_users_email', 0)) {
      $from = $user->mail;
    }
    else {
      if ($from_site) {
        $from = $from_site;
      }
    }
  }
  if (!$reply_to) {
    if ($user->uid && variable_get('invite_use_users_email_replyto', 0)) {
      $reply_to = $user->mail;
    }
    else {
      if ($from_site) {
        $reply_to = $from_site;
      }
    }
  }
  if ($reply_to) {
    $headers['Reply-To'] = $reply_to;
  }
  if (!($success = drupal_mail('invite-mail', $recipient, $subject, wordwrap($body, 72), $from, $headers))) {
    static $error_shown = FALSE;
    if (!$error_shown) {
      drupal_set_message(t('Problems occurred while sending the invitation(s). Please contact the site administrator.'), 'error');
      $error_shown = TRUE;
    }
    watchdog('invite', t('Failed sending invitation. To: @email From: @from', array(
      '@email' => '<' . $recipient . '>',
      '@from' => '<' . $from . '>',
    )));
  }
  return $success;
}