tags:

views:

91

answers:

3

Hi, I am try to send a mail from my php application.Mail send successfully but plain text email which contains html tags.is there any solution for it.Please help me.My message is as follows

 $message = '
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
                    <html xmlns="http://www.w3.org/1999/xhtml"&gt;
                        <head>
                            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                                <title>Gaishan</title>
                        </head>
                        <body>
                            <table width="750" border="0" cellspacing="0" cellpadding="0" style="background-color:#043c58; padding:15px;">
                            <tr>
                                <td style="padding-bottom:10px;"><a href="#"><img src="http://www.toobler.com/staging/gaishan/index.php/users/ec/1/logo_mail.jpg"; border="0" /></a></td>
                            </tr>
                            <tr>
                                <td colspan="2" style="background-color:#fff; padding:10px 30px;"><h1 style="font-family:Arial, Helvetica, sans-serif; font-size:26px; font-weight:bold; color:#111;">testmail</h1>
                                  <p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:normal; color:#555; line-height:22px;">http://www.toobler.com/&lt;/p&gt;
                                      <a href="http://www.toobler.com/" style="font-family:Arial, Helvetica, sans-serif; color:#7ea515; text-decoration:underline;">http://www.toobler.com/staging/gaishan/index.php/users/ec/1/'.time().'&lt;/a&gt;
                                        <p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:normal; color:#4a483f; line-height:22px;">Demo textDemo textDemo textDemo text</p>
                                        <p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:normal; color:#4a483f; line-height:22px;">Demo textDemo textDemo textDemo textDemo text</p>
                                        <br />
                                        <p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:normal; color:#4a483f; line-height:22px;">Demo textDemo textDemo text<br />
                                        Demo textDemo textDemo text Demo textDemo text
                                        </p>
                                </td>
                            </tr>
                        </table>
                    </body>
                </html>
                ';
A: 

You must set: Content-type: text/html; in the header of the mail.

Redlab
+1  A: 

Are you also setting the headers to indicate that the email is supposed to be HTML? If you don't, it will always just be plain text.

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail($to, $subject, $message, $headers);
Mailslut
Agreed, however the encoding (charset) should be utf-8 as this is the one contained in the html, I belileve.
Moritz Both
Thank you very much.working perfectly
Ajith
Well spotted moritz +1
Mailslut
A: 

$headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subject,$message,$headers);

Phil