I am sending HTML emails containing images, the src
attribute for those images is an URL to a yii2 controller action that outputs the image content.
Images are shown if I open my email on the browser, my problem is with outlook that can not download and show my images.
Here is my action to output the image:
public function actionImage($img_name) {
$filepath = Yii::getAlias('@webroot')."/media/files/$img_name";
if (file_exists($filepath))
{
$mime = \yii\helpers\BaseFileHelper::getMimeType($filepath);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="' . $img_name. '"');
header('Content-Length: ' . filesize($filepath));
// Render the file
readfile($filepath);
exit(0);
}
else
{
die('Media Not Found!');
}
}