Вопрос

We would like to include multipart/alternative (plain-text) support in a HTML email template. I've searched Google for concrete examples, but couldn't find it. It's a classic ASP website with a custom newsletter module. I know that modern newsletter services already support such feature.

The reason I'm asking this, is because there are no clear directions given when searching on Google. Also a lot websites are referring to newsletter services.

The template:

<!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>

Thank you!

Это было полезно?

Решение

Multipart Email: (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 <me@me.com>";
$bcc = "You <you@you.com>, Them <them@them.com>";
$from = "Me.com <me@me.com>";
$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!";
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top