失败使用PHP发送HTML电子邮件

时间:2013-09-24 11:57:25

标签: php html email

当我尝试使用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);

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

2 个答案:

答案 0 :(得分:0)

请阅读php doc:

  

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

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

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

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

答案 1 :(得分:-1)

请尝试正确使用img标记:

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