Page 1 of 1

How to include SQL output into an outgoing mail??

Posted: Sat Dec 04, 2010 7:14 pm
by huisjames
I have a typical user registration/purchase confirmation scenario. I need to send out a confirmation email but I'm not sure how to include mysql_fetch_array into the body of the mail.
*WAMPServer 2.0
*PHP 5.3.0
*MySQL 5.1.36
*Using PHPMailer script I found and sending via Gmail SMTP server (sent mail with text works)
*The text contains Simplified Chinese

What's wrong with my code?

class database{

Code: Select all

	function query()
	{
		$Paytype=  $_POST['Cardtype'];
		$CarID = $_POST['CarID'];
		$Calendar = $_POST['Calendar'];
		
		//1. Connect/Login to MySQL
		$con = mysql_connect("localhost", "fakeuser", "fakeuser");
		//echo !$con ? 'Could not connect: '.mysql_error() : 'Connection success!<p />';
		
		//2. Tells which db to connect to
		mysql_select_db("carshare", $con);
		
		/*On the MySQL side, set two session control variables: 
		character_set_client=utf8 and character_set_connection=utf8 
		when saving input text to the database table. 
		This is to tell MySQL server that my SQL statement is encoded as UTF-8 and keep it as UTF-8 when executing the statement.
		*/
		mysql_query("SET character_set_client=utf8", $con);
		mysql_query("SET character_set_connection=utf8", $con);
		//When retrieving text data from MySQL, I need to set one session control variable: 
		//character_set_results=utf8. This is to tell MySQL server that result set must be sent back in UTF-8 encoding.
		mysql_query("SET character_set_results=utf8", $con);
		
		//3. Queries the db
		$result = mysql_query("
		SELECT cars.CarID, cars.Img, cars.Year, cars.Make, cars.Model, cars.City, cars.Shift, cars.Distance, cars.Price
		FROM cars
		WHERE cars.CarID=".$CarID."
		") or die(mysql_error());
		
		$date = date('H:i, jS F Y');
		
		$resultcount = mysql_num_rows($result); 
		
		//4. Print results in an array
		while($row = mysql_fetch_array($result))
		{
			echo	"<b>Date: ".$date."</b><p />";
			echo "City: ".$row['City']."<p />";
			echo	"Calendar: ".$Calendar."<p />";
			echo	'<img src="img/large/'.$row['Img'].'" border="1" /><p />';
			echo	"Year: ".$row['Year']."<p />";
			echo	"Make: ".$row['Make']."<p />";
			echo	"Model: ".$row['Model']."<p />";
			echo	"Shift: ".$row['Shift']."<p />";
			echo	"Distance: ".$row['Distance']."<p />";
			echo	"Price: ¥".$row['Price']."<p />";
			echo "Payment method: ".$Paytype."<p />";
		}
		//5. Close connection with db
		$close = mysql_close($con);
	}
}
$object = new database();
$object->query();