Error embedding image in mailbox using Yii2

I want to embed images in my mailbox and I am following the documentation http://www.yiiframework.com/doc-2.0/guide-tutorial-mailing.html .

My code in my controller looks like this:

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

      

And in the mail viewer file:

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

      

However, when I run it, it gives me an 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 am getting this error. Does anyone have a similar problem?

+3


source to share


1 answer


Yii needs an image path to be able to embed it, you should just use path instead of url:



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

      

+7


source







All Articles