WatsonN Posted October 27, 2010 Share Posted October 27, 2010 I am trying to print the contents of my database into mail function and send it but i'm not sure how this is done. i already have the code to print all the data needed, I just don't know how to get it into the e-mail <?php // Connects to your Database mysql_connect(***) or die(mysql_error()); mysql_select_db("loginwatsonn") or die(mysql_error()); ?> <p>Yearbook Users</p> <table class="listing" cellpadding="0" cellspacing="0"> <tr> <th>ID </th> <th>UID </th> <th>Ads Sold </th> <th>mail </th> <th>Allowed </th> </tr> <tr> <?php $data = mysql_query("SELECT y.*,COUNT(ads.UID) AS posts FROM YBK_Login AS y LEFT JOIN YBK_Ads AS ads ON ads.UID=y.ID GROUP BY y.ID") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { Print "<tr>"; Print "<td>".$info['ID'] . " </td>"; Print "<td>".$info['UID'] . "</td> "; Print "<td> ".$info['posts'] . " </td>"; Print "<td>".$info['mail'] . " </td>"; Print "<td> ".$info['Allowed'] . "</td>"; } ?></tr></table><br><br> Quote Link to comment https://forums.phpfreaks.com/topic/216942-php-mail-and-mysql/ Share on other sites More sharing options...
trq Posted October 27, 2010 Share Posted October 27, 2010 Put this before your current code.... <?php ob_start(); ?> And this at the end..... <?php $data = ob_get_clean(); // $data now contains your output. Send email using mail. Quote Link to comment https://forums.phpfreaks.com/topic/216942-php-mail-and-mysql/#findComment-1126977 Share on other sites More sharing options...
WatsonN Posted October 27, 2010 Author Share Posted October 27, 2010 Thank you I did that and it sends the code itself instead of formatting it. What do i need to chnge? // ---------------- SEND MAIL FORM ---------------- $to="[email protected]"; $subject="Weekly user report!"; $header="from: Yearbook Ads <[email protected]>"; $headers .= "X-Mailer: NLW\n"; $headers .= "X-Priority: 1\n"; $headers .= "Return-Path: [email protected] \n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $messages= "Here is the weekly report of all users and the ads sold. . . \r\n"; $messages .= $data; $sentmail = mail($to,$subject,$messages,$header); ?> Quote Link to comment https://forums.phpfreaks.com/topic/216942-php-mail-and-mysql/#findComment-1127287 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.