Page 1 of 1

building a mail from the db

Posted: Thu Jan 19, 2006 4:58 am
by rsmarsha
twigletmac | Using

Code: Select all

tags makes syntax errors easier to spot.[/color]


I need to build a mail with results from the database.

Code: Select all

$mesg = 'THIS IS AN ORDER FOR '.$fr['q'].' COMPUTER(S)'."\r\n"
                ."\r\n".'Ex VAT: '.$fr['exvat'].''."\r\n"
	."\r\n".'Price: '.$fr['price'].''."\r\n"
	."\r\n".'Bulk Discount: '.$fr['discount'].''."\r\n"
	."\r\n".'Total ex VAT: '.$fr['totalexvat'].''."\r\n"
	."\r\n".'Total Order Price: '.$fr['total'].''."\r\n"
	."\r\n".''."\n".'Order Number: '.$SR."\r\n"
	."\r\n".'Title: '.$fr['title']."\r\n"
	."\r\n".'Full Name: '.$fr['fullname']."\r\n"
	."\r\n".'Email: '.$fr['username']."\r\n"	
	."\r\n".'Payment Method: '.$fr['payment']."\r\n"
	."\r\n".'Home Tel: '.$fr['hometel']."\r\n"
	."\r\n".'Work Tel: '.$fr['worktel']."\r\n"
	."\r\n".'Mob Tel: '.$fr['mobtel']."\r\n"
	."\r\n".'Date: '.$today."\r\n"
	."\r\n".'Address 1: '.$fr['daddress1']."\r\n"
	.'Address 2: '.$fr['daddress2']."\r\n"
	.'Address 3: '.$fr['daddress3']."\r\n"
	.'Town/City: '.$fr['dtown']."\r\n"
	.'County: '.$fr['dcounty']."\r\n"
	.'Post Code: '.$fr['dpostcode']."\r\n"
	.'Delivery details: '.$fr['deldet']."\r\n"
$build_mail = "SELECT * FROM categories,orders_products WHERE caegories_category_id=orders_products.category_id AND orders_products.orderno='$SR'";
$bq = mysql_query($build_mail, $db_conn) or die("Query $build_mail Failed".mysql_error());
	while ($br = mysql_fetch_assoc($bq))
		{
	                ."\r\n".''.$br['category_name'].': '.$br['description'].''."\r\n"
		}
	mail($emailto, $subj, $mesg, $additional_headers)or die('mail not sent');
The above code won't work as it see's the query and the rest as errors. Any ideas?

Posted: Thu Jan 19, 2006 5:07 am
by twigletmac
Do you get any error messages?

Mac

Posted: Thu Jan 19, 2006 5:23 am
by duk
good point :)

but if you dont get any error message... try to set display_error = on;

Posted: Thu Jan 19, 2006 5:38 am
by rsmarsha
it sees an error at this line:

Code: Select all

$build_mail = "SELECT * FROM categories,orders_products WHERE caegories_category_id=orders_products.category_id AND
Parse error: parse error, unexpected T_VARIABLE in /homepages/40/d108546070/htdocs/test/sec_test/admin/v12_update.php on line 229

Posted: Thu Jan 19, 2006 5:53 am
by JayBird
im guessign the error might be the line before...show all your code

and you have spelt caegories_category_id wrong

Posted: Thu Jan 19, 2006 6:14 am
by Jenk

Code: Select all

.'Delivery details: '.$fr['deldet']."\r\n"
Missing a semi colon ( ; ) on the end of that line.

Posted: Thu Jan 19, 2006 6:37 am
by rsmarsha
If i add the semi colon won't that end the building of the message and not allow the next to be added?

I've changed it to this:

Code: Select all

$mesg = 'THIS IS AN ORDER FOR '.$fr['q'].' COMPUTER(S)'."\r\n"
."\r\n".'Ex VAT: '.$fr['exvat'].''."\r\n"
	."\r\n".'Price: '.$fr['price'].''."\r\n"
	."\r\n".'Bulk Discount: '.$fr['discount'].''."\r\n"
	."\r\n".'Total ex VAT: '.$fr['totalexvat'].''."\r\n"
	."\r\n".'Total Order Price: '.$fr['total'].''."\r\n"
	."\r\n".''."\n".'Order Number: '.$SR."\r\n"
	."\r\n".'Title: '.$fr['title']."\r\n"
	."\r\n".'Full Name: '.$fr['fullname']."\r\n"
	."\r\n".'Email: '.$fr['username']."\r\n"	
	."\r\n".'Payment Method: '.$fr['payment']."\r\n"
	."\r\n".'Home Tel: '.$fr['hometel']."\r\n"
	."\r\n".'Work Tel: '.$fr['worktel']."\r\n"
	."\r\n".'Mob Tel: '.$fr['mobtel']."\r\n"
	."\r\n".'Date: '.$today."\r\n"
	."\r\n".'Address 1: '.$fr['daddress1']."\r\n"
	.'Address 2: '.$fr['daddress2']."\r\n"
	.'Address 3: '.$fr['daddress3']."\r\n"
	.'Town/City: '.$fr['dtown']."\r\n"
	.'County: '.$fr['dcounty']."\r\n"
	.'Post Code: '.$fr['dpostcode']."\r\n"
	.'Delivery details: '.$fr['deldet']."\r\n";
		$build_mail = "SELECT * FROM categories,orders_products WHERE categories.category_id=orders_products.category_id AND orders_products.orderno='$SR'";
		$bq = mysql_query($build_mail, $db_conn) or die("Query $build_mail Failed".mysql_error());
		while ($br = mysql_fetch_assoc($bq))
		{
	."\r\n".''.$br['category_name'].': '.$br['description'].''."\r\n";
		}
		mail($emailto, $subj, $mesg, $additional_headers)or die('mail not sent');
And i get this error:

Parse error: parse error, unexpected '.' in /homepages/40/d108546070/htdocs/test/sec_test/admin/v12_update.php on line 233


If i'm right, thats due to the ; i added ending the building of the mail, so it doesn't see the "." as adding another line to the mail creation.

Posted: Thu Jan 19, 2006 6:42 am
by twigletmac
The semi-colon you added is correct, the problem is this line:

Code: Select all

."\r\n".''.$br['category_name'].': '.$br['description'].''."\r\n";
You need to change it to:

Code: Select all

$mesg .= "\r\n".''.$br['category_name'].': '.$br['description'].''."\r\n";
You can't have all that other code (SQL queries, while loop etc.) whilst setting the $mesg variable.

Mac

Posted: Mon Jan 23, 2006 2:38 am
by rsmarsha
I need to start the mail build earlier in the page as the other info has to come first. The other lines are appended onto the previous ones. If i change the loop within the query won't that redefine the $mesg variable meaning the previous set of info was lost to it?

Posted: Mon Jan 23, 2006 9:11 am
by twigletmac
rsmarsha wrote:If i change the loop within the query won't that redefine the $mesg variable meaning the previous set of info was lost to it?
No - by putting a period in front of the equals sign it means that you are appending to the string. Give it a try.

Mac

Posted: Tue Jan 24, 2006 2:37 am
by rsmarsha
Ah cheers. :) Sorry was just me being a bit blind, hehe didn't even see it. :oops: