setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->setAttribute (PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); //return ($dbh); - this would have been useful if we created a function from this... //$dbh = mysql_connect (); $sql = $dbh->query ("SELECT subject, body, tbmsgtemplate.heading, tbmsgtemplate.bodyformat, tbmsgtemplate.footer FROM tbmsg LEFT JOIN tbmsgtemplate ON tbmsg.MsgTemplateID = tbmsgtemplate.EID WHERE DATE_FORMAT(SendDate, '%d/%m/%Y') = DATE_FORMAT(CURDATE(), '%d/%m/%Y') AND MsgTypeID = 2 AND Status <> 'On Hold' AND Medium='Email' ORDER BY Priority LIMIT 1 "); // (Status='In Queue' OR Status='Send Test' OR Status='Preparing Message' OR Status='Sending...' ) while ($row = $sql->fetch (PDO::FETCH_OBJ)) { //Prepare html - first the body //NOTE the order of replacing is very NB... // I'm removing the following, allowing HTML formatting... //In first line: .Replace(">", ">").Replace("<", "<") //In second line: .Replace("\\", "\") $b = $row->body; $i = strpos($b, ">"); while ($i !== FALSE) { $j = strpos($b, "<", $i + 1); if($j === FALSE) break; $str = htmlentities(substr($b, $i+1, $j - ($i + 1)), ENT_QUOTES , "UTF-8"); $start = substr($b, 0, $i + 1); $end = substr($b, $j); $b = $start . $str . $end; $i = strpos($b, ">", $i + strlen($str) + 1); } /*$b = str_replace("&","&",$b); //This one MUST be first $b = str_ireplace("\r\n", "
",$b); $b = str_ireplace("\t", " ",$b);*/ /*$b = str_ireplace(chr(145),"'",$b); // ’ $b = str_ireplace(chr(146),"'",$b); // ‘ $b = str_ireplace(chr(147),"'",$b); // ” $b = str_ireplace(chr(148),"'",$b); // “*/ /*$b = str_ireplace("‘", "‘",$b); //$b = str_ireplace("?", "″",$b); $b = str_ireplace("”","″",$b); // ” $b = str_ireplace("?", "?",$b); $b = str_ireplace("%", "%",$b); $b = str_ireplace("\"", """,$b); $b = str_ireplace("“", "“",$b); $b = str_ireplace("’", "'",$b); // $b = str_ireplace(chr(226),"'",$b); $b = str_ireplace("'", "'",$b); $b = str_ireplace("€", "",$b); $b = str_ireplace("œ", "",$b); $b = str_ireplace("™", "",$b); $b = str_ireplace("Â", "",$b); $b = str_ireplace(" ", " ", $b);*/ //$b = str_ireplace(chr(13).chr(10), "
",$b); //Body Format $bf = $row->bodyformat; $bf = str_ireplace("\r\n", "",$bf); $bf = str_ireplace("\"", "'",$bf); //Heading $h = $row->heading; $h = str_ireplace("\r\n", "",$h); $h = str_ireplace("\"", "'",$h); //Footer $f = $row->footer; $f = str_ireplace("\r\n", "",$f); $f = str_ireplace("\"", "'",$f); //$htmlBody = " "; //$htmlBody = ""; //$htmlBody = $htmlBody.""; $htmlBody = ""; // $htmlBody. $htmlBody = $htmlBody.$h." ".$bf." ".$b; // if (strlen($bf) > 1) // $htmlBody = $htmlBody."

"." "; $htmlBody = $htmlBody.$f; $htmlBody = $htmlBody. ""; require_once('html2text.php'); $h = new html2text(); $text = $h->convert_html_to_text($htmlBody); $text = str_ireplace("’", "'", $text); $text = str_ireplace("“", "'", $text); $text = str_ireplace("â€", "'", $text); //$text = str_ireplace("\n", "\r\n", $text); echo $text; //printf ("subject: %s, body: %s\n", $row->subject, $row->body); } $dbh = NULL; } catch (PDOException $e) { echo 'Database error.'; } ?>