Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by PhpStorm.
- * User: scott
- * Date: 12/17/18
- * Time: 12:07 PM
- */
- // Import PHPMailer classes into the global namespace
- // These must be at the top of your script, not inside a function
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- //Load Composer's autoloader
- require 'vendor/autoload.php';
- include('Rework.php');
- include('DateTimeStuff.php');
- $reworks = new Rework;
- $accounts = $reworks->get_list_of_accounts();
- foreach($accounts as $account){
- if (is_null($account['account_no'])){
- continue;
- }
- $zero = $reworks->fetch_zero_ranks($account['account_no']);
- $keywords = $reworks->number_of_keywords($account['account_no']);
- //var_dump($keywords[0][ 'COUNT(keyword)']);
- //var_dump($zero);
- $zeros = $zero[1]['zero'];
- $numkeywords = $keywords[0]['COUNT(keyword)'];
- // var_dump($zeros);
- // var_dump($numkeywords);
- /* if ($keywords[0][ 'COUNT(keyword)']= 0){
- continue;
- }
- if(($zero[1]['zero']/$keywords[0][ 'COUNT(keyword)']) > .5){
- $reworks->send_rework_mail($account['account_no']);
- }*/
- if(($zeros/$numkeywords) > .5){
- $latest = $reworks->already_in_rework($account['account_no']);
- // var_dump($latest);
- if(!$latest || date() > $latest['end_date']){
- echo "Account: ".$account['account_no'].": ".$zeros."/".$numkeywords." Result: ".($zeros/$numkeywords)."\r\n";
- file_put_contents('current/rework.txt', "Account: ".$account['account_no'].": ".$zeros."/".$numkeywords." Result: ".($zeros/$numkeywords)."\r\n", FILE_APPEND | LOCK_EX);
- $date = new DateTime();
- $start = $date->format('Y-m-d');
- $end = $date->add(new DateInterval('P28D'));
- $end = $end->format('Y-m-d');
- $result = $reworks->put_for_rework($account['account_no'], $start, $end);
- }
- }
- else{
- echo "Account: ".$account['account_no'].": ".$zeros."/".$numkeywords." Good Result: ".($zeros/$numkeywords)."\r\n";
- }
- // add mail function
- //Create a new PHPMailer instance
- $mail = new PHPMailer(true);
- // Set PHPMailer to use the sendmail transport
- $mail->isSendmail();
- //Set who the message is to be sent from
- $mail->setFrom('xxxxxx@yyyyy.com');
- //Set an alternative reply-to address
- // $mail->addReplyTo('replyto@example.com', 'First Last');
- //Set who the message is to be sent to
- $mail->addAddress('xxxxxx@wyyyyy.com');
- //Set the subject line
- $mail->Subject = 'Rework Report';
- $mail->Body = 'Here is the weekly rework report.';
- //Attach an image file
- $mail->addAttachment('current/rework.txt');
- //send the message, check for errors
- if (!$mail->send()) {
- echo "Mailer Error: " . $mail->ErrorInfo;
- } else {
- echo "Message sent!";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement