trouble emailing query |
8/21/2007 5:17:10 AM |
PHPRunner General questions | |
M
morpheus author
Morning folks, <?php // Create Connection $dbhost = 'localhost'; $dbuser = 'stockcontrol'; $dbpass = 'stockcontrol'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'stockcontrol'; mysql_select_db($dbname); // Get date 7 days ago $sevendaysago = date("Y-m-d H:i:s", strtotime("-1 days")); // Get Engineer list into array $result = mysql_query("SELECT FROM location WHERE (status_preset = 'ALLOCATED TO ENGINEER') AND (email <> '')"); // Loop through engineers getting stock more than 7 days old while($row = mysql_fetch_array($result)) { $result2 = mysql_query("SELECT FROM items WHERE (currentloc = 'TRUE') AND (location = '".$row['id']."') AND (amend_date < '".$sevendaysago."') AND (status = 'AVL' OR status = 'ALL' OR status = 'ALLOCATED TO ENGINEER' OR status = 'ALLOCATED TO ENGINEE')"); $row2 = mysql_fetch_array($result2); // Build array into readable format $message if ($row2['id']<>""){ $table = "<html>"; $table .= "<p>Hi $row[name],</p>"; $table .= "<p>The following is a list of stock that was allocated to you 7 or more days ago. "; $table .= "Please could you check your current stock and notify the stores with any amendments required.</p>"; $table .= " "; $table .= " "; $table .= "<table width=\"600\" border=\"1\">"; // Start the table $table .= "<tr>"; $table .= "<td width=\"100\"><strong>Item No.</strong></td>"; $table .= "<td width=\"350\"><strong>Description</strong></td>"; $table .= "<td width=\"200\"><strong>Date Issued</strong></td>"; while($row2 = mysql_fetch_array($result2)) { $table .= "<tr><td>$row2[id]</td>"; $table .= "<td>$row2[description]</td>"; $table .= "<td>$row2[amend_date]</td>"; $table .= "</tr>"; } $table .= "</table>"; // End the table $table .= "</html>"; echo $table; //ini_set("SMTP","localhost"); //ini_set("sendmail_from", "admin@localhost"); //send message $to = $row['email']; $subject = "Weekly Stock Check"; $message = "$table"; $from = "stores@comms-care.com"; if (strtoupper(substr(PHP_OS,0,3)=='WIN')) $eol="\r\n"; elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) $eol="\r"; else $eol="\n"; // Now append $eol variable with header $headers = "From: ".stripslashes($from)." < ".stripslashes($from_email).">".$eol; //specify MIME version 1.0 $headers .= "MIME-Version: 1.0".$eol; //unique boundary $boundary = md5(uniqid(time())); //tell e-mail client this e-mail contains//alternate versions $headers .= "Content-Type: multipart/alternative" . "; boundary =".$boundary.$eol; //message to people with clients who don't //understand MIME $headers .= "This is a MIME encoded message.".$eol; //HTML version of message $headers .= "--".$boundary.$eol . "Content-Type: text/html; charset=ISO-8859-1".$eol . "Content-Transfer-Encoding: 8bit".$eol; if (mail(stripslashes($to), stripslashes($subject), stripslashes($message), $headers)) { echo $row['name']; echo("<p>Email successfully sent!</p>"); } else { echo $row['name']; echo("<p>Message delivery failed...</p>"); } } } // close connection $conn = mysql_close() ?> |
|
J
|
Jane 8/21/2007 |
Jason,
|
S
|
slobbering_dog 8/23/2007 |
Hi Guys, |
S
|
slobbering_dog 8/24/2007 |
Hi again, |