2014-01-06 55 views
-1

我们希望在HTML电子邮件模板中包含multipart/alternative(纯文本)支持。我搜索了Google的具体示例,但找不到它。这是一个带有定制时事通讯模块的经典ASP网站。我知道现代通讯服务已经支持这种功能。电子邮件中的multipart/alternative支持

我问这个问题的原因是因为在Google上搜索时没有明确的指示。还有很多网站都提到时事通讯服务。

模板:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <meta http-equiv="Content-Style-Type" content="text/css"> 
    <title></title> 

<style type="text/css"> 
    /* setting font style for Outlook 2007 */ 
    body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,p,pre,blockquote,th,td,span,em { 
     color: #ffffff; 
     font-family: 'Trebuchet MS', sans-serif; 
     font-size: 15px; 
     line-height: 1.333em; 
    } 
    body { 
     margin: 0; 
     padding: 0; 
    } 
    p { 
     margin: 0 0 1.3em 0; 
    } 
</style> 
</head> 

<body style=" 
     margin: 0; 
     padding: 0; 
     color: #646567; 
     font-family: 'Trebuchet MS', sans-serif; 
     font-size: 15px; 
     line-height: 1.333em; 
     background: #281E14"> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#281E14" style="background: #281E14"><tr><td valign="top" bgcolor="#281E14"> 
     <table width="680" border="0" cellspacing="0" cellpadding="0" id="DesignTester" align="center" bgcolor="#000000"> 
      <tr> 
       <td style="height: 28px;" height="28">&nbsp;</td> 
      </tr> 
      <tr> 
       <td> 
        <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
         <tr> 
          <td valign="bottom" style="padding-bottom: 20px; padding-left: 20px;"> 
           <h1 style="margin: 0; color: #FF0000; font-size: 30px; font-weight: bold;">##Titel##</h1> 
          </td> 
          <td align="right" valign="bottom" style="padding-bottom: 15px; padding-right: 20px;"> 
           <img src="http://##URL##/BeheerSjablonen/nieuwsbrief/images/logo.gif" alt="" width="129" height="70"> 
          </td> 
         </tr> 
         <tr> 
          <td valign="bottom" style="padding-bottom: 20px; padding-left: 20px;"> 
           &nbsp; 
          </td> 
          <td align="right" valign="bottom" style="padding-bottom: 15px; padding-right: 20px;"> 

          </td> 
         </tr> 
         <tr> 
          <td colspan="2"> 
           <img src="http://##URL##/BeheerSjablonen/nieuwsbrief/images/divider.gif" alt="" width="680" height="2"> 
          </td> 
         </tr> 
        </table> 
       </td> 
      </tr> 
      <tr> 
       <td style="padding: 24px 0"> 
        ##Intro## 
        ##Inhoud## 
       </td> 
      </tr> 
      <tr> 
       <td style="padding: 24px 0"> 
        ##Films## 
       </td> 
      </tr> 
     </table> 
    </td></tr></table> 
</body> 
</html> 

谢谢!

+0

请询问这样一个问题之前做更多的研究,并创建一些代码进行审查,看看有什么是错的。 SO是为了帮助你已经编写的代码。 –

回答

0

多部分电子邮件:(source):

$notice_text = "This is a multi-part message in MIME format."; 
$plain_text = "This is a plain text email.\r\nIt is very cool."; 
$html_text = "<html><body>This is an <b style='color:purple'>HTML</b>" . 
      "text email.\r\nIt is very cool.</body></html>"; 

$semi_rand = md5(time()); 
$mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand"; 
$mime_boundary_header = chr(34) . $mime_boundary . chr(34); 

$to = "Me <[email protected]>"; 
$bcc = "You <[email protected]>, Them <[email protected]>"; 
$from = "Me.com <[email protected]>"; 
$subject = "My Email"; 

$body = "$notice_text 

--$mime_boundary 
Content-Type: text/plain; charset=us-ascii 
Content-Transfer-Encoding: 7bit 

$plain_text 

--$mime_boundary 
Content-Type: text/html; charset=us-ascii 
Content-Transfer-Encoding: 7bit 

$html_text 

--$mime_boundary--"; 

if (@mail($to, $subject, $body, 
    "From: " . $from . "\n" . 
    "bcc: " . $bcc . "\n" . 
    "MIME-Version: 1.0\n" . 
    "Content-Type: multipart/alternative;\n" . 
    "  boundary=" . $mime_boundary_header)) 
    echo "Email sent successfully."; 
else 
    echo "Email NOT sent successfully!"; 
相关问题