function ad_notify_send_mail in Advertisement 6
Same name and namespace in other branches
- 5.2 notify/ad_notify.module \ad_notify_send_mail()
- 5 notify/ad_notify.module \ad_notify_send_mail()
Send email notifications using PHP mail() function.
1 call to ad_notify_send_mail()
- ad_notify_cron in notify/
ad_notify.module - Implementation of hook_cron(). For performance reasons, all notifications are actually sent via this cron hook.
File
- notify/
ad_notify.module, line 137 - Receive email notifications regarding ads.
Code
function ad_notify_send_mail($notification, $count = 0) {
$uid = db_result(db_query('SELECT uid FROM {ad_owners} WHERE oid = %d', $notification->oid));
$node = node_load(array(
'nid' => $notification->aid,
));
$owner = user_load(array(
'uid' => $uid,
));
$statistics = ad_statistics($notification->aid);
$notifications = module_invoke_all('adnotifyapi', 'register');
$variables = array(
'%owner_name' => $owner->name,
'%owner_mail' => $owner->mail,
'%owner_uid' => $owner->uid,
'%sitename' => variable_get('site_name', 'drupal'),
'%status' => $node->adstatus,
'%type' => $node->adtype,
'%event' => $notification->event,
'%frequency' => t(strtolower($notifications[$notification->event]), array(
'@when' => format_interval($notification->delay),
)),
'%redirect' => url($node->redirect, array(
'absolute' => TRUE,
)),
'%aid' => $notification->aid,
'%title' => $node->title,
'%url' => url("node/{$node->nid}", array(
'absolute' => TRUE,
)),
'%siteurl' => url('', array(
'absolute' => TRUE,
)),
'%comments' => $node->comment_count,
'%count' => $count,
'%created_small' => format_date($node->created, 'small'),
'%created_medium' => format_date($node->created, 'medium'),
'%created_large' => format_date($node->created, 'large'),
'%activated_small' => $node->activated ? format_date($node->activated, 'small') : t('never'),
'%activated_medium' => $node->activated ? format_date($node->activated, 'medium') : t('never'),
'%activated_large' => $node->activated ? format_date($node->activated, 'large') : t('never'),
'%expired_small' => $node->expired ? format_date($node->expired, 'small') : t('never'),
'%expired_medium' => $node->expired ? format_date($node->expired, 'medium') : t('never'),
'%expired_large' => $node->expired ? format_date($node->expired, 'large') : t('never'),
'%autoactivate_small' => $node->autoactivate ? format_date($node->autoactivate, 'small') : t('never'),
'%autoactivate_medium' => $node->autoactivate ? format_date($node->autoactivate, 'medium') : t('never'),
'%autoactivate_large' => $node->autoactivate ? format_date($node->autoactivate, 'large') : t('never'),
'%autoexpire_small' => $node->autoexpire ? format_date($node->autoexpire, 'small') : t('never'),
'%autoexpire_medium' => $node->autoexpire ? format_date($node->autoexpire, 'medium') : t('never'),
'%autoexpire_large' => $node->autoexpire ? format_date($node->autoexpire, 'large') : t('never'),
'%maxviews' => $node->maxviews,
'%maxclicks' => $node->maxclicks,
'%global_views' => $statistics['global']['views'],
'%global_clicks' => $statistics['global']['clicks'],
'%last_year_views' => $statistics['last_year']['views'],
'%last_year_clicks' => $statistics['last_year']['clicks'],
'%this_year_views' => $statistics['this_year']['views'],
'%this_year_clicks' => $statistics['this_year']['clicks'],
'%last_month_views' => $statistics['last_month']['views'],
'%last_month_clicks' => $statistics['last_month']['clicks'],
'%this_month_views' => $statistics['this_month']['views'],
'%this_month_clicks' => $statistics['this_month']['clicks'],
'%this_week_views' => $statistics['this_week']['views'],
'%this_week_clicks' => $statistics['this_week']['clicks'],
'%yesterday_views' => $statistics['yesterday']['views'],
'%yesterday_clicks' => $statistics['yesterday']['clicks'],
'%today_views' => $statistics['today']['views'],
'%today_clicks' => $statistics['today']['clicks'],
'%last_hour_views' => $statistics['last_hour']['views'],
'%last_hour_clicks' => $statistics['last_hour']['clicks'],
'%this_hour_views' => $statistics['this_hour']['views'],
'%this_hour_clicks' => $statistics['this_hour']['clicks'],
);
// TODO: Add hook to allow other modules to define variables.
// TODO: Should the from_address be configurable?
drupal_mail('ad_notify_mail', $notification->address, strtr($notification->subject, $variables), wordwrap(strtr($notification->body, $variables), 72), variable_get('site_mail', ini_get('sendmail_from')));
}