We help IT Professionals succeed at work.
Get Started

Don't send email

Richard Korts
on
144 Views
Last Modified: 2016-09-27
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
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE