Jump to content

[SOLVED] mysql_query in mail() message body


l17wnj

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/145818-solved-mysql_query-in-mail-message-body/
Share on other sites

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>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.