send html table in php mail

Discussion in 'PHP' started by MSK7, Jan 5, 2010.

  1. #1
    Hello all,

    I want to send a html table in php mail .

    
    <html>
    
    <p align='center'> <img src='http://www.mydomain.com/Images/Logo.jpg' width='210' height='45'> </p>
    
    <table cellspacing="4" cellpadding="4" border="1" align="center">
      
      <tr>
      <td align="center">Name</td>
      <td align="center"> John</td>
      <td align="center">Age</td>
      <td align="center">20</td>
      </tr>
      
      <tr>
      <td align="center">Empid</td>
      <td align="center">0014 </td>
      <td align="center">Depart</td>
      <td align="center">IT</td>
      </tr>
      
      <tr>
      <td align="center">Salary</td>
      <td align="center">20000</td>
      <td align="center">Country</td>
      <td align="center">US</td>
      </tr>
      
    </table>
      
    </html>  
    
    Code (markup):
    on sending it simply in the message & then opening the mail ,
    the code is displayed in place of structured table.

    Please help me to send html in php mail so that on opening
    a structured table can be displayed in the recieved mail .


    Thanks & regards.
     
    Last edited: Jan 5, 2010
    MSK7, Jan 5, 2010 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    
    <?php
    $to = "you@gmail.com";
    $subject = "html table";
    
    $message = '
    <html>
    
    <table cellspacing="4" cellpadding="4" border="1" align="center">
      
      <tr>
      <td align="center">Name</td>
      <td align="center"> John</td>
      <td align="center">Age</td>
      <td align="center">20</td>
      </tr>
      
      <tr>
      <td align="center">Empid</td>
      <td align="center">0014 </td>
      <td align="center">Depart</td>
      <td align="center">IT</td>
      </tr>
      
      <tr>
      <td align="center">Salary</td>
      <td align="center">20000</td>
      <td align="center">Country</td>
      <td align="center">US</td>
      </tr>
      
    </table>
      
    </html>
    ';
    
    
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= 'From: <me@me.com>' . "\r\n";
    mail($to,$subject,$message,$headers);
    ?>
    
    Code (markup):
     
    javaongsan, Jan 5, 2010 IP
  3. MSK7

    MSK7 Member

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    Hello javaongsan,

    Thanks for your precious reply.

    on sending the mail according your suggestion,

    on opening the recieved the mail html code itself is displaying ,

    & if i change its mode from settings to html view then the data is

    displayed but without inside any table .


    Please suggest how these can be recieved correctly .


    Thanks.
     
    MSK7, Jan 5, 2010 IP
  4. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #4
    Sorry I don't get what your are saying. I am able to see the table in my mail.
     
    javaongsan, Jan 6, 2010 IP
  5. MSK7

    MSK7 Member

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    Hello javaongsan,

    I am getting the text code like:
    
    Content-type:text/html;charset=iso-8859-1
    From: <myname@mysite.com>
    
    <html>
    
    <table cellspacing="4" cellpadding="4" border="1" align="center">
      
      <tr>
      <td align="center">Name</td>
      <td align="center"> John</td>
      <td align="center">Age</td>
      <td align="center">20</td>
      </tr>
      
      <tr>
      <td align="center">Empid</td>
      <td align="center">0014 </td>
      <td align="center">Depart</td>
      <td align="center">IT</td>
      </tr>
      
      <tr>
      <td align="center">Salary</td>
      <td align="center">20000</td>
      <td align="center">Country</td>
      <td align="center">US</td>
      </tr>
      
    </table>
      
    </html>
    
    
    Code (markup):
    in the recieved mail instead of table & data,

    Please help me to correct these problem.

    Thanks.
     
    Last edited: Jan 6, 2010
    MSK7, Jan 6, 2010 IP
  6. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #6
    are using a email client?
     
    javaongsan, Jan 6, 2010 IP
  7. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    its bery easy
    just use this header
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     
    astkboy2008, Jan 6, 2010 IP
  8. dtkirby

    dtkirby Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If the problem persists, make sure the your text editor is formatted to 'Unix' or 'Linux' and not 'Windows.' The Exchange mail server rejects Windows line return characters in HTML as being illegal and instead displays the HTML as raw text in Outlook. It's rare, but it happens.
     
    dtkirby, Jan 6, 2010 IP