Location: PHPKode > projects > PLiMa > plima-0.5.2/restricted/send.php
#!/usr/bin/php -q
<?
/***
  *   pLiMa - php List Manager
  *   Copyright (C) 2003  Jinn Koriech (hide@address.com)
  *
  *		This file is part of pLiMa.
  *
  *   pLiMa is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
  *   the Free Software Foundation; either version 2 of the License, or
  *   any later version.
  *
  *   pLiMa is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *   GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
  *   along with pLiMa; if not, visit http://www.gnu.org or write to the
  *   Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  *	  Boston, MA  02111-1307  USA
  *
  */

  $SKIP_SESSION = "your_password";
  require("../inc/init.inc.php");

  $sendAt = date("Y-m-d G:i:s", time());
  $sql = "SELECT *
            FROM lima_queue
            WHERE sendAt <= '$sendAt'
              AND status ='W'
            ORDER BY sendAt DESC
            LIMIT 1";
  $result_Q = db_query($sql, "SNDQ10");
  $queue = db_num_rows($result_Q);

  if ( $queue > 0 ) {
    $row = db_fetch_array($result_Q, $idx) or die(mysql_error());

    $sql = "UPDATE lima_queue SET status='S' WHERE mailout_id = '".$row['mailout_id']."';";
    db_query($sql,"SNDQ15");

    // Set up the sending environment
    require("./phpmailer/class.phpmailer.php");
    $mail = new phpmailer();
    switch ( PHPMAILER_SEND_METHOD ) {
      case 'sendmail':
        $mail->IsSendmail();
        break;
      case 'smtp':
        $mail->IsSMTP();
        $mail->Host = PHPMAILER_SMTP_HOST;
        if ( PHPMAILER_AUTH == '1' ) {
          $mail->SMTPAuth = true;
          $mail->Username = PHPMAILER_AUTH_USERNAME;
          $mail->Password = PHPMAILER_AUTH_PASSWORD;
        }
        break;
      default: // use PHP mail() function
        $mail->IsMail();
        break;
    }

    for ( $idx=0; $idx < $queue ; $idx++ ) {
      $row = db_fetch_array($result_Q, $idx) or die(mysql_error());

      $options = getOptions($row['list_name']);

      ereg("(@.*)", $options['sender'], $domain);

      //$mail->ReplyTo = $options['sender'];
      $mail->Sender = "no-reply".$domain[0];
      $mail->From = $options['sender'];
      $mail->FromName = $options['senderName'];

      $mail->Subject = $row['subject'];

      $list_sub_set = $row['criteria'] . " ORDER BY userid ASC LIMIT " . $row['sent'] . ", " . $row['recipients'];
      $result_Recipients = db_query($list_sub_set, "SNDQ20");

      while ( $recipient = db_fetch_array($result_Recipients,$rdx++) ) {
        $mail->ClearAddresses();
        $mail->AddAddress($recipient['email'], $recipient['name']);

        if ( $row['usename'] == 'Y' )
          $body = $row['salutation'] ." ". $recipient['name'] . ",\n\n" . $row['message'];
        else
          $body = $row['message'];

        $body .= "\n\n\n---\n";
        if ( $row['usenum'] == 'Y' ) 	$body .= "This message was sent to ".$row['recipients']." people.\n\n";
        if ( $row['usesig'] == 'Y' ) 	$body .= $options['signature'] . "\n\n";

        $mail->Body = $body;

        if ( $options['wrap'] > 0 )
          $mail->WordWrap = $options['wrap'];

        $mail->Send();
        $sql = "UPDATE lima_queue SET sent=(sent + 1), status='S' WHERE mailout_id = '".$row['mailout_id']."';";
        db_query($sql,"SNDQ30") or die(mysql_error());
      }
      $sql = "UPDATE lima_queue SET status='D' WHERE mailout_id = '".$row['mailout_id']."';";
      db_query($sql,"SNDQ40") or die(mysql_error());
    }
  }
?>
Return current item: PLiMa