每天使用_autoload功能无法发送电子邮件

时间:2015-12-14 02:18:22

标签: php class pdo autoload

我想每天从我的数据库向用户发送电子邮件。查询将检查今天的日期是否大于创建日期,如果状态等于打开。我使用__autoload来调用此查询所在的类。请帮助我如何使它工作。感谢。

UPDATE ----------------------------------------

我尝试使用此功能但是我得到了消息:无法加载EmailNotif。

function __autoload($class_name) {

   if(file_exists($class_name . '.php')) {
      require_once($class_name . '.php');    
   } else {
      throw new Exception("Unable to load $class_name.");
   }
}

try {
   $class = new EmailNotif();
} catch (Exception $e) {
   echo $e->getMessage(), "\n";
}

END UPDATE ------------------------------------

function __autoload($class_name) {

    require 'EmailNotif.php';
}

$class = new EmailNotif();

EmailNotif.php

class EmailNotif {

   function email() {

    $date = date('Y-m-d');
    $stats = 'Open';

   $conn = dbConnect();
   $stmt = $conn->prepare("SELECT * FROM invalid_invoice WHERE Creation_Date<=:date AND Status=:stats");
   $stmt->bindParam(':date', $date);
    $stmt->bindParam(':stats', $stats);
   $stmt->execute();
   $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
   $conn = null;
   //var_dump($data);


   $messages = array();

   foreach ($data as $row6) {

            $invnumb=$row6['Invoice_Number'];
            $partnumb=$row6['Part_Number'];
            $issue=$row6['Issues'];
            $pic=$row6['PIC_Comments'];
            $issuetype=$row6['Issue_Type'];
            $createdate=$row6['Creation_Date'];
            $site=$row6['Site'];
            $vendor=$row6['Vendor_Name'];
            $invdate=$row6['Invoice_Date'];
            $po=$row6['PO'];
            $rr=$row6['RR'];
            $currency=$row6['Currency'];
            $invamount=$row6['Invoice_Amount'];
            $stat=$row6['Status'];
            $emailadd= $row6['PersoninCharge'];


    if(!isset($messages[$emailadd])) {

                $messages[$emailadd] = '';
        }

                $messages[$emailadd] .= "<b>Issue Type: {$issuetype} </b><br><br>";
                $messages[$emailadd] .= "<b>Creation Date: {$createdate} </b><br><br>";
                $messages[$emailadd] .= "<b>Site: {$site} </b><br><br>";
                $messages[$emailadd] .= "<b>Vendor Name: {$vendor} </b><br><br>";
                $messages[$emailadd] .= "<b>Invoice Date: {$invdate} </b><br><br>";
                $messages[$emailadd] .= "<b>Invoice Number: {$invnumb} </b><br><br>";
                $messages[$emailadd] .= "<b>Part Number:</b><br>{$partnumb}<br><br>";
                $messages[$emailadd] .= "<b>PO: {$po} </b><br><br>";
                $messages[$emailadd] .= "<b>RR: {$rr} </b><br><br>";
                $messages[$emailadd] .= "<b>Currency: {$currency} </b><br><br>";
                $messages[$emailadd] .= "<b>Invoice Amount: {$invamount} </b><br><br>";
                $messages[$emailadd] .= "<b>Issues:{$issue}</b><br><br>";
                $messages[$emailadd] .= "<b>Status: {$stat} </b><br><br>";
                $messages[$emailadd] .= "<b>PIC Comments: {$pic}</b><br>";
                $messages[$emailadd] .= "<br><br>";

   }

   foreach($messages as $email=>$message) {

      $send_to = $email;
      $subject = "Invalid Invoice Tracking Message";
      $message = "<html>{$message}</html>";

      $sql7 = "INSERT INTO email_queue (send_to, subject, message) 
        VALUES (:send_to, :subject, :message)"; 

      $conn = dbConnect();
      $stmt7 = $conn->prepare($sql7); 
      $stmt7->bindParam(':send_to', $send_to);
      $stmt7->bindParam(':subject', $subject);
      $stmt7->bindParam(':message', $message);
      $stmt7->execute();
      $conn=null; 

   }

  }
  }

0 个答案:

没有答案