Results 1 to 2 of 2

Thread: How to get an email with multiple records form MySQL displayed using php?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    12

    How to get an email with multiple records form MySQL displayed using php?

    Hi,

    Could you pls tell me how to get an email with multiple records form MySQL displayed using php?

    Suppose, I have 10 fields in a table. and have 25 records. I want to make an email in HTML format which makes query to db and then send s me an email displaying these all 25 records one below the other.

    P.S.: Single record are displayed properly. but the multiple records - the while loop is been used. Thanks


    this is my code

    PHP Code:
    if($nume>=1)
    {
      while(
    $row=mysql_fetch_array($query))
      {
      
    $location=$row["loc_ville"]."[".$row["loc_codepostal"]."]";
      
    $surface=$row["surface"];
      
    $montant=$row["montant"];
      
    $pieces=$row["pieces"];
      
    $description=$row["description"];
      
    $chambres=$row["chambres"];
       
    $ids=$row[0];
      }
      }
                                                
    $message "<html>
        <head>
                <title>mail temp</title>
                </head>
                <body>
                <div align='center'>
                <table border='0' cellpadding='0' cellspacing='0' width='600'>
            <tr>
                <td>

                    <table border='0' cellpadding='0' cellspacing='0' width='600'>
                        <tr>
                            <td><img src='http://www.agencymmo.com/images/mail_banner1.jpg' width='329' height='137' alt='' border='0'></td>        
                            <td><img src='http://www.agencymmo.com/images/mail_banner2.jpg' width='287' height='137' alt='' border='0'></td>
                        </tr>
                        <tr>
                            <td colspan='2'>
                                <table border='0' cellpadding='0' cellspacing='0' width='600'>
                                  <!--DWLayoutTable-->
                                    <tr>
        <td width='28'><img src='http://www.agencymmo.com/images/mail_left_top.jpg' alt='' border='0' height='22' width='28'></td>
    <td width='558' background='http://www.agencymmo.com/images/mail_top_line.jpg'>&nbsp;</td>
    <td width='28'><img src='http://www.agencymmo.com/images/mail_rite_top.jpg' alt='' border='0' height='22' width='28'></td>
                                    </tr>
        <tr>
        <td height='402' background='http://www.agencymmo.com/images/mail_left_vert.jpg'></td>
      <td >
      <table border='0' cellpadding='0' cellspacing='0' width='558'>
       <!--DWLayoutTable-->
                                              <tr>

                                                <td width='558' height='399' >
                                                    <table border='0' cellpadding='0' cellspacing='0' width='558'>
                                                      <!--DWLayoutTable-->
                                                        <tr>
                                                            <td width='558'>
                                                                <table border='0' cellpadding='0' cellspacing='0' width='558'>
                                      <tr>
                                                                        <td align='right' height='30'><span class='s2'>Your login name</span>&nbsp;:&nbsp;<span class='s1'>
    $email.</span></td>

    </tr>
                                                                      <tr>
                                      <td><p class='line'><span class='s1'>Dear customer,</span><br>
        Thanks
    for contacting agency mmo. And here with your annon details are sent
    with complete information.The annon is available on [url]www.agencymmo.com.pls[/url]
    contact.</p></td>
                                                                      </tr>
                                                                      <tr>
                                                                          <td height='10'></td>
                                                                      </tr>
                                                                </table>                                                            </td>
                                                            </tr>
                                                          <tr>
                                                              <td height='40'>
                                                                  <table border='0' cellpadding='0' cellspacing='0' width='558'>
                                                                      <tr>
                                                                          <td class='s4' background='http://www.agencymmo.com/images/mail_button_bg.jpg' width='140'>&nbsp;&nbsp;Matched annonces</td>
                                                                          <td><img src='http://www.agencymmo.com/images/mail_button_edge.jpg' alt='' border='0' height='23' width='32'></td>

                                                                          <td background='http://www.agencymmo.com/images/mail_button_line.jpg' width='390'>&nbsp;</td>
                                                                        </tr>
                                                                 </table>                                                            </td>
                                                          </tr>
                                                          
                                                          <tr>
                                                            <td height='97' >
                                                                  <table border='0' cellpadding='0' cellspacing='0' width='558'>
                                                                    <!--DWLayoutTable-->
                                                                      <tr>

                                                                          <td width='10' height='19'>&nbsp;</td>
                                                                          <td class='s1' width='170'>Location</td>
                                                                          <td align='center' width='11'>:&nbsp;&nbsp;</td>
                                                                          <td class='line' width='100'>.
    $location.</td>
                                                                          <td width='10'>&nbsp;</td>
                                                                         
                                                                            <td class='s1' width='143'><div align='right'><a href='http://www.agencymmo.com/emaildetalisannounce.php?id=
    $ids&ids=$id' class='link9'>Fiche Complete</a></div></td>
                                                                <td width='12'>&nbsp;</td>
                                  </tr>
                                                                        <tr>
            <td height='19'>&nbsp;</td>
                        <td class='s1'>Prixs</td>
                        <td align='center'>:&nbsp;&nbsp;</td>
                                <td class='line'>
    $montant</td>
                                        <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                        </tr>                                <tr>
        <td height='19'>&nbsp;</td>
        <td class='s1'>Surfaces</td>
        <td align='center'>:&nbsp;&nbsp;</td>
        <td class='line'>
    $surface</td>                    <td>&nbsp;</td>                        <td>&nbsp;</td>                            </tr>                            <tr>                                <td height='19'>&nbsp;</td>                <td class='s1'>Nb. of pieces</td>            <td align='center'>:&nbsp;&nbsp;</td>                <td class='line'>$pieces</td>                <td>&nbsp;</td>            <td>&nbsp;</td>                    </tr>                        <tr>        <td height='19'>&nbsp;</td>                <td class='s1'>Chambers</td>            <td align='center'>:&nbsp;&nbsp;</td>                <td class='line'>$chambres</td>                    <td>&nbsp;</td>                    <td>&nbsp;</td>    </tr>                            <tr>                <td height='19'>&nbsp;</td>        <td class='s1'>Description</td>                <td align='center'>:&nbsp;&nbsp;</td>                <td class='line'>$description</td>                    <td>&nbsp;</td>                        <td>&nbsp;</td>                            </tr>                </table></td>                              </tr>
                                                          <tr>                            <td height='26' valign='top'>                   <table border='0' cellpadding='0' cellspacing='0' width='558'>                                                  <tr>
                                                                        
                                                                        <td background='http://www.agencymmo.com/images//mail_button_line.jpg'  border='0' height='' width='390'>&nbsp;</td>
                                                                        <td background='http://www.agencymmo.com/images//mail_button_line.jpg' width='390'>&nbsp;</td>
                                                                        </tr>
                                                                
                                                                </table></td>
                                                          </tr>
                                                           
                                                          <tr>
                                                            <td height='2' valign='top'><hr color='#bda738'></td>
                                                          </tr>
                                                          <tr>
                                                            <td height='29' valign='top'><p class='line' align='center'>
                                                            Please save this email ID to ensure that all communication from agencymmo to reaches you!</p></td>
                                                          </tr>
                                                          <tr>
                                                            <td height='27' align='center' valign='top'><span class='line'>Copy right agency mmo</span>&nbsp;&nbsp;<a href='#' class='ref1'>www.agencymmo.com</a></td>
                                                          </tr>
                                                          <tr>
                                                            <td height='2'></td>
                                                          </tr>
                                                        
                                                </table></td>
                                                </tr>
                                                <tr>
                                                  <td height='3'></td>
                                                </tr>
                                            
                                              </table></td>
                                        <td background='http://www.agencymmo.com/images//mail_rite_vert.jpg'></td>
                                    </tr>
                                    <tr>
                                      <td height='25' valign='top' background=''><img src='http://www.agencymmo.com/images/mail_left_bot.jpg' ' border='0' height='22' width='28'></td>
                                      <td valign='top' background='http://www.agencymmo.com/images/mail_bot_line.jpg'><!--DWLayoutEmptyCell-->&nbsp;</td>
                                      <td valign='top' ><img src='http://www.agencymmo.com/images/mail_rite_bot.jpg' alt='' border='0' height='22' width='28'></td>
                                    </tr>
                                    </table>
                            </td>
                        </tr>

                    </table>
                </td>
            </tr>
            <tr>
                <td></td>
            </tr>
        </table>
        </div>
                            </body>
                            </html>"
    ;
            
    $subject ="Votre compte Announce a été créé";
            
    $headers  "MIME-Version: 1.0\r\n";
            
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        
    /* additional headers */
            
    $headers .= "From: Agencymmo.com<[email protected]>\r\n";
            
    $headers .= "Reply-To:[email protected]\r\n";
            
    mail($email$subject$message$headers);
            
            
            
    ?> 
    Last edited by penagate; Nov 26th, 2007 at 08:16 AM. Reason: added code tags

  2. #2
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Re: How to get an email with multiple records form MySQL displayed using php?

    PHP Code:
    $msg = array(); // keeps the script safe on less secure systems
    if($nume>0)
    {
      while(
    $row=mysql_fetch_array($query))
      {
        
    $location=$row["loc_ville"]."[".$row["loc_codepostal"]."]";
        
    $surface=$row["surface"];
        
    $montant=$row["montant"];
        
    $pieces=$row["pieces"];
        
    $description=$row["description"];
        
    $chambres=$row["chambres"];
        
    $ids=$row[0];
        
    $msg[] = "sometext $location other text {$row["some_array_var"]}..." //etc, you get the picture
      
    }

    Just write the part that changes with the place holder vars in the string (use double quotes only) the curly fellas allowyou to put statements and arrays and "stuff" into your string. Then when you want to output all that use a foreach:

    PHP Code:
    foreach($msg as $m){
      echo 
    $m

    ?
    'What's this bit for anyway?
    For Jono

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width