我如何使用 cakephp 3 电子邮件模板在电子邮件中发送图像?

How i can send image in email with cakephp 3 email template?

我正在尝试将图片发送到电子邮件中, 我的图片代码是:<?php echo $this->Html->image('image-name.jpg', ['class'=>'img-responsive']); ?>

当我在我的本地主机上调试电子邮件模板时,它工作正常,图像显示正常,但是当同样的代码让它在服务器上运行并发送电子邮件时,电子邮件内容正常显示但图像不显示(未找到) .

任何机构都会建议正确的实施方法。

谢谢, 马克

先附上你要发送的文件

$email->attachments([
    'photo.png' => [
        'file' => '/full/some_hash.png',
        'mimetype' => 'image/png',
        'contentId' => 'unique-id'
    ]
]);

然后在您的电子邮件模板中,添加唯一 ID

 <img src="cid:unique-id">

详细解释,here

对于电子邮件或整个网站,如果您想要内容的完整路径,请使用具有 true 值的 fullBase 参数,

echo $this->Html->image("logo.png", ['fullBase' => true]);

将输出:

<img src="http://example.com/img/logo.jpg" alt="" />

https://book.cakephp.org/3.0/en/views/helpers/html.html#linking-to-images

这是 CakePhp 框架建议的正确方法。