使用Yii2将图像嵌入邮件中时出错 [英] Error when embed image in mail using Yii2

查看:65
本文介绍了使用Yii2将图像嵌入邮件中时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在邮件正文中嵌入图像,并且遵循 http://www.yiiframework.com/doc-2.0/guide-tutorial-mailing.html .

I want to embed images in my mail body and I follow the documentation on http://www.yiiframework.com/doc-2.0/guide-tutorial-mailing.html .

我在控制器中的代码如下:

My code in the controller looks like this:

$messages[] = Yii::$app->mailer->compose('downNotify', [
    'websiteList' => $websiteList,
    'logo' => Url::to('@web/mail/images/logo.png')
])

在邮件视图文件中:

<a href="#"><img width="100" src="<?= $message->embed($logo); ?>"></a>

但是,当我运行它时,它给了我错误:

However when I run it, it gives me the error:

打开(/WEBSITE_MONITOR/web/mail/images/logo.png):无法打开流:没有这样的文件或目录

fopen(/WEBSITE_MONITOR/web/mail/images/logo.png): failed to open stream: No such file or directory

该路径有效,但我不知道为什么会收到此错误.有人有类似的问题吗?

The path is valid but I don't know why I get this error. Is anyone has similar problem?

推荐答案

Yii需要图像 path 才能嵌入它,您只需使用路径而不是url即可:

Yii need the image path to be able to embed it, you should simply use a path instead of url :

'logo' => Yii::getAlias('@app/web/mail/images/logo.png');

这篇关于使用Yii2将图像嵌入邮件中时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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