You are here

function invite_send in Invite 7.2

Send an invite.

The invitation email is sent to the invitee, and if sending is successful, the invite is saved.

Parameters

$invite: Invite object.

$send: The invitation email will be sent to the invitee only when $send is TRUE. Otherwise, only processing is done.

Return value

TRUE, if sending was successful; FALSE otherwise..

2 calls to invite_send()
example_send_invite_email in ./invite.api.php
Send an invitation email.
invite_form_submit in ./invite.module
Forms API callback; process submitted form data.

File

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

Code

function invite_send($invite, $send = TRUE) {
  global $language;

  // Check if this is an existing invite.
  $existing_invite = invite_load($invite->reg_code);
  if ($existing_invite) {
    $invite->expiry = REQUEST_TIME + variable_get('invite_expiry', 30) * 60 * 60 * 24;
    $invite->resent++;
  }
  if ($send) {
    if (empty($invite->inviter)) {
      $invite->inviter = user_load($invite->uid);
    }
    if (!variable_get('invite_use_users_email', 0)) {
      $from = variable_get('invite_manual_from', '');
    }
    elseif (!empty($invite->inviter->mail)) {
      $from = $invite->inviter->mail;
    }
    if (empty($from)) {

      // Never pass an empty string to drupal_mail()
      $from = NULL;
    }
    $params = array(
      'invite' => $invite,
    );

    // Override Reply-To address.
    if (!variable_get('invite_use_users_email_replyto', 0)) {
      $reply_to = variable_get('invite_manual_reply_to', '');
    }
    elseif (!empty($invite->inviter->mail)) {
      $reply_to = $invite->inviter->mail;
    }
    if (!empty($reply_to)) {
      $params['reply-to'] = $reply_to;
    }

    // Send e-mail.
    $result = drupal_mail('invite', 'invite', $invite->email, $language, $params, $from, TRUE);
  }
  if (!$send || $result['result']) {

    // Save invite.
    invite_save($invite);

    // Notify other modules.
    if (!$existing_invite) {
      module_invoke_all('invite_send', $invite, $send);
    }
    return TRUE;
  }
  else {
    return FALSE;
  }
}