dlebowski Posted June 5, 2009 Share Posted June 5, 2009 I have a basic mysql query that will return multiple results using mysql_fetch_row. I want those results to be inserted in the the "$mail_body" portion of the email that is going out. I cannot get this to work. The only thing that will work is if I just use a standard "$variable" variable in the "$mail_body". Can someone me with this? Let me know if I need to elaborate. Thank you. <?php $Name = "Da Duder"; //senders name $email = "[email protected]"; //senders e-mail adress $recipient = "[email protected]"; //recipient $mail_body = "The text for the mail..."; //mail body $subject = "Subject for reviever"; //subject $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields mail($recipient, $subject, $mail_body, $header); //mail command ?> Quote Link to comment https://forums.phpfreaks.com/topic/161069-mail-function-wanting-to-send-mysql-query-in-message/ Share on other sites More sharing options...
Jibberish Posted June 5, 2009 Share Posted June 5, 2009 Does the text you are returning from the DB have any html tags in it? as I think this would cause it to fail. You could try adding these to the headers $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; which should let it send ok. (its been a while since i have used e-mails with php though) Quote Link to comment https://forums.phpfreaks.com/topic/161069-mail-function-wanting-to-send-mysql-query-in-message/#findComment-849999 Share on other sites More sharing options...
dlebowski Posted June 5, 2009 Author Share Posted June 5, 2009 Thanks for the reply. It sends all the HTML over fine. It's the query results that will not go over. Quote Link to comment https://forums.phpfreaks.com/topic/161069-mail-function-wanting-to-send-mysql-query-in-message/#findComment-850002 Share on other sites More sharing options...
Jibberish Posted June 5, 2009 Share Posted June 5, 2009 Would you be able to show us the full code? Quote Link to comment https://forums.phpfreaks.com/topic/161069-mail-function-wanting-to-send-mysql-query-in-message/#findComment-850004 Share on other sites More sharing options...
dlebowski Posted June 5, 2009 Author Share Posted June 5, 2009 I want the results of this query, to be sent in the $mail_body. include("dbinfo.$companyname.inc.php"); mysql_connect("localhost",$uname,$pword) or die("cannot connect"); mysql_select_db("$database")or die("cannot select DB"); $query45 = "SELECT itemspurchased FROM items WHERE ID = '1' LIMIT 1"; $result45=mysql_query($query45); $num45=mysql_numrows($result45); while ($row45 = mysql_fetch_row($result45)) { $itemspurchased = $row45[0]; } } Quote Link to comment https://forums.phpfreaks.com/topic/161069-mail-function-wanting-to-send-mysql-query-in-message/#findComment-850009 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.