You are here

function _anonymous_publishing_cl_send_email in Anonymous Publishing 7

Send verification email.

Parameters

object $node: The node object.

string $akey: Activation key.

2 calls to _anonymous_publishing_cl_send_email()
anonymous_publishing_cl_node_form_submit in modules/cl/anonymous_publishing_cl.module
Implements a custom submit form for nodes.
_anonymous_publishing_cl_my_comment_insert in modules/cl/anonymous_publishing_cl.module
Helper function to handle anonymous comment submits.

File

modules/cl/anonymous_publishing_cl.admin.inc, line 1273
Menu callbacks for the CL tabs on the module admin page.

Code

function _anonymous_publishing_cl_send_email($node, $akey) {
  $options = variable_get('anonymous_publishing_cl_options', array());
  if (isset($node->title)) {
    $title = $node->title;
    $vfurl = url('node/' . $node->nid . '/verify', array(
      'query' => array(
        'akey' => $akey,
      ),
      'absolute' => TRUE,
    ));
    $modp = !$options['sactivate'];
  }
  else {
    $title = $node->subject;
    if (empty($title)) {
      $title = '';
    }
    $vfurl = url('comment/' . $node->cid . '/verify', array(
      'query' => array(
        'akey' => $akey,
      ),
      'absolute' => TRUE,
    ));
    $modp = !$options['sactivate'];
  }
  $autodelhours = variable_get('anonymous_publishing_cl_autodelhours', '48');
  $from = variable_get('site_mail', ini_get('sendmail_from'));
  $variables = array(
    '!action' => $modp ? t('verify') : t('activate'),
    '!autodelhours' => $autodelhours,
    '!email' => $node->anonymous_publishing['email'],
    '!site' => variable_get('site_name', 'Drupal'),
    '!title' => check_plain($title),
    '!verification_uri' => $vfurl,
  );
  $to = $node->anonymous_publishing['email'];
  $subject = _anonymous_publishing_cl_substitute_text($modp ? 'anonymous_publishing_cl_emailsubjectver' : 'anonymous_publishing_cl_emailsubjectact', $variables);
  $b1 = _anonymous_publishing_cl_substitute_text('anonymous_publishing_cl_emailaction', $variables);
  $b2 = $autodelhours >= 0 ? _anonymous_publishing_cl_substitute_text('anonymous_publishing_cl_emailactivate', $variables) : '';
  $b3 = $modp ? _anonymous_publishing_cl_substitute_text('anonymous_publishing_cl_emailverify', $variables) : '';
  $body = array(
    $b1,
    $b2,
    $b3,
  );

  // 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes'.
  $message = array(
    'id' => 'anonymous_publishing_verify',
    'to' => $to,
    'subject' => $subject,
    'body' => $body,
    'headers' => array(
      'From' => $from,
      'Sender' => $from,
      'Return-Path' => $from,
      'MIME-Version' => '1.0',
      'Content-Type' => 'text/plain; charset=UTF-8',
      'Content-Transfer-Encoding' => '8bit',
      'X-Mailer' => 'Drupal',
    ),
  );
  $system = drupal_mail_system('anonymous_publishing', 'verify');
  $message = $system
    ->format($message);
  $result = $system
    ->mail($message);
  if ($result) {
    drupal_set_message(t('A link and further instructions have been sent to your e-mail address. Check your spam-folder if you do not receive it within one minute.'));
    watchdog('anonymous_publishing', 'Verification mail sent to @to, from @from.', array(
      '@to' => $to,
      '@from' => $from,
    ));
  }
  else {
    watchdog('anonymous_publishing', 'Error mailing activation/verification link.');
    drupal_set_message(t('Unable to send mail. Please contact the site admin.'), 'error');
  }
  if ($options['modmail']) {
    $admin = user_load(1);
    $subject = _anonymous_publishing_cl_substitute_text('anonymous_publishing_cl_emailnsubject', $variables);
    $body = _anonymous_publishing_cl_substitute_text('anonymous_publishing_cl_emailnbody', $variables);
    $body = wordwrap($body);
    $body = str_replace("\n", "\r\n", $body);
    $message = array(
      'id' => 'anonymous_publishing_notify',
      'to' => variable_get('anonymous_publishing_cl_moderator', $admin->mail),
      'subject' => $subject,
      'body' => $body,
      'headers' => array(
        'From' => $from,
        'Sender' => $from,
        'Return-Path' => $from,
        'MIME-Version' => '1.0',
        'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
        'Content-Transfer-Encoding' => '8bit',
        'X-Mailer' => 'Drupal',
      ),
    );
    $system = drupal_mail_system('anonymous_publishing', 'notify');
    if (!$system
      ->mail($message)) {
      watchdog('anonymous_publishing', 'Error notifying admin.');
    }
  }
}