Error when embed image in mail using Yii2

落花浮王杯 提交于 2019-12-23 20:14:05

问题


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')
])

And in the mail view file:

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

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

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?


回答1:


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');


来源:https://stackoverflow.com/questions/27606838/error-when-embed-image-in-mail-using-yii2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!