问题
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