Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to send mail to the user when they register our site in a tabular format but i am unable to fetch the record from database.how can do it.

XML
public function sendMailRegisterToUser()
    {
            $userid     =   @$_SESSION['front_user_id'];
            $query      =   "SELECT * FROM `user` WHERE `id` = '$userid' ";
            $db_query   =   mysql_query($query);
            $row        =   @mysql_fetch_assoc($db_query);

            $first      =   $row['f_name'];
            $last       =   $row['l_name'];
            $username   =   $row['username'];
            $password   =   $row['password'];

            

            $subject    =   '[xyz.com] Account Created';
$message = '<table width="100%"cellspacing="1" cellpadding="1" bgcolor="#CCCCCC">
    <tr>
      <td width="483" height="50"><font color="#CC3333">abc</font></td>
      <td width="208" height="50" align="center"><font color="#CC3333">Tech Support
<br />1-111-979-1234<br />
support@abc.com</font></td>
      <td width="277" height="50" align="right"><font color="#CC3333">Customer Service <br />
1-111-979-0400 <br />
feedback@abc.com</font></td>
    </tr>
     <table width="100%"cellspacing="1" cellpadding="1" bgcolor="#CCCCCC">

    <td width="483" align="center"><font color="#CC3333">Congratulations on your purchase</font>
    </td>
    </table>

  </table>
  <TABLE BORDER="1" WIDTH="100%">
  <TR>
   <TD WIDTH=460>
   <table width="460" border="1" cellspacing="1" cellpadding="1">
    <tr bordercolor="#FFFFFF">
      <td width="244" bgcolor="#000000"> <font color="#FFFFFF">Your Personal info registered with us - </font></td>

    </tr>
    <tr bordercolor="#FFFFFF">
      <td > Your Personal Detail  are </td>

    </tr>
    <tr>
      <td> First Name : </td>
      <td>$message.=$first</td>
    </tr>
    <tr>
      <td> Last Name : </td>
      <td>$last</td>
    </tr>
    <tr>
      <td> Email : </td>
      <td><?php echo $username ; ?></td>
    </tr>
    <tr>
      <td><strong>Primary contact </strong>: </td>
      <td></td>
    </tr>
    <tr>
      <td><strong>Secondary contact </span></strong>: </td>
      <td>&nbsp;</td>
    </tr>
  </table>

   <TD WIDTH="502">

      <table width="502" border="1" style="margin-top:-90px;" >
    <tr>
    <td width="244" bgcolor="#000000"> <font color="#FFFFFF">Your subscription details are - </font></td>


    </tr>
    <tr>
      <td width="244"> Account Number :</td>
      <td width="244">&nbsp;</td>
    </tr>
    <tr>
      <td width="244"> Access code :</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC"> Product subscribed to </td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td> Product Name :</td>
      <td> </td>
    </tr>
    <tr>
      <td> Activation Date :</td>
      <td></td>
    </tr>
    <tr>
      <td> Expiry Date :</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC"> Payment Details </td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td> Amount Charged :</td>
      <td></td>
    </tr>
      </table>
      </TD>
   </TD>
  </TR>
</TABLE>



  ';



            $headers = 'MIME-Version: 1.0' . "\r\n";
            $headers.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
            $headers.= 'From: <support@abc.com> '."\n";


            $to         =   $username;

            @mail($to,$subject,$message,$headers);
            return;
    }


PHP
<pre lang="PHP">
Posted
Updated 14-Aug-12 1:03am
v3

There is a mistake in your header, every line must end with \r\n

and the last line of header will contain \r\n

and is sendMailRegisterToUser function under any class? because I am confused about mysql_connection. make sure your mysql is connected.

add a small verification
C++
if($db_query==false)
{
 echo mysql_error(); // you would know what is your mistake
}


Why are you using this?
$userid = @$_SESSION['front_user_id'];

this has a basic mistake, what if $_SESSION['front_user_id'] is invalid?

use mysql_fetch_assoc instead mysql_fetch_array
 
Share this answer
 
Comments
ambujmalviya 14-Aug-12 6:37am    
my mail function working fine earlier but when i inserted a table in them it crate a problem,and i also tried with mysql_fetch_assoc but it not gives any result
ambujmalviya 14-Aug-12 6:48am    
and second thing my mails are still going but they not show any value from database like first name etc how can i do it.?
i find the solution my self

XML
public function sendMailRegisterToUser()
    {
            $userid     =   @$_SESSION['front_user_id'];
            $query      =   "SELECT * FROM `user` WHERE `id` = '$userid' ";
            $db_query   =   mysql_query($query);
            $row        =   @mysql_fetch_assoc($db_query);

            $first      =   $row['f_name'];
            $last       =   $row['l_name'];
            $username   =   $row['username'];
            $password   =   $row['password'];



            $subject    =   '[xyz.com] Account Created';
$message = '<table width="100%"cellspacing="1" cellpadding="1" bgcolor="#CCCCCC">
    <tr>
      <td width="483" height="50"><font color="#CC3333">abc</font></td>
      <td width="208" height="50" align="center"><font color="#CC3333">Tech Support
<br />1-111-979-1234<br />
support@abc.com</font></td>
      <td width="277" height="50" align="right"><font color="#CC3333">Customer Service <br />
1-111-979-0400 <br />
feedback@abc.com</font></td>
    </tr>
     <table width="100%"cellspacing="1" cellpadding="1" bgcolor="#CCCCCC">

    <td width="483" align="center"><font color="#CC3333">Congratulations on your purchase</font>
    </td>
    </table>

  </table>
  <TABLE BORDER="1" WIDTH="100%">
  <TR>
   <TD WIDTH=460>
   <table width="460" border="1" cellspacing="1" cellpadding="1">
    <tr bordercolor="#FFFFFF">
      <td width="244" bgcolor="#000000"> <font color="#FFFFFF">Your Personal info registered with us - </font></td>

    </tr>
    <tr bordercolor="#FFFFFF">
      <td > Your Personal Detail  are </td>

    </tr>
    <tr>
      <td> First Name : </td>
      <td>'.$first.'</td>
    </tr>
    <tr>
      <td> Last Name : </td>
      <td>'.$last.'</td>
    </tr>
    <tr>
      <td> Email : </td>
      <td><></td>
    </tr>
    <tr>
      <td><strong>Primary contact </strong>: </td>
      <td></td>
    </tr>
    <tr>
      <td><strong>Secondary contact </span></strong>: </td>
      <td> </td>
    </tr>
  </table>

   <TD WIDTH="502">

      <table width="502" border="1" style="margin-top:-90px;" >
    <tr>
    <td width="244" bgcolor="#000000"> <font color="#FFFFFF">Your subscription details are - </font></td>


    </tr>
    <tr>
      <td width="244"> Account Number :</td>
      <td width="244"> </td>
    </tr>
    <tr>
      <td width="244"> Access code :</td>
      <td> </td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC"> Product subscribed to </td>
      <td> </td>
    </tr>
    <tr>
      <td> Product Name :</td>
      <td> </td>
    </tr>
    <tr>
      <td> Activation Date :</td>
      <td></td>
    </tr>
    <tr>
      <td> Expiry Date :</td>
      <td> </td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC"> Payment Details </td>
      <td> </td>
    </tr>
    <tr>
      <td> Amount Charged :</td>
      <td></td>
    </tr>
      </table>
      </TD>
   </TD>
  </TR>
</TABLE>



  ';



            $headers = 'MIME-Version: 1.0' . "\r\n";
            $headers.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
            $headers.= 'From: <support@abc.com> '."\n";


            $to         =   $username;

            @mail($to,$subject,$message,$headers);
            return;
    }

PHP
<pre lang="PHP"><pre lang="PHP">
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900