2012-10-01 62 views
-1

從早上我一直在嘗試,但最後我必須把這個在stackoverflow。我一直在試圖通過PHP發送HTML郵件時,當我看到我的郵件我得到的HTML COADS恰好不是設計精美的郵件如何發送一個HTML設計的郵件通過郵件功能PHP

<?php 
$email = $_POST["email"]; 
$to = $email; 
$from = "[email protected]"; 
$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."; 
?> 
+0

你米發出郵件標題來說出它的html電子郵件 – 2012-10-01 19:37:39

+3

**「width:797.4166870117188px」**我會想到的極端極端,將像素分成兩半是不夠的,但是這樣? :-) – 2012-10-01 19:41:05

+0

請糾正它的代碼我是一個新手,這將是非常有幫助的我 –

回答

3

你缺少郵件標題 從php.net見例如 http://php.net/manual/en/function.mail.php

<?php 
// multiple recipients 
$to = '[email protected]' . ', '; // note the comma 
$to .= '[email protected]'; 

// 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 <[email protected]>, Kelly <[email protected]>' . "\r\n"; 
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n"; 
$headers .= 'Cc: [email protected]' . "\r\n"; 
$headers .= 'Bcc: [email protected]' . "\r\n"; 

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

我建議你PHPMailer的 http://phpmailer.worxware.com/index.php?pg=examplebmail http://sourceforge.net/projects/phpmailer/

+0

謝謝你幫助它解決 –

1

不幸的是它不是那麼簡單,是在發送HTML在體內。你需要告訴郵件客戶端的內容類型和幾個步驟。

最好的辦法是使用庫像Pear MailZend_Mail,使您的生活更輕鬆