使用phpmailer发送邮件时未获取CSS

使用phpmailer发送邮件时未获取CSS,php,html,css,phpmailer,Php,Html,Css,Phpmailer,当我发送邮件时没有得到css,只得到没有样式的html内容我的php代码如下,我使用phpmailer。那么,如何用我的html内容得到css样式呢?我总是通过添加$mail->IsHTML(true)来尝试代码;但什么也没发生 require_once('../class.phpmailer.php'); $mail= new PHPMailer(); // defaults to using php "mail()" $mail->IsSendmail(); // telli

当我发送邮件时没有得到css,只得到没有样式的html内容我的php代码如下,我使用phpmailer。那么,如何用我的html内容得到css样式呢?我总是通过添加$mail->IsHTML(true)来尝试代码;但什么也没发生

require_once('../class.phpmailer.php');


$mail= new PHPMailer(); // defaults to using php "mail()"



$mail->IsSendmail(); // telling the class to use SendMail transport



$body= file_get_contents('contents.html');

$body= eregi_replace("[\]",'',$body);



$mail->AddReplyTo("name@yourdomain.com","First Last");


$mail->SetFrom('name@yourdomain.com', 'First Last');



$mail->AddReplyTo("name@yourdomain.com","First Last");



$address = "whoto@otherdomain.com";

$mail->AddAddress($address, "John Doe");



$mail->Subject= "PHPMailer Test Subject via Sendmail, basic";



$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; //     optional, comment out and test

$mail->MsgHTML($body);



$mail->AddAttachment("images/phpmailer.gif");      // attachment

$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment



if(!$mail->Send()) {

echo "Mailer Error: " . $mail->ErrorInfo;

} else {

echo "Message sent!";

}
Html代码:

<head>

<style>
 #outlook a { 
 padding:0; 
} 

body{ 
width:100% !important; 
 min-width: 100%;
-webkit-text-size-adjust:100%; 
-ms-text-size-adjust:100%; 
margin:0; 
padding:0;
}

.ExternalClass { 
width:100%;
} 
 .....etc...................
 .......................
</style>
</head>
<body>
<table class="body">
    <tr>
        <td class="center" align="center" valign="top">
    <center>

      <table class="row header">
        <tr>
          <td class="center" align="center">
            <center>

              <table class="container">
                <tr>
                  <td class="wrapper last">

                    <table class="twelve columns">
                      <tr>
                        <td class="six sub-columns">
                          <img src="http://placehold.it/200x50">
                        </td>
                                                                                         <td class="six sub-columns last" style="text-align:right;     vertical-align:middle;">
                          <span class="template-label">BASIC</span>
                        </td>
                        <td class="expander"></td>
                      </tr>
                    </table>

                  </td>
                </tr>
              </table>

            </center>
          </td>
        </tr>
      </table>

      <table class="container">
        <tr>
          <td>

            <table class="row">
              <tr>
                <td class="wrapper last">

                  <table class="twelve columns">
                    <tr>
                      <td>
                        <h1>Hi, Susan Calvin</h1>
                                    <p class="lead">Phasellus dictum sapien a neque luctus cursus. Pellentesque sem dolor, fringilla et pharetra vitae.</p>
                                    <p>Phasellus dictum sapien a neque luctus cursus. Pellentesque sem dolor, fringilla et pharetra vitae. consequat vel lacus. Sed iaculis pulvinar ligula, ornare fringilla ante viverra et. In hac habitasse platea dictumst. Donec vel orci mi, eu congue justo. Integer eget odio est, eget malesuada lorem. Aenean sed tellus dui, vitae viverra risus. Nullam massa sapien, pulvinar eleifend fringilla id, convallis eget nisi. Mauris a sagittis dui. Pellentesque non lacinia mi. Fusce sit amet libero sit amet erat venenatis sollicitudin vitae vel eros. Cras nunc sapien, interdum sit amet porttitor ut, congue quis urna.</p>
                      </td>
                      <td class="expander"></td>
                    </tr>
                  </table>

                </td>
              </tr>
            </table>

            <table class="row callout">
              <tr>
                <td class="wrapper last">

                  <table class="twelve columns">
                    <tr>
                      <td class="panel">
                        <p>Phasellus dictum sapien a neque luctus cursus. Pellentesque sem dolor, fringilla et pharetra vitae. <a href="#">Click it! »</a></p>
                      </td>
                      <td class="expander"></td>
                    </tr>
                  </table>

                </td>
              </tr>
            </table>

            <table class="row footer">
              <tr>
                <td class="wrapper">

                  <table class="six columns">
                    <tr>
                      <td class="left-text-pad">

                        <h5>Connect With Us:</h5>

                        <table class="tiny-button facebook">
                          <tr>
                            <td>
                              <a href="#">Facebook</a>
                            </td>
                          </tr>
                        </table>

                        <br>

                        <table class="tiny-button twitter">
                          <tr>
                            <td>
                              <a href="#">Twitter</a>
                            </td>
                          </tr>
                        </table>

                        <br>

                        <table class="tiny-button google-plus">
                          <tr>
                            <td>
                              <a href="#">Google +</a>
                            </td>
                          </tr>
                        </table>

                      </td>
                      <td class="expander"></td>
                    </tr>
                  </table>

                </td>
                <td class="wrapper last">

                  <table class="six columns">
                    <tr>
                      <td class="last right-text-pad">
                        <h5>Contact Info:</h5>
                        <p>Phone: 408.341.0600</p>
                        <p>Email: <a href="mailto:hseldon@trantor.com">hseldon@trantor.com</a></p>
                      </td>
                      <td class="expander"></td>
                    </tr>
                  </table>

                </td>
              </tr>
            </table>


            <table class="row">
              <tr>
                <td class="wrapper last">

                  <table class="twelve columns">
                    <tr>
                      <td align="center">
                        <center>
                          <p style="text-align:center;"><a href="#">Terms</a> | <a href="#">Privacy</a> | <a href="#">Unsubscribe</a></p>
                        </center>
                      </td>
                      <td class="expander"></td>
                    </tr>
                  </table>

                </td>
              </tr>
            </table>

          <!-- container end below -->
          </td>
        </tr>
      </table>

    </center>
        </td>
    </tr>
</table>

#展望a{
填充:0;
} 
正文{
宽度:100%!重要;
最小宽度:100%;
-webkit文本大小调整:100%;
-ms文本大小调整:100%;
保证金:0;
填充:0;
}
.ExternalClass{
宽度:100%;
} 
等
.......................
基本的
嗨,苏珊·卡尔文

Phasellus dictum sapien a neque luctus cursus。Pellentesque sem dolor、fringilla和pharetra vitae

圣人的圣名和圣人的圣名。Pellentesque sem dolor、fringilla和pharetra vitae。康塞奎特·韦尔拉克斯。在高原居住区,人们可以看到一种被称为叶舌的植物。我的名字叫Donec vel orci mi,你的名字叫congue justo。整数eget odio est,eget malesuada lorem。埃尼安·塞德·泰勒斯酒后驾车,维韦拉·瑞苏的生命。这是一个智慧的世界,是一个充满活力的世界。毛里斯是一个射手座的酒后驾车者。佩伦茨克非拉西尼亚mi。这是一个自由的世界,一个自由的世界。我是一个智者,我是一个港口工人

圣人的圣名和圣人的圣名。Pellentesque sem dolor、fringilla和pharetra vitae

联系我们:

联系方式: 电话:408.341.0600

电邮:


我认为您使用的是旧版本的,或者至少是旧的示例代码

不要使用ereg*函数-它们已被弃用多年

PHPMailer不会触及您的HTML,只会正确编码,所以您看到的任何内容都会在进入收件箱之前进行服务器端过滤,或者@SLaks说的客户端限制

我知道您正在使用Zurb的Ink框架(不错的选择),但是您需要通过他们的应用程序运行它,以使CSS可靠地工作,特别是在gmail中


为了测试您的内容是否被干净地交付,请使用Apple Mail之类的工具进行测试,它具有所有客户端中最好的呈现效果,并且根本不会弄乱您的内容。Gmail不剥离样式,但它剥离类和ID,这使得CSS毫无用处,除非您将所有内容内联或仅使用基于标记的选择器。

我认为您使用的是旧版本的,或者至少是旧示例代码

不要使用ereg*函数-它们已被弃用多年

PHPMailer不会触及您的HTML,只会正确编码,所以您看到的任何内容都会在进入收件箱之前进行服务器端过滤,或者@SLaks说的客户端限制

我知道您正在使用Zurb的Ink框架(不错的选择),但是您需要通过他们的应用程序运行它,以使CSS可靠地工作,特别是在gmail中


为了测试您的内容是否被干净地交付,请使用Apple Mail之类的工具进行测试,它具有所有客户端中最好的呈现效果,并且根本不会弄乱您的内容。Gmail不剥离样式,但它剥离类和ID,这使得CSS毫无用处,除非您将所有内容内联或仅使用基于标记的选择器。

我认为您使用的是旧版本
<table cellpadding=0" cellspacing="0" width="700" align="center" border="0" bgcolor="#ffffff">