【问题标题】:fail send html email by using php使用 php 发送 html 电子邮件失败
【发布时间】:2013-09-24 11:57:25
【问题描述】:

当我尝试在 php 上使用 mail() 发送 html 电子邮件时遇到问题,当我尝试使用此代码时,它工作完美

        $bodyhtml="<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>

<div dir='RTL'> 
    <p dir='RTL'>      
        <table> 
            <tr> 
                <td> 
                    <div>  
                        <p dir='RTL'><strong><span style='color:#00B0F0'>Hi</span></strong></p> 
                        <p dir='RTL'><strong><span style='color:#FFC000'>Test</span></strong></p> 
                        <p dir='RTL'><span style='color:#404040'>Test</span></p> 
                        <p dir='RTL'><span style='color:#404040'>Test</span></p>  </div></td> </tr> </table>       
                        </p>    
                        </div> </body></html>";
        $headers = "From: " . $email. "\r\n";
        $headers .= "Reply-To: ". $email . "\r\n";
        $headers .= "CC: me@gmail.com\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=utf-8\r\n";
        mail($email, $subject, $bodyhtml, $headers);

但是当我尝试使用 html 按摩放置图像时:

        $bodyhtml="<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>

<div dir='RTL'> 
    <p dir='RTL'>                      </p> 
    <p dir='RTL'>      
        <table> 
            <tr> 
            <img src='http://xxxxxx/form/image/image001.png' />
                <td> 
                    <div>  
                        <p dir='RTL'><strong><span style='color:#00B0F0'>Hi</span></strong></p> 
                        <p dir='RTL'><strong><span style='color:#FFC000'>Test</span></strong></p> 
                        <p dir='RTL'><span style='color:#404040'>Test</span></p> 
                        <p dir='RTL'><span style='color:#404040'>Test</span></p>  </div></td> </tr> </table>         </p>        </div> </body></html>";
        $headers = "From: " . $email. "\r\n";
        $headers .= "Reply-To: ". $email . "\r\n";
        $headers .= "CC: technomedia.ws@gmail.com\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=utf-8\r\n";
        mail($email, $subject, $bodyhtml, $headers);

发送按摩失败,是什么问题或我该如何解决?

【问题讨论】:

  • 如果您发布不工作的代码而不是工作的代码可能会有所帮助
  • 尝试将&lt;img&gt; 放在&lt;td&gt; 中,如果你把桌子弄乱了,可能会发生奇怪的事情
  • 还要确保您有错误报告,实际的错误消息也可能会有所帮助
  • @GeraldSchneider 好的,我正在编辑我的帖子
  • @GeraldSchneider 当我尝试将 放入 时它也失败了,我如何阅读报告?我的空间没有error_log

标签: php html email


【解决方案1】:

只需阅读 php 文档:

最后,如果您添加一张图片并希望它显示在您的电子邮件中, 将 Content-Type 从附件更改为内联:

$message .= "Content-Disposition: inline; filename=\"$theFile\"\n\n"; 

http://php.net/manual/fr/function.mail.php

编辑:您的解决方案可能在这里 -> http://www.phpeveryday.com/articles/PHP-Email-Using-Embedded-Images-in-HTML-Email-P113.html

【讨论】:

  • 这仅适用于电子邮件中发送的图像,不适用于从外部来源链接的图像
【解决方案2】:

尝试正确使用img标签:

<img src='http://xxx/form/image/image001.png' />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多