Answer the question
In order to leave comments, you need to log in
How to attach an image (imagick) to an email being sent on the fly in Yii2?
Greetings.
I can't attach a file to an email on the fly, I generate an image using Imagick, then I try to attach it to an email using the attachContent() method, but the file doesn't arrive. I also try an example from the documentation of sending a text file - the same result.
Just a letter comes with text from the mail-tpl template. If you use attach () and specify the path to the file, then everything is OK - the file comes.
The code:
Yii::$app->mailer->compose('mail-tpl')
->setTo('[email protected]')
->setFrom(['[email protected]' => 'Письмо'])
->setSubject('Тестовый файл')
# не прикрепляет
->attachContent('Attachment content', ['fileName' => 'attach.txt', 'contentType' => 'text/plain'])
# не прикрепляет
->attachContent($image->getImageBlob(), ['fileName' => 'image.png', 'contentType' => 'image/png'])
# прикрепляет
->attach('/path/to/file.png')
->send();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question