dongzanghong4379 2010-11-29 19:06
浏览 29

使用php Mail / mime发送html和内嵌图像

I am using php/Mail_mime to send styled html content using the code below.

$headers = array ('From' => $sender,
          'To' => implode(',',$to), 
          'Subject' => $subject,
          'Reply-To'=>'myemail@mydomain.com',
          'MIME-Version'=>'1.0',
          'Content-Type'=>'text/html'
    ); 
    /*end header*/

    $this->mime = new Mail_mime();
    $tt=$this->mime;
    $tt->addBcc(implode(',',$bcc));
    $tt->addCc(implode(',',$cc));
    $tt->setTXTBody($text);
    $tt->setHTMLBody($body);
    $tt->addHTMLImage('../images/delete.gif');
//  $tt->addAttachment('../images/delete.gif','image/gif');
    $mime_body = $tt->get();
    $mime_hdrs = $tt->headers($headers);

    $smtp = Mail::factory('smtp',
    array ('host' => $this->host,
            'port' => $this->port, 
            'auth' => false, 
            'username' => $this->username, 
            'password' => $this->password)); 
    $recipients=array_merge($to,$cc,$bcc);
    $mail = $smtp->send($recipients, $mime_hdrs, $mime_body);

This is all a class code, so initialization is done on the constructor, which is not posted here.

Now my question is, while the above code works fine, i didnt see the correct style on the email sent.

for example if i have this as a message body of my email:

<div style="background-color:silver;">

<h1>MY Header</h1> </div>

On my email, I can only see the My Header. The background didnt showup as silver.

What did i miss on my code above. Any help ?

  • 写回答

1条回答 默认 最新

  • dongniuxia8650 2010-11-29 22:16
    关注

    Its quite possible that the email provider you are using doesn't allow HTML code in the emails, or it restricts CSS styling in the allowed HTML code. Which email provider are you using?

    You might want to test this by sending an email to a gmail.com email address, which does allow html code, and see if it makes any difference.

    Another thing to test would be to do a view source, or inspect element if you're using google chrome or firebug in firefox, and see if the html code is being placed where it should be.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度