-1

从早上开始我一直在尝试,但最后我必须把它放在 stackoverflow 上。我一直在尝试通过 php 发送 HTML 邮件,当我看到我的邮件时,我得到的 HTML 代码完全不是设计精美的邮件

    <?php
$email = $_POST["email"];
$to = $email;
$from = "arshkapoor2015@gmail.com";
$subject = "Your thebigmall coupon code";
$headers = "From:" . $from;
ob_start();
?>


<html>
    <head>
        <title></title>
    </head>
    <body>
        <p>
            &nbsp;</p>
        <div style="font-size: small; width: 797.4166870117188px; background-color: rgb(236, 236, 236); margin: 0px; padding: 0px; font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; ">
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tbody>
                    <tr style="border-collapse: collapse; ">
                        <td align="center" bgcolor="#ececec" style="border-collapse: collapse; ">
                            <table border="0" cellpadding="0" cellspacing="0" style="margin: 0px 10px; " width="640">
                                <tbody>
                                    <tr style="border-collapse: collapse; ">
                                        <td height="20" style="border-collapse: collapse; " width="640">
                                            &nbsp;</td>
                                    </tr>
                                    <tr style="border-collapse: collapse; ">
                                        <td style="border-collapse: collapse; " width="640">
                                            <table bgcolor="#00707b" border="0" cellpadding="0" cellspacing="0" style="border-top-left-radius: 6px; border-top-right-radius: 6px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; background-color: rgb(4, 57, 72); color: rgb(231, 203, 163); " width="640">
                                                <tbody>
                                                    <tr style="border-collapse: collapse; ">
                                                        <td style="border-collapse: collapse; " width="15">
                                                            &nbsp;</td>
                                                        <td align="left" style="border-collapse: collapse; " valign="middle" width="350">
                                                            <table border="0" cellpadding="0" cellspacing="0" width="350">
                                                                <tbody>
                                                                    <tr style="border-collapse: collapse; ">
                                                                        <td height="8" style="border-collapse: collapse; " width="350">
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                </tbody>
                                                            </table>
                                                            <div style="font-size: 12px; ">
                                                                <a href="http://www.thebigmall.co.in" style="font-weight: bold; color: rgb(231, 203, 163); text-decoration: none; " target="_blank">Web Version</a></div>
                                                            <table border="0" cellpadding="0" cellspacing="0" width="350">
                                                                <tbody>
                                                                    <tr style="border-collapse: collapse; ">
                                                                        <td height="8" style="border-collapse: collapse; " width="350">
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                </tbody>
                                                            </table>
                                                        </td>
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                        <td align="right" style="border-collapse: collapse; " valign="middle" width="255">
                                                            <table border="0" cellpadding="0" cellspacing="0" width="255">
                                                                <tbody>
                                                                    <tr style="border-collapse: collapse; ">
                                                                        <td height="8" style="border-collapse: collapse; " width="255">
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                </tbody>
                                                            </table>
                                                            <table border="0" cellpadding="0" cellspacing="0">
                                                                <tbody>
                                                                    <tr style="border-collapse: collapse; ">
                                                                        <td style="border-collapse: collapse; " valign="middle">
                                                                            <a href="http://preview.createsend3.com/t/j-fb-wukdik-l-t/" rel="cs_facebox" style="font-weight: bold; color: rgb(231, 203, 163); text-decoration: none; " target="_blank"><img alt="Facebook icon" border="0" height="14" src="https://img.createsend1.com/img/templatebuilder/like-glyph.png" style="min-height: auto; line-height: 13px; outline-style: none; display: block; " width="8" /></a></td>
                                                                        <td style="border-collapse: collapse; " width="3">
                                                                            &nbsp;</td>
                                                                        <td style="border-collapse: collapse; " valign="middle">
                                                                            <div style="font-size: 12px; ">
                                                                                <a href="http://preview.createsend3.com/t/j-fb-wukdik-l-i/" rel="cs_facebox" style="font-weight: bold; color: rgb(231, 203, 163); text-decoration: none; " target="_blank">Like</a></div>
                                                                        </td>
                                                                        <td style="border-collapse: collapse; " width="10">
                                                                            &nbsp;</td>
                                                                        <td style="border-collapse: collapse; " valign="middle">
                                                                            <a href="http://client.forwardtomyfriend.com/j-l-2AD73FFF-wukdik-l-d" lang="en" style="font-weight: bold; color: rgb(231, 203, 163); text-decoration: none; " target="_blank"><img alt="Forward icon" border="0" height="14" src="https://img.createsend1.com/img/templatebuilder/forward-glyph.png" style="min-height: auto; line-height: 13px; outline-style: none; display: block; " width="19" /></a></td>
                                                                        <td style="border-collapse: collapse; " width="3">
                                                                            &nbsp;</td>
                                                                        <td style="border-collapse: collapse; " valign="middle">
                                                                            <div style="font-size: 12px; ">
                                                                                <a href="http://client.forwardtomyfriend.com/j-l-2AD73FFF-wukdik-l-h" lang="en" style="font-weight: bold; color: rgb(231, 203, 163); text-decoration: none; " target="_blank">Forward</a></div>
                                                                        </td>
                                                                    </tr>
                                                                </tbody>
                                                            </table>
                                                            <table border="0" cellpadding="0" cellspacing="0" width="255">
                                                                <tbody>
                                                                    <tr style="border-collapse: collapse; ">
                                                                        <td height="8" style="border-collapse: collapse; " width="255">
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                </tbody>
                                                            </table>
                                                        </td>
                                                        <td style="border-collapse: collapse; " width="15">
                                                            &nbsp;</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr style="border-collapse: collapse; ">
                                        <td align="center" bgcolor="#00707b" style="border-collapse: collapse; " width="640">
                                            <table border="0" cellpadding="0" cellspacing="0" width="640">
                                                <tbody>
                                                    <tr style="border-collapse: collapse; ">
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                        <td height="30" style="border-collapse: collapse; " width="580">
                                                            &nbsp;</td>
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                    </tr>
                                                    <tr style="border-collapse: collapse; ">
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                        <td style="border-collapse: collapse; " width="580">
                                                            <div align="center">
                                                                <p style="color: rgb(231, 203, 163); font-family: 'Helvetica Neue', Arial, Helvetica, Geneva, sans-serif; font-size: 36px; margin-top: 0px; margin-bottom: 30px; ">
                                                                    <strong>TheBigMall Coupon code !</strong></p>
                                                            </div>
                                                        </td>
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr style="border-collapse: collapse; ">
                                        <td bgcolor="#ffffff" height="30" style="border-collapse: collapse; " width="640">
                                            &nbsp;</td>
                                    </tr>
                                    <tr style="border-collapse: collapse; ">
                                        <td bgcolor="#ffffff" style="border-collapse: collapse; " width="640">
                                            <table border="0" cellpadding="0" cellspacing="0" width="640">
                                                <tbody>
                                                    <tr style="border-collapse: collapse; ">
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                        <td style="border-collapse: collapse; " width="580">
                                                            <table border="0" cellpadding="0" cellspacing="0" width="580">
                                                                <tbody>
                                                                    <tr style="border-collapse: collapse; ">
                                                                        <td style="border-collapse: collapse; " width="580">
                                                                            <h1 align="left" style="font-size: 18px; line-height: 24px; color: rgb(154, 150, 97); font-weight: bold; margin-top: 0px; margin-bottom: 18px; ">
                                                                                25% off on modular kitchens (Faizabad Road)</h1>
                                                                            <div align="left" style="font-size: 13px; line-height: 18px; color: rgb(68, 68, 68); margin-top: 0px; margin-bottom: 18px; ">
                                                                                <p style="margin-bottom: 15px; ">
                                                                                    <strong>Offer Details</strong></p>
                                                                                <p style="margin-bottom: 15px; ">
                                                                                    Make your kitchen a beautiful place to cook with RECENT KITCHEN WORLD</p>
                                                                                <p style="margin-bottom: 15px; ">
                                                                                    Get 25% discount on total billing amount on modular kitchens manufacturing.&nbsp;</p>
                                                                                <p style="margin-bottom: 15px; ">
                                                                                    Our Products:<br style="line-height: 13px; " />
                                                                                    Marine Ply Shutter (Weather Proof)<br style="line-height: 13px; " />
                                                                                    Marine Ply Carcass (Weather Proof)<br style="line-height: 13px; " />
                                                                                    Acrylic shutter<br style="line-height: 13px; " />
                                                                                    Civil work<br style="line-height: 13px; " />
                                                                                    Chimney<br style="line-height: 13px; " />
                                                                                    150 Colours available</p>
                                                                                <p style="margin-bottom: 15px; ">
                                                                                    Offer for limited period. So don&#39;t leave this opportunity &amp; make your kitchen beautiful !!!</p>
                                                                            </div>
                                                                        </td>
                                                                    </tr>
                                                                    <tr style="border-collapse: collapse; ">
                                                                        <td height="10" style="border-collapse: collapse; " width="580">
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                </tbody>
                                                            </table>
                                                            <table border="0" cellpadding="0" cellspacing="0" width="580">
                                                                <tbody>
                                                                    <tr style="border-collapse: collapse; ">
                                                                        <td style="border-collapse: collapse; " width="580">
                                                                            <p align="left" style="font-size: 18px; line-height: 24px; color: rgb(154, 150, 97); font-weight: bold; margin-top: 0px; margin-bottom: 18px; ">
                                                                                Coupon code !</p>
                                                                            <div align="left" style="font-size: 13px; line-height: 18px; color: rgb(68, 68, 68); margin-top: 0px; margin-bottom: 18px; ">
                                                                                <h1 style="margin-bottom: 15px; text-align: center; ">
                                                                                    12345$randstr$randstr2</h1>
                                                                                <p style="margin-bottom: 15px; ">
                                                                                    &nbsp;</p>
                                                                            </div>
                                                                        </td>
                                                                    </tr>
                                                                    <tr style="border-collapse: collapse; ">
                                                                        <td height="10" style="border-collapse: collapse; " width="580">
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                </tbody>
                                                            </table>
                                                            <table border="0" cellpadding="0" cellspacing="0" width="580">
                                                                <tbody>
                                                                    <tr style="border-collapse: collapse; ">
                                                                        <td style="border-collapse: collapse; " width="580">
                                                                            <p align="left" style="font-size: 18px; line-height: 24px; color: rgb(154, 150, 97); font-weight: bold; margin-top: 0px; margin-bottom: 18px; ">
                                                                                Address :</p>
                                                                            <div align="left" style="font-size: 13px; line-height: 18px; color: rgb(68, 68, 68); margin-top: 0px; margin-bottom: 18px; ">
                                                                                <p style="text-align: center; margin-bottom: 15px; ">
                                                                                    Store Address :Kamta Check Post, Faizabad Road, Opp. Kamta Petrol Pump, Lucknow.<br style="line-height: 13px; " />
                                                                                    City :Lucknow<br style="line-height: 13px; " />
                                                                                    Contact No.9415255816, 9721961276, 9918404211<br style="line-height: 13px; " />
                                                                                    <span style="color: rgb(255, 0, 0); ">Offers valid for 48 hours only.</span></p>
                                                                            </div>
                                                                        </td>
                                                                    </tr>
                                                                    <tr style="border-collapse: collapse; ">
                                                                        <td height="10" style="border-collapse: collapse; " width="580">
                                                                            &nbsp;</td>
                                                                    </tr>
                                                                </tbody>
                                                            </table>
                                                        </td>
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr style="border-collapse: collapse; ">
                                        <td bgcolor="#ffffff" height="15" style="border-collapse: collapse; " width="640">
                                            &nbsp;</td>
                                    </tr>
                                    <tr style="border-collapse: collapse; ">
                                        <td style="border-collapse: collapse; " width="640">
                                            <table bgcolor="#043948" border="0" cellpadding="0" cellspacing="0" style="border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 6px; border-bottom-left-radius: 6px; background-color: rgb(4, 57, 72); color: rgb(226, 226, 226); " width="640">
                                                <tbody>
                                                    <tr style="border-collapse: collapse; ">
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                        <td height="30" style="border-collapse: collapse; " width="360">
                                                            &nbsp;</td>
                                                        <td style="border-collapse: collapse; " width="60">
                                                            &nbsp;</td>
                                                        <td style="border-collapse: collapse; " width="160">
                                                            &nbsp;</td>
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                    </tr>
                                                    <tr style="border-collapse: collapse; ">
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                        <td style="border-collapse: collapse; " valign="top" width="360">
                                                            <p align="left" style="font-size: 12px; line-height: 15px; margin-top: 0px; margin-bottom: 15px; ">
                                                                &nbsp;</p>
                                                            <p align="left" style="font-size: 12px; line-height: 15px; margin-top: 0px; margin-bottom: 15px; ">
                                                                All Rights Reserved &gt; TheBigMall.co.in - Great discounts in your city</p>
                                                        </td>
                                                        <td style="border-collapse: collapse; " width="60">
                                                            &nbsp;</td>
                                                        <td style="border-collapse: collapse; " valign="top" width="160">
                                                            <p align="right" style="font-size: 11px; line-height: 16px; margin-top: 0px; margin-bottom: 15px; color: rgb(231, 203, 163); ">
                                                                &nbsp;</p>
                                                        </td>
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                    </tr>
                                                    <tr style="border-collapse: collapse; ">
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                        <td height="15" style="border-collapse: collapse; " width="360">
                                                            &nbsp;</td>
                                                        <td style="border-collapse: collapse; " width="60">
                                                            &nbsp;</td>
                                                        <td style="border-collapse: collapse; " width="160">
                                                            &nbsp;</td>
                                                        <td style="border-collapse: collapse; " width="30">
                                                            &nbsp;</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr style="border-collapse: collapse; ">
                                        <td height="60" style="border-collapse: collapse; " width="640">
                                            &nbsp;</td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                </tbody>
            </table>
            <img border="0" height="1" src="https://createsend3.com/t/j-o-wukdik-l/o.gif" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important; line-height: 13px; outline-style: none; display: block; " width="1" /></div>
        <div>
            &nbsp;</div>
        <p>
            &nbsp;</p>
    </body>
</html>

<?
$message = ob_get_clean();


mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
4

2 回答 2

3

您缺少邮件标题请参阅 php.net http://php.net/manual/en/function.mail.php中的示例

<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// 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";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

我推荐你 phpmailer http://phpmailer.worxware.com/index.php?pg=examplebmail http://sourceforge.net/projects/phpmailer/

于 2012-10-01T19:44:46.540 回答
1

不幸的是,它并不像在正文中发送 html 那样简单。您需要告诉邮件客户端内容类型和更多步骤。

您最好的选择是使用Pear MailZend_Mail 之类的库来让您的生活更轻松

于 2012-10-01T19:38:39.343 回答