Loading ...
Sorry, an error occurred while loading the content.

how can i use while loop inside message body in mail() using php?

Expand Messages
  • sheenrose_joseph
    hello, i want to send am email.am attaching my code with this mail.
    Message 1 of 2 , Mar 31 10:52 PM
    • 0 Attachment
      hello,
      i want to send am email.am attaching my code with this mail.


      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <?php
      $uname=$_SESSION['UID'];
      $Date=date("Y-m-d");
      $month=date("m");
      $f=0;
      $link = mysql_connect("localhost","root","kushal")or die();
      mysql_select_db('mysql') or die();
      $query = "select
      SUM(Manjusha),SUM(Sheen),SUM(Partha),DATE_FORMAT(Logindate,'%a') as s1
      from score group by Logindate having (Logindate = '2008-03-24') ";
      $result = mysql_query($query) or die ('error');
      while($row=mysql_fetch_array($result))
      {
      switch ($uname)
      {
      case 'manjusha' : $s1=$row['SUM(Manjusha)'];
      break;
      case 'sheen' : $s1=$row['SUM(Sheen)'];
      break;
      case 'suresh' : $s1=$row['SUM(Partha)'];
      break;

      default:print "no such user";
      }
      $day=$row['s1'];
      $avg=$s1/3;

      }


      echo $avg;

      if($day=='Mon')
      {
      $f=0;

      }
      else
      {
      $f=$f+1;
      }
      $query1 = "insert into avg values('".$day."','".$avg."','".$f."')";
      $result1 = mysql_query($query1);

      $query2 = "select day,score from avg where status=1";
      $result2 = mysql_query($query2);

      $to = 'sheen.rose@...' . ', '; // note the comma
      $to .= 'manjusha.valsan@...';
      /*$to = 'manjusha@...';*/
      $subject = 'Weekly Report';
      $message = "<html>
      <body>
      <h3><center>Average Score for $uname On $Date</center></h3>
      <table border=1>
      <tr>

      <th>Days</th>
      <th>Average score</th>
      </tr>
      <?php while($col=mysql_fetch_array($result2,MYSQL_ASSOC)))
      { ?>

      <tr>
      <td>{$col['day']}</td>
      <td>{$col['score']}</td>
      </tr>
      <?php } ?>

      </table>
      </body>
      </html>";


      $headers = 'From: sheen@...' . "\r\n" .
      'Reply-To: webmaster@...' . "\r\n" .
      'X-Mailer: PHP/' . phpversion();
      /* To send HTML mail, you can set the Content-type header. */
      $headers .= "MIME-Version: 1.0\r\n";
      $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
      if ($f == 0)
      {
      mail($to, $subject, $message, $headers);
      echo "mail delivered";
      $f=0;

      //$query2="update table avg set status='".$f."'";
      //$result2 = mysql_query($query2);
      }
      ?>
      <html>
      <head>
      <title>Sign Out</title>
      <style>
      body {background:#B0C4DE; font-family:Verdana; font-size:12}
      table {font-family:Verdana; font-size:12}
      a {text-decoration:none;}
      a:visited {color:red}
      a:hover {color:yellow}
      </style>
      </head>
      <body >
      <?php $uname=$_SESSION['UID']; ?>
      <table width=750 height=350>
      <tR>
      <td>
      <center>
      <table><tr><td><img
      src="https://www.google.com/a/cpanel/etchr.com/images/logo.gif?service=mail"></td></tr></table>
      </center>
      </tr>
      </td>
      <tr>
      <td>
      <?
      $link = mysql_connect("localhost","root","kushal")
      or die();
      mysql_select_db('mysql') or die();

      /* Performing SQL query */
      $query = " update userinfo set online='0' where
      Email_id='".$uname."'";
      $result =mysql_query($query);
      mysql_close($link);



      exec("sudo rm /upload/$uname/*.* -d -r -f ");
      unset($_SESSION['UID']);
      unset($_SESSION['addr']);
      unset($_SESSION['attachtype']);
      unset($_SESSION['attachfile']);
      unset($_SESSION['attachsize']);
      session_destroy();
      ?>
      <center>
      <table width=650 height=250 >
      <tr>
      <td>
      <center>
      <font color="#008000" size=5 face="VERDANA, ARIAL" >
      <b>You've signed out successfully!<br></b>
      <br><a href="login.html">SignIn</a><b> as different user.<br></font>
      <i><h5><p><br><br><br><br>
      Thank you <br>
      Have a nice day!</i></b></h5>
      </center>
      </td>
      </tr>
      </table>
      </center>
      </td>
      </tr>
      </table>
      </body>
      </html>


      and the while loop inside the message body doesnt work...can any one
      help me out??
    • Vinu Thomas
      Try this code for your message body instead: $message = Average Score for $uname On $Date
      Message 2 of 2 , Apr 1, 2008
      • 0 Attachment
        Try this code for your message body instead:
        $message = "<html>
        <body>
        <h3><center>Average Score for $uname On $Date</center></h3>
        <table border=1>
        <tr>

        <th>Days</th>
        <th>Average score</th>
        </tr>";
        while($col=mysql_fetch_array($result2,MYSQL_ASSOC)))
        {
        $message .="<tr>
        <td>{$col['day']}</td>
        <td>{$col['score']}</td>
        </tr>";
        }
        $message .= "</table>
        </body>
        </html>";


        Regards,
        Vinu

        On Tue, Apr 1, 2008 at 11:22 AM, sheenrose_joseph
        <sheenrose_joseph@...> wrote:
        >
        >
        >
        >
        >
        >
        > hello,
        > i want to send am email.am attaching my code with this mail.
        >
        > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        > <?php
        > $uname=$_SESSION['UID'];
        > $Date=date("Y-m-d");
        > $month=date("m");
        > $f=0;
        > $link = mysql_connect("localhost","root","kushal")or die();
        > mysql_select_db('mysql') or die();
        > $query = "select
        > SUM(Manjusha),SUM(Sheen),SUM(Partha),DATE_FORMAT(Logindate,'%a') as s1
        > from score group by Logindate having (Logindate = '2008-03-24') ";
        > $result = mysql_query($query) or die ('error');
        > while($row=mysql_fetch_array($result))
        > {
        > switch ($uname)
        > {
        > case 'manjusha' : $s1=$row['SUM(Manjusha)'];
        > break;
        > case 'sheen' : $s1=$row['SUM(Sheen)'];
        > break;
        > case 'suresh' : $s1=$row['SUM(Partha)'];
        > break;
        >
        > default:print "no such user";
        > }
        > $day=$row['s1'];
        > $avg=$s1/3;
        >
        > }
        >
        > echo $avg;
        >
        > if($day=='Mon')
        > {
        > $f=0;
        >
        > }
        > else
        > {
        > $f=$f+1;
        > }
        > $query1 = "insert into avg values('".$day."','".$avg."','".$f."')";
        > $result1 = mysql_query($query1);
        >
        > $query2 = "select day,score from avg where status=1";
        > $result2 = mysql_query($query2);
        >
        > $to = 'sheen.rose@...' . ', '; // note the comma
        > $to .= 'manjusha.valsan@...';
        > /*$to = 'manjusha@...';*/
        > $subject = 'Weekly Report';
        > $message = "<html>
        > <body>
        > <h3><center>Average Score for $uname On $Date</center></h3>
        > <table border=1>
        > <tr>
        >
        > <th>Days</th>
        > <th>Average score</th>
        > </tr>
        > <?php while($col=mysql_fetch_array($result2,MYSQL_ASSOC)))
        > { ?>
        >
        > <tr>
        > <td>{$col['day']}</td>
        > <td>{$col['score']}</td>
        > </tr>
        > <?php } ?>
        >
        > </table>
        > </body>
        > </html>";
        >
        > $headers = 'From: sheen@...' . "\r\n" .
        > 'Reply-To: webmaster@...' . "\r\n" .
        > 'X-Mailer: PHP/' . phpversion();
        > /* To send HTML mail, you can set the Content-type header. */
        > $headers .= "MIME-Version: 1.0\r\n";
        > $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        > if ($f == 0)
        > {
        > mail($to, $subject, $message, $headers);
        > echo "mail delivered";
        > $f=0;
        >
        > //$query2="update table avg set status='".$f."'";
        > //$result2 = mysql_query($query2);
        > }
        > ?>
        > <html>
        > <head>
        > <title>Sign Out</title>
        > <style>
        > body {background:#B0C4DE; font-family:Verdana; font-size:12}
        > table {font-family:Verdana; font-size:12}
        > a {text-decoration:none;}
        > a:visited {color:red}
        > a:hover {color:yellow}
        > </style>
        > </head>
        > <body >
        > <?php $uname=$_SESSION['UID']; ?>
        > <table width=750 height=350>
        > <tR>
        > <td>
        > <center>
        > <table><tr><td><img
        >
        > src="https://www.google.com/a/cpanel/etchr.com/images/logo.gif?service=mail"></td></tr></table>
        > </center>
        > </tr>
        > </td>
        > <tr>
        > <td>
        > <?
        > $link = mysql_connect("localhost","root","kushal")
        > or die();
        > mysql_select_db('mysql') or die();
        >
        > /* Performing SQL query */
        > $query = " update userinfo set online='0' where
        > Email_id='".$uname."'";
        > $result =mysql_query($query);
        > mysql_close($link);
        >
        >
        >
        > exec("sudo rm /upload/$uname/*.* -d -r -f ");
        > unset($_SESSION['UID']);
        > unset($_SESSION['addr']);
        > unset($_SESSION['attachtype']);
        > unset($_SESSION['attachfile']);
        > unset($_SESSION['attachsize']);
        > session_destroy();
        > ?>
        > <center>
        > <table width=650 height=250 >
        > <tr>
        > <td>
        > <center>
        > <font color="#008000" size=5 face="VERDANA, ARIAL" >
        > <b>You've signed out successfully!<br></b>
        > <br><a href="login.html">SignIn</a><b> as different user.<br></font>
        > <i><h5><p><br><br><br><br>
        > Thank you <br>
        > Have a nice day!</i></b></h5>
        > </center>
        > </td>
        > </tr>
        > </table>
        > </center>
        > </td>
        > </tr>
        > </table>
        > </body>
        > </html>
        >
        > and the while loop inside the message body doesnt work...can any one
        > help me out??
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.