Modfix: Link Submission Email

Author: yktan
Author's Website: http://www.phplinkdirectory.com/
Added: February 18, 2006

Hi, here's a mod to fix the submission notification email for both the user and administrator (there are 2 emails that are being sent out when a submission is entered).

Open include\functions.php
(1) Find:










Code:
function get_emailer(){
   global $tables, $db;
   require_once 'libs/phpmailer/class.phpmailer.php';
   $user = $db->GetRow("SELECT * FROM {$tables['user']['name']} WHERE ID=".$_SESSION['user_id']);
   $mail = new PHPMailer();
   $mail->PluginDir = 'libs/phpmailer/';
   $mail->From = $user['EMAIL'];
   $mail->FromName = $user['NAME'];
   $mail->Mailer = EMAIL_METHOD;
   switch(EMAIL_METHOD){
      case 'smtp':
         $mail->Host = EMAIL_SERVER;
         if(strlen(EMAIL_USER)>0){
            $mail->SMTPAuth = true;
            $mail->Username = EMAIL_USER;
            $mail->Password = EMAIL_PASS;
         }
         break;
      case 'sendmail':
         $mail->Sendmail = EMAIL_SENDMAIL;
         break;
   }
   return $mail;
}


Add below:










Code:
function get_emailer_admin(){
   global $tables, $db;
   require_once 'libs/phpmailer/class.phpmailer.php';
   $user = $db->GetRow("SELECT * FROM {$tables['user']['name']} WHERE ADMIN=1");
   $mail = new PHPMailer();
   $mail->PluginDir = 'libs/phpmailer/';
   $mail->From = $user['EMAIL'];
   $mail->FromName = $user['NAME'];
   $mail->Mailer = EMAIL_METHOD;
   switch(EMAIL_METHOD){
      case 'smtp':
         $mail->Host = EMAIL_SERVER;
         if(strlen(EMAIL_USER)>0){
            $mail->SMTPAuth = true;
            $mail->Username = EMAIL_USER;
            $mail->Password = EMAIL_PASS;
         }
         break;
      case 'sendmail':
         $mail->Sendmail = EMAIL_SENDMAIL;
         break;
   }
   return $mail;
}



(2) Find:










Code:
function send_submit_notifications($data) {
   global $db, $tables, $notif_msg;
   if (DEMO)
      return;
   $sql = "SELECT SUBJECT, BODY FROM {$tables['email_tpl']['name']} WHERE ID=".$db->qstr(NTF_SUBMIT_TPL);
   $tmpl = $db->GetRow($sql);
   if ($tmpl) {
      $mail = get_emailer();
      $mail->Body = replace_email_vars($tmpl['BODY'], $data, 2);
      $mail->Subject = replace_email_vars($tmpl['SUBJECT'], $data, 2);
      $mail->AddAddress($data['OWNER_EMAIL'], $data['OWNER_NAME']);
      $sent = $mail->Send();
   }
   
   $tmpl = $notif_msg['submit'];
   $rs = $db->Execute("SELECT * FROM {$tables['user']['name']} WHERE SUBMIT_NOTIF=1");
   $users = $rs->GetAssoc(true, true);
   $mail = get_emailer();
   $mail->Body = replace_email_vars($tmpl['BODY'], $data, 2);
   $mail->Subject = replace_email_vars($tmpl['SUBJECT'], $data, 2);
   foreach ($users as $user) {
      $mail->AddBCC($user['EMAIL'], $data['NAME']);
   }
   $sent = $mail->Send();
}


Replace with:










Code:
function send_submit_notifications($data) {
   global $db, $tables, $notif_msg;
   if (DEMO)
      return;
   $sql = "SELECT SUBJECT, BODY FROM {$tables['email_tpl']['name']} WHERE ID=".$db->qstr(NTF_SUBMIT_TPL);
   $tmpl = $db->GetRow($sql);
   if ($tmpl) {
      $mail = get_emailer_admin();
      $mail->Body = replace_email_vars($tmpl['BODY'], $data, 2);
      $mail->Subject = replace_email_vars($tmpl['SUBJECT'], $data, 2);
      $mail->AddAddress($data['OWNER_EMAIL'], $data['OWNER_NAME']);
      $sent = $mail->Send();
   }

   $tmpl = $notif_msg['submit'];
      $rs = $db->Execute("SELECT * FROM {$tables['user']['name']} WHERE SUBMIT_NOTIF=1");
      $users = $rs->GetAssoc(true);
      $mail = get_emailer_admin();
      $mail->Body = replace_email_vars($tmpl['BODY'], $data, 2);
      $mail->Subject = replace_email_vars($tmpl['SUBJECT'], $data, 2);
      foreach ($users as $user) {
         $mail->AddBCC($user['EMAIL'], $user['NAME']);
      }
   $sent = $mail->Send();
}



The reasons for the above changes:
Since during the submission process, no admin user is logged in, the function will not be able to get the admin user's email and name. A new function is made so that it will take the first admin user's email and name to be used during sending of emails.
Note: This is a temporary fix. I am not sure if dcb will implement new parameters to let you specify what is the default email address and name to be used for sending emails.