Avatar of Richard Korts
Richard Korts
Flag for United States of America

asked on 

Don't send email

I am working on a project that will go live next week. Each "rep" will get an email with one or two or no attachments.

We have never tested this because a "live" test will actually send the emails.

The code that follows is what I have put together as a test version. Note the LACK of $mail->Send() (or at least that is my intention).

I'm not trusting my own perception because so many things have gone wrong on this project.

I need some other eyes to look at this code & tell me "no emails will be sent".
<?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>";
	}	
}	
?>

Open in new window


Thanks
PHP

Avatar of undefined
Last Comment
Scott Fell

8/22/2022 - Mon