asked on
<?php
// email_RFQs.php
date_default_timezone_set("America/Los_Angeles");
require( 'wp-load.php' );
global $wpdb;
$dir = getcwd();
$pdfdir = $dir . "/pdfs/";
$odir = $dir . "/opdfs/";
//echo "dir = " . $dir . "<br>";
require_once('class.phpmailer.php');
if (strpos($dir, "staging") !== false) {
$loc = "http://watermanusa.staging.wpengine.com";
} else {
$loc = "http://www.watermanusa.com";
}
$qry = "SELECT * from auth_users";
$users = $wpdb->get_results($qry, ARRAY_A);
$i = 0;
foreach($users as $user) {
$entity = $user['entity'];
$ocode = $user['code'];
if ($entity == "") {
$ocode = "All";
$entity = "All";
}
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->isSMTP(); // telling the class to use SMTP transport
$mail->SetFrom('noreply@watermanusa.com');
$body = "Dear " . $user['name'] . "<br><br>";
$body = $body . "Greetings!<br><br>";
$body = $body . "Here is your weekly update of quotes in process with Waterman Industries estimating department. Please take a minute to review the status of your projects. Check in with our estimating team if you have questions or concerns.<br><br>";
$body = $body . "Thank you for your efforts toward growing our mutual success in your region.<br><br>";
$body = $body . "The Team at Waterman Industries";
$mail->Subject = "Your Weekly Status Report from Waterman Industries";
$mail->AddAddress($user['email']);
$someAttach = false;
$file = $pdfdir . $entity . ".pdf";
//echo "attach = " . $file . "<br>";
//echo "email = " . $user['email'] . "<br>";
if (file_exists ($file)) {
$someAttach = true;
$mail->AddAttachment($file);
}
$ofile = $odir . $ocode . "orders.pdf";
if (file_exists ($ofile)) {
$someAttach = true;
$mail->AddAttachment($ofile);
}
if (! $someAttach) {
$body = $body . "<br><br>There are currently no RFQ's or orders for " . $entity;
}
$mail->MsgHTML($body);
if ($someAttach) {
echo $user['email'] . " will get RFQ file: " . $file . " and order file: " . $ofile . "<br>";
} else {
echo $user['email'] . " will get no attachments.<br>";
}
}
?>