Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

php mail fails

See code (php).

Until yesterday, this worked.

It used to be that $mailto = "richard@rkassociates.com". Yesterday, I added the other email addresses.

Now nothing.

The echo at the end displays.

What's wrong?
<?
function conv_date($x) {
	if ($x != "" && substr($x,0,10) != "0000-00-00") {
		$fd = substr($x,5,2) . "/" . substr($x,8,2) . "/" . substr($x,0,4);
	} else {
		$fd = "";
	}		
	return $fd;
} 
// Set the variables for the database access:
$Host = "localhost";
$User = "adcd";
$Password = "1234";
$DBName = "adcd";
$Link = mysql_connect ($Host, $User, $Password);	
$today = mktime(0,0,0,date('m'), date('d'), date('Y'));
$tomorrow = $today + 86400;
$tom = getdate($tomorrow);
$emon = $tom["mon"];
if ($emon < 10){
	$emon = "0" . $emon;
}	
$eday = $tom["mday"];
if ($eday < 10) {
	$eday = "0" . $eday;
}	
$tomdt = $tom['year'] . "-" . $emon . "-" . $eday;
$qry = "SELECT * from schedule where date = '" . $tomdt . "'";
$res = mysql_db_query ($DBName, $qry, $Link);
$ns = mysql_num_rows ($res);
$ne = 0;
$subj = "Appointments Tomorrow with Lawn Sprinkler Services";
$header  = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset=iso-8859-1\r\n";
$header .= "From: donotreply@LSS.com\r\n";	
$msg = "";
$mailto = "richard@rkassociates.com; aveatch@lawnsprinklerservices.com; lawnsprinklerservice@hotmail.com";
for ($i = 0; $i < $ns; $i++) {
	$sch = mysql_fetch_array($res);
	$qryc = "SELECT * from customer where ListID = '" . $sch['ListID'] . "'";
	$resc = mysql_db_query ($DBName, $qryc, $Link);
	$cust = mysql_fetch_array($resc);
	if ($cust['email'] != "") {
		$msg = $msg . "Dear " . $cust['contactname'] . ",<br><br>";
		$aptt = "";
		if ($sch['AMPM'] == "A") {
			$aptt = ", in the morning.";
		} else {
			if ($sch['AMPM'] == "P") { 
				$aptt = ", in the afternoon.";
			}
		}	
		$addr = "unknown";
		if (is_numeric(substr($cust['address1'],0,1))) {
			$addr = $cust['address1'];
		} else {
			if (is_numeric(substr($cust['address2'],0,1))) {		
				$addr = $cust['address2'];
			} else {
				if (is_numeric(substr($cust['address3'],0,1))) {		
					$addr = $cust['address3'];
				}
			}
		}
		$msg = $msg . "Lawn Sprinkler Services is scheduled to provide a service appointment to your location at " . $addr . " tomorrow, " . conv_date($sch['date']);		
		$msg = $msg . $aptt . "<br><br>";
		$msg = $msg . "If you need to cancel or reschedule this appointment, please call us at (316)-303-1200 today before 5:00 PM.<br><br>";
		$msg = $msg . "We look forward to providing you with service.<br><br>";		
		$msg = $msg . "Thank you,<br><br>";
		$msg = $msg . "Lawn Sprinkler Services<br><br>";	
		$ne++;
	}	
}	
$mres = mail($mailto, $subj, $msg, $header);	
echo $ne . " emails sent.";	
?>

Open in new window

Avatar of Brad Brett
Brad Brett
Flag of United States of America image

Try sending email by simply using mail() function (no header) and see if it will be sent, if it's not work at all, you probably have misconfiguration in the server or the IP address is not static.
If you echo $mres, what is the result? Have you changed servers or server config?

Also, this doesn't look, at a glance, to even attempt sending to customers.
Does it work when you return the mailto back to just email?
I tried using the mail function with multiple addresses before and it did not work but with a single address it did.
sorry typoed my response if you set it back to just one email address.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richard Korts

ASKER

Hi Ray,

I remembered that from before while I was out on errands. That fixes it.

Odd that php function mail can't recognize that. It changes them to semicolons when it actually sends the email.

I guess all php functions expect commas as delimiters or ???
Thanks for the points.  regarding this, "I guess all php functions expect commas as delimiters or ???" mostly that is true.  Best, ~Ray