Advertisement
Guest User

Untitled

a guest
Jan 30th, 2018
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.54 KB | None | 0 0
  1. <?php
  2.  
  3. class RemindMeMail{
  4.        
  5.     //ADMIN CONFIGURATION
  6.     public $USERNAME="cytometric";
  7.     public $PASSWORD="sistema";
  8.        
  9.      
  10.     // SCRIPT CONFIGURATION
  11.     public $DAYS_BEFORE =array(1,3,7,15,30,45,60); // days before the event to get the mail remi
  12.         public $DATE=2; // date format: 1->timestamp  ---  2->yyyy/mm/dd
  13.     public $LOGFILE="log.txt"; // log file
  14.     public $RECEIVE_MAIL=1; // 1 to receive mail when cron script runs. 0 to not receive mails
  15.     public $YOUR_EMAIL="bromero@cytometricbioservices.com";
  16.  
  17.     // DATABASE CONFIGURATION
  18.     public $DB_HOST="localhost";
  19.     public $DB_USER="cytometr_mremind";
  20.     public $DB_PASSWORD="201xcyto";
  21.     public $DB_DATABASE="cytometr_mreminder";
  22.    
  23.     public $dbConn;
  24.     public $dbConnection;
  25.  
  26.     // EVENT DB TABLE
  27.     public $DB_TABLE_EVENT="event";
  28.     public $DB_COL_EVENT_ID="id_event"; // the id column of the event
  29.     public $DB_COL_DATE="date"; // the date event column
  30.     public $DB_COL_EVENT="event"; // the event column
  31.         public $DB_COL_RM="isrmensual"; // recordatorio mensual 0/1
  32.    
  33.     // USER DB TABLE
  34.     public $DB_TABLE_USER="user"; // table where the user mail is
  35.     public $DB_COL_USER_ID="id_user";
  36.     public $DB_COL_USER_MAIL="email";
  37.        
  38.         // USUARIOS DEL SISTEMA
  39.         public $DB_PANEL_USER="accounts";
  40.    
  41.     // USER-EVENT TABLE
  42.     public $DB_TABLE_USER_EVENT="user_event"; // user_id - event-id correlation
  43.     public $DB_TABLE_USER_EVENT_ID_USER="id_user";
  44.     public $DB_TABLE_USER_EVENT_ID_EVENT="id_event";
  45.    
  46.     // EMAIL CONFIGURATION
  47.     public $FROM="Recordatorio de Correo";
  48.     public $FROM_EMAIL="informes@cytometricbioservices.com";
  49.     public $TO;
  50.     public $SUBJECT;
  51.     public $MESSAGE_BODY;
  52.        
  53.     public function sendMail($to, $subject, $messageBody){
  54.         $HEADERS = "From: $this->FROM <$this->FROM_EMAIL>\n";
  55.         $HEADERS .= "Reply-To: $this->FROM <$this->FROM_EMAIL>\n";
  56.         $HEADERS .= "Return-Path: $this->FROM <$this->FROM_EMAIL>\n";  
  57.         $HEADERS .= "Message-ID:<TheSystem@".$_SERVER['SERVER_NAME'].">\n";
  58.         $HEADERS .= "X-Mailer: PHP v".phpversion()."\n";    
  59.        
  60.         $this->TO=$to;
  61.         $this->SUBJECT=$subject;
  62.         $this->MESSAGE_BODY=$messageBody;
  63.        
  64.         if(mail($this->TO, $this->SUBJECT, $this->MESSAGE_BODY, $HEADERS))
  65.             $this->writeLog($this->getDate(), "Mail sent to: ".$this->TO." #-# ".$this->MESSAGE_BODY); 
  66.         else    
  67.             $this->writeLog($this->getDate(), "Error sending mail to: ".$this->TO." #-# ".$this->MESSAGE_BODY);
  68.     }
  69.    
  70.     // like 2011-12-07T12:48:05+01:00
  71.     public function getDate(){
  72.         return date('Y-m-d - G:i:s');      
  73.     }
  74.    
  75.     // write a logfile
  76.     public function writeLog($date, $text){
  77.         $toWrite=$date." #-# ".$text."\n"; // string to write in the logfile
  78.         if (!file_exists($this->LOGFILE))
  79.             touch($this->LOGFILE) or die("can't write file");
  80.         $lines = file($this->LOGFILE); // all the old lines
  81.         $fopen = fopen($this->LOGFILE, "w+");
  82.         fwrite( $fopen, $toWrite); // write the new line
  83.         foreach ($lines as $line) { fwrite( $fopen, "$line"); } // and all the old lines
  84.         fclose($fopen);
  85.     }
  86.    
  87.     // how many days between 2 dates
  88.     public function differenceDateInDays($date_start, $date_end){
  89.         $start_ts = strtotime($date_start);
  90.         $end_ts = strtotime($date_end);
  91.         $diff = $end_ts - $start_ts;
  92.         return round($diff / 86400);
  93.     }
  94.        
  95.        
  96.  
  97.                 // connection to db and db selection
  98.     public function setConnection(){
  99.         $this->dbConn = mysql_connect($this->DB_HOST, $this->DB_USER, $this->DB_PASSWORD) or die ("Connection failed on Server");
  100.         $this->dbConnection = mysql_select_db ($this->DB_DATABASE, $this->dbConn) or die ("Mysql Select failed on Database");
  101.     }
  102. }
  103.  
  104.  
  105. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement