A
A
Arthur2019-08-20 09:33:23
Yii
Arthur, 2019-08-20 09:33:23

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

Version stable yiisoft/yii2-swiftmailer (2.1.2)
swifmailer latest from dev branch (6.2.x-dev)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question