使用php邮件在电子邮件中未显示图片

时间:2018-09-12 11:48:56

标签: php html email html-email

我正在尝试使用php代码发送电子邮件邮件正在工作,但图像未进入邮件。图片src路径带有如下编码字符串

<img style="width:100%" src="https://ci6.googleusercontent.com/proxy/NT6fQckS1LLRnuTUJnW0Fp2qUujk_Cpv9kV1hwoKQADwL8XU7fo4=s0-d-e1-ft#http://header.png" class="CToWUd a6T" tabindex="0">

<?php
        $to = $_REQUEST['email'];
        $subject = 'Winning prize';
        $email_id =  'info@sample.com';
        $headers = "From: " . strip_tags($email_id) . "\r\n";
        $headers .= "Reply-To: " . strip_tags($email_id) . "\r\n";
        $headers .= "CC: satishv@sample.com";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
      $message = '<html>
       <head>
          <title></title>
       </head>
       <body>
          <div style="border:1px solid #e96000; width: 600px;">
          <table style="color: #777;font-family: sans-serif;" width="600">
             <tr>
                <td style="padding:0px 0">
                   <img style="width: 100%;" src="header.png">
                </td>
             </tr>
             <tr>
                <td><span style="font-family: sans-serif;">Hey</span><span style="font-family: sans-serif;margin-left: 5px;">'.$address['customer_name'].'!,</span></td>
             </tr>
             <tr>
                <td style="padding:20px 0 0 20px"><span style="font-family: sans-serif;">Congratualtion! The product is Yours.</span></td>
             </tr>

          </table>
          <table style="color: #777;font-family: sans-serif;text-align: center;" width="600">   
             <tr>
                <td colspan="4" style="padding: 30px 0;border-top: 1px solid #e96000;border-bottom: 1px solid #e96000;"><span>Once Your Package ships we will send your a tracking number Once Your Package ships we will send your a tracking number Once Your Package ships we will send your a tracking number </span></td>
             </tr>
          </table>
       </div>
       </body>
    </html>';
        $result = mail($to, $subject, $message, $headers);

?>

上面的代码是工作文件,只是图像没有进入邮件

1 个答案:

答案 0 :(得分:1)

大多数电子邮件客户端会阻止图像。但是,您仍然可以显示图像。您必须使用绝对图像源URL。例如

<img style="width: 100%;" src="header.png">

更改为

<img style="width: 100%;" src="http://www.YourSite.com/header.png">

请确保路径中存在该图像。