l17wnj Posted February 18, 2009 Share Posted February 18, 2009 I'm Using PHP Version 4.4.9 and MySQL 5.0 I wish to send an email with muliple mysql queries in the body of the message. can this be done. i have the script working ok on a but i don't know how to have the mail function read it. Any help would be very much appreciated Thanks Quote Link to comment https://forums.phpfreaks.com/topic/145818-solved-mysql_query-in-mail-message-body/ Share on other sites More sharing options...
premiso Posted February 18, 2009 Share Posted February 18, 2009 Show your current code, chances are no one is just going to blindly write this up for you. It is possible, if it is done right. Quote Link to comment https://forums.phpfreaks.com/topic/145818-solved-mysql_query-in-mail-message-body/#findComment-765608 Share on other sites More sharing options...
l17wnj Posted February 18, 2009 Author Share Posted February 18, 2009 i've got the queries and the mail section working ok i need this table in the message body <table width="100%" border="0" align="right" cellpadding="5" cellspacing="0" class="row1"> <tr> <td class="headingText"><table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#000000" class="tablebody"> <tr> <td colspan="2"><? $querySearch = mysql_query("SELECT * FROM basket WHERE order_ref = '$invoice' ORDER BY `id` ASC"); while($myrowSearch = mysql_fetch_assoc($querySearch)) { ?></td> </tr> <tr> <td class="tablebody"><div align="left"><? echo $myrowSearch['name'] ?></div> <div align="left"></div> <div align="left"></div></td> </tr> <tr> <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="tablebody"> <tr> <td colspan="4"><? $category_id = $myrowSearch['product_id']; $queryLinks = mysql_query("SELECT * FROM images WHERE pk = $category_id ORDER BY `pk` ASC"); while($myrowLinks = mysql_fetch_assoc($queryLinks)) { ?></td> </tr> <tr> <td width="250" class="tablebody"><div align="left"><? $msg1 = $myrowLinks['description'] ?></div></td> <td width="250" class="tablebody"><div align="left"><a href="http://<? echo $myrowLinks['website'] ?>" target="_blank"><? echo $myrowLinks['website'] ?></a></div></td> </tr> <tr> <td colspan="4"><? } ?></td> </tr> </table></td> </tr> <tr> <td colspan="2"><hr size="1" /></td> </tr> <tr> <td colspan="2"><? } ?></td> </tr> </table></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/145818-solved-mysql_query-in-mail-message-body/#findComment-765612 Share on other sites More sharing options...
premiso Posted February 18, 2009 Share Posted February 18, 2009 Well you will need to look up mail MIME types, I do not send emails as HTML, so maybe someone can help you with that part. As far as getting that into a variable for you to utilize try this: <?php ob_start(); ?> <table width="100%" border="0" align="right" cellpadding="5" cellspacing="0" class="row1"> <tr> <td class="headingText"><table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#000000" class="tablebody"> <tr> <td colspan="2"><? $querySearch = mysql_query("SELECT * FROM basket WHERE order_ref = '$invoice' ORDER BY `id` ASC"); while($myrowSearch = mysql_fetch_assoc($querySearch)) { ?></td> </tr> <tr> <td class="tablebody"><div align="left"><? echo $myrowSearch['name'] ?></div> <div align="left"></div> <div align="left"></div></td> </tr> <tr> <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="tablebody"> <tr> <td colspan="4"><? $category_id = $myrowSearch['product_id']; $queryLinks = mysql_query("SELECT * FROM images WHERE pk = $category_id ORDER BY `pk` ASC"); while($myrowLinks = mysql_fetch_assoc($queryLinks)) { ?></td> </tr> <tr> <td width="250" class="tablebody"><div align="left"><? $msg1 = $myrowLinks['description'] ?></div></td> <td width="250" class="tablebody"><div align="left"><a href="http://<? echo $myrowLinks['website'] ?>" target="_blank"><? echo $myrowLinks['website'] ?></a></div></td> </tr> <tr> <td colspan="4"><? } ?></td> </tr> </table></td> </tr> <tr> <td colspan="2"><hr size="1" /></td> </tr> <tr> <td colspan="2"><? } ?></td> </tr> </table></td> </tr> </table> <?php $emailContents = ob_get_contents(); ob_end_clean(); ?> That will put your table created into $emailContents, now you just need to figure out the right mail headers etc to send it as an HTML email. Mail() should have examples of that. Quote Link to comment https://forums.phpfreaks.com/topic/145818-solved-mysql_query-in-mail-message-body/#findComment-765617 Share on other sites More sharing options...
l17wnj Posted February 18, 2009 Author Share Posted February 18, 2009 Thanks very much that worked great. Quote Link to comment https://forums.phpfreaks.com/topic/145818-solved-mysql_query-in-mail-message-body/#findComment-765628 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.