用php显示html电子邮件中的图像 [英] Display image in html e-mail with php

查看:161
本文介绍了用php显示html电子邮件中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一些有关这方面的话题,已经尝试过许多话题,但是没有一个人工作到目前为止。所以我现在很失去了现在要做的事情,在电子邮件中显示这些图像是非常重要的。

I've read a few topics about this, already tried many of them, but none of them worked so far. So I'm kinda lost what to do now, it would be really important to display these images in the e-mail.

这是我的代码的缩写版本:

Here is a shortened version of my code:

require_once("class.phpmailer.php");
$body = '
    <body style="margin: 10px auto;">
            <table width="100%">
                <tr>
                    <td width="360">
                        <img src="cid:trip_2" alt="trip_2">
                        <!--<img src="trip_2.png" alt="trip_2">-->
                    </td>
                </tr>
            </table>
            <table width="100%">
                <tr>
                    <td align="right" width="360">
                        <img src="cid:pic" alt="pic">
                        <!--<img src="pic.png" alt="pic">-->
                    </td>
                </tr>
            </table>
            <table width="100%">
                <tr>
                    <td width="360">
                        <img src="cid:pub" alt="pub">
                        <!--<img src="pub.png" alt="pub">-->
                    </td>
                </tr>
            </table>
        </div>
    </body>';

    $mail = new PHPMailer();

    $mail->Host       = "smtp.gmail.com";
    $mail->Port       = 25;
    $mail->Username   = "*****";
    $mail->Password   = '*****'

    $mail->IsHTML(true);
    $mail->Subject = "Please appear";
    $mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
    $mail->SetFrom("example@example.com","Example");
    $mail->AddReplyTo("example@example.com","Example");
    $mail->AddAddress("example@example.com", "Example");

    $mail->AddEmbeddedImage("trip_2.png", "trip_2","trip_2.png");
    //$mail->AddAttachment("trip_2.png");
    $mail->AddEmbeddedImage("pic.png", "pic","pic.png");
    //$mail->AddAttachment("pic.png");
    $mail->AddEmbeddedImage("pub.png", "pub","pub.png");
    //$mail->AddAttachment("pub.png");
    $mail->MsgHTML($body);

    $mail->Send();

我想要实现的是在电子邮件中默认显示这3个图像。所以用户不必点击从这个地址显示图像或类似的东西。因为没有图像,电子邮件将是一个空的,我们需要一些风格的电子邮件。

What I want to achieve is to display these 3 images in the e-mail, by default. So the user don't have to click "display images from this address" or something like that. Because without the images, the e-mail would be kinda empty, and we need some style in the e-mail.

对不起,我的语法的人,
谢谢你的时间。

Sorry about my grammar Guys, thank you for your time.

标记

推荐答案


您无法在用户批准您的图像。这是一种反垃圾邮件/反追踪技术,默认情况下必须关闭。

In gmail: You can't without the user approving your imagery. It's an anti-spam/ anti-tracking technique that has to be off by default to work.

您可以使Gmail显示图像(嵌入内容),并发送电子邮件。您只需确保您具有正确的SPF记录,并且1024位DKIM签名消息。然后gmail在内容中显示嵌入的图像。

You can make Gmail display images (embedded into content) with authenticating emails sent. You just make sure you have a correct SPF record, and 1024 bit DKIM signed the message. Then gmail shows embedded images within content.

这篇关于用php显示html电子邮件中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆