I have a PHP script which checks and gets data from a MySQL database and then sends email. The emails received have one line of gibberish at the end: "...If you have received a renewal notice from the license/certificate issuer, please forward it to {snipped}. If you are due for a repeat TB test, please send documentation of the PPD results to {snipped} when the test is complete. Thank you.
ÀžØ¯Š»¬jö¬µSÒÓÝ9×4çýyÿm4ôë¬n‹§vg¬±¨ \ íŠø«ºÄ¬jÛ¬ Wš ".

I'm using XAMPP for Windows and around the time this gibberish started occurring, I had updated XAMPP. I'm thinking there is something in my PHP code which doesn't mesh with the update (now PHP 5.2.9).

Can someone tell me where the gibberish is coming from? Be nice, I still consider myself a noob at this!

Full code:

<?
ini_set (SMTP, "example.com");	
	$conn = mysql_connect("localhost","XXuserXX","XXpswdXX") or die(mysql_error());
		$db = mysql_select_db("sleepco_credentialing", $conn) or die(mysql_error());
		$sql = "SELECT * FROM docs ORDER BY Doctor ASC";
		$sqlloc = "SELECT loc, ofccontact FROM locations ORDER BY loc ASC";
		$sql_result = mysql_query($sql) or die (mysql_error());
		$sql_resultloc = mysql_query($sqlloc) or die (mysql_error());
		if (!$sql_result || !$sql_resultloc) {
			echo "Something has gone wrong!";
		} else {
			$todays_date = date("Y-m-d");
			$today = strtotime($todays_date); 
			$fortyfivedays = strtotime("+45 days");
			$fifteendays = strtotime("+15 days");
			$emailsent = '';

		while ($record = mysql_fetch_array($sql_result)) {
			$managers = "example";
			$certificate = "";
			$Doctor = $record['Doctor'];
			$tpcemail = $record['tpcemail'];
			$PermitNum = $record['PermitNum'];
			$permitexp = $record['permitexp'];
			$permitreminder = $record['permitreminder'];

				if ($permitexp != ""){
					$permitdt = strtotime($permitexp);
					if ($permitdt < $today && $permitreminder == "") {
						$certificate .= "License - $permitexp (EXPIRED!)";
						$permitreminder = 3;
					}
					if ($permitdt < $today && $permitreminder == "2") {
						$certificate .= "License - $permitexp (EXPIRED!)";
						$permitreminder = 3;
					}
					if ($permitdt == $fortyfivedays && $permitreminder == ""){
						$certificate .= "License - $permitexp (expires in 45 days)";
						$permitreminder = 1;
					}
					if ($permitdt == $fifteendays && $permitreminder == "1"){
						$certificate .= "License - $permitexp (expires in 15 days)";
						$permitreminder = 2;
					}
					if ($permitdt > $fortyfivedays && $permitreminder != "") {
						$permitreminder = '';
					}
				}

			$DEANum = $record['DEANum'];
			$deaexp = $record['deaexp'];
			$deareminder = $record['deareminder'];

				if ($deaexp != ""){
					$deadt = strtotime($deaexp);
					if ($deadt < $today && $deareminder == "") {
						if ($certificate == "") {
							$certificate .= "DEA certificate - $deaexp (EXPIRED!)";
						} else {
							$certificate .= "<br>DEA certificate - $deaexp (EXPIRED!)";
						}
						$deareminder = 3;
					}
					if ($deadt < $today && $deareminder == "2") {
						if ($certificate == "") {
							$certificate .= "DEA certificate - $deaexp (EXPIRED!)";
						} else {
							$certificate .= "<br>DEA certificate - $deaexp (EXPIRED!)";
						}
						$deareminder = 3;
					}
					if ($deadt == $fortyfivedays && $deareminder == "") {
						if ($certificate == "") {
							$certificate .= "DEA certificate - $deaexp (expires in 45 days)";
						} else {
							$certificate .= "<br>DEA certificate - $deaexp (expires in 45 days)";
						}
						$deareminder = 1;
					}
					if ($deadt == $fifteendays && $deareminder == "1") {
						if ($certificate == "") {
							$certificate .= "DEA certificate - $deaexp (expires in 15 days)";
						} else {
							$certificate .= "<br>DEA certificate - $deaexp (expires in 15 days)";
						}
						$deareminder = 2;
					}
					if ($deadt > $fortyfivedays && $deareminder != "") {
						$deareminder = '';
					}
				}
				

			$DPSNum = $record['DPSNum'];
			$dpsexp = $record['dpsexp'];
			$dpsreminder = $record['dpsreminder'];

				if ($dpsexp != ""){
					$dpsdt = strtotime($dpsexp);
					if ($dpsdt < $today && $dpsreminder == "") {
					if ($certificate == ""){
							$certificate .= "DPS certificate - $dpsexp (EXPIRED!)";
						} else {
							$certificate .= "<br>DPS certificate - $dpsexp (EXPIRED!)";
						}
						$dpsreminder = 3;
					}
					if ($dpsdt < $today && $dpsreminder == "2") {
						if ($certificate == ""){
							$certificate .= "DPS certificate - $dpsexp (EXPIRED!)";
						} else {
							$certificate .= "<br>DPS certificate - $dpsexp (EXPIRED!)";
						}
						$dpsreminder = 3;
					}
					if ($dpsdt == $fortyfivedays && $dpsreminder == ""){
						if ($certificate == ""){
							$certificate .= "DPS certificate - $dpsexp (expires in 45 days)";
						} else {
							$certificate .= "<br>DPS certificate - $dpsexp (expires in 45 days)";
						}
						$dpsreminder = 1;
					}
					if ($dpsdt == $fifteendays && $dpsreminder == "1"){
						if ($certificate == ""){
							$certificate .= "DPS certificate - $dpsexp (expires in 15 days)";
						} else {
							$certificate .= "<br>DPS certificate - $dpsexp (expires in 15 days)";
						}
						$dpsreminder = 2;
					}
					if ($dpsdt > $fortyfivedays && $dpsreminder != "") {
						$dpsreminder = '';
					}
				}
				
				$tbtest = $record['tbtest'];
				$PPDStatus = $record['PPDStatus'];
				$tbreminder = $record['tbreminder'];
				if ($tbtest != "" && $PPDStatus == "Negative"){
					$tbtestdt = strtotime($tbtest);
					$tbtestdt += 31536000;
					if ($tbtestdt < $today && $tbreminder == "") {
						if ($certificate == ""){
							$certificate .= "PPD - Last done on $tbtest (EXPIRED!)";
						} else {
							$certificate .= "<br>PPD - Last done on $tbtest (EXPIRED!)";
						}
						$tbreminder = 2;
					}
					if ($tbtestdt < $today && $tbreminder == "1") {
						if ($certificate == ""){
							$certificate .= "PPD - Last done on $tbtest (EXPIRED!)";
						} else {
							$certificate .= "<br>PPD - Last done on $tbtest (EXPIRED!)";
						}
						$tbreminder = 2;
					}
					if ($tbtestdt == $fifteendays && $tbreminder == "1"){
						if ($certificate == ""){
							$certificate .= "PPD - Last done on $tbtest (expires in 15 days)";
						} else {
							$certificate .= "<br>PPD - Last done on $tbtest (expires in 15 days)";
						}
						$tbreminder = 1;
					}
					if ($tbtestdt > $fortyfivedays && $tbreminder != "") {
						$tbreminder = '';
					}
				}
				
		$Location = $record['Location'];

	$sqlupd = "UPDATE docs SET 
		permitreminder = '$permitreminder',
		deareminder = '$deareminder',
		dpsreminder = '$dpsreminder', 
		tbreminder = '$tbreminder' WHERE Doctor = '$Doctor'";
		$result = mysql_query($sqlupd) or die (mysql_error());
if ($certificate != "") {
	if ($tpcemail != "") {
	$managers .= ", $tpcemail";
	}
	$sqllocquery = "SELECT ofccontact FROM locations WHERE loc = '$Location'"; 
	$sql_resultlocquery = mysql_query($sqllocquery) or die (mysql_error());
	while ($row = mysql_fetch_array($sql_resultlocquery)) {
		$ofccontact = $row["ofccontact"];
	}
	$managers .= ", $ofccontact";

$headers = "MIME-Version: 1.0\r\n"; 
$boundary = uniqid("HTMLDEMO"); 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n" . 
   "Content-Transfer-Encoding: base64\r\n\r\n"; 
$headers .= chunk_split(base64_encode("<table><tr><td colspan=2><font size =3>This is an automated message to notify you of licenses or certificates which have expired or will expire soon, or of a repeat TB test which is due.</font></td></tr><tr><td>&nbsp;</td><td>&nbsp;</b></td></tr>
<tr><td>Provider Name:</td><td>   <b>$Doctor</b></td></tr>
<tr><td valign=top>Expiring/Expired Item(s):</td><td>   <b>$certificate</b></td></tr></table>
<table><tr><td><br>If you have received a renewal notice from the license/certificate issuer, please forward it to (snipped). If you are due for a repeat TB test, please send documentation of the PPD results to (snipped)when the test is complete. <i>Thank you.</i></td></tr></table>"));

//send message
$headersb = "From: (snipped).com>\n"; 
$headersb .= $headers;

mail( "$managers", "$Doctor - Expiring licensure and/or PPD", "", $headersb);
$emailsent .= "$Doctor<br><br>";
}
}
			echo "<HTML>
			<HEAD>
			<TITLE>Reminder Utility</TITLE>
			</HEAD>
			<BODY style=\"font-family: Verdana; font-size: 10pt\">
			<h1>Licensure reminders have been processed.</h1><p>&nbsp;</p>";
			if ($emailsent == ''){
			echo "No emails were sent.";
			} else {
			echo "<p>Emails were sent to:</p><blockquote>$emailsent</blockquote>";
			}
			echo "<p><input type=\"button\" value=\"Close this window\" onclick=\"self.close()\" /></p></BODY>
			</HTML>";
			}
?>

Recommended Answers

All 2 Replies

Why are you putting your message text directly in the header and leaving the message argument blank? http://php.net/mail

This did the trick. Thanks!

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: TPCCC Credentialing <XXXX@XXXX.com>\r\n"; 

$message = "<html>
<head>
<title>Credentialing</title>
</head>
<body><table><tr><td colspan=2><font size =3>This is an automated message to notify you of licenses or certificates which have expired or will expire soon, or of a repeat TB test which is due.</font></td></tr><tr><td>&nbsp;</td><td>&nbsp;</b></td></tr>
<tr><td>Provider Name:</td><td>   <b>$Doctor</b></td></tr>
<tr><td valign=top>Expiring/Expired Item(s):</td><td>   <b>$certificate</b></td></tr></table>
<table><tr><td><br>If you have received a renewal notice from the license/certificate issuer, please forward it to (snipped). If you are due for a repeat TB test, please send documentation of the PPD results to (snipped)when the test is complete. <i>Thank you.</i></td></tr></table>
</body>
</html>";

//send message
//$headersb = "From: TPCCC Credentialing <XXXX@XXXX.com>\n"; 
//$headersb .= $headers;

mail( $managers, "$Doctor - Expiring licensure and/or PPD", $message, $headers);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.