Problem with PHP, Swift-mailer

When I click the submit button on my contact page, trying to submit a form using swift-mailer, I get the following:

Warning: fopen (uploads /) [function.fopen]: could not open stream: there is no such file or directory in / home / polycys 2 / public_html / html / swift-mailer / lib / classes / Swift / ByteStream / FileByteStream.php in line 131

Fatal error: Uncaught exception 'Swift_IoException' with message 'Unable to open file for reading [uploads/]' in /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php:133 Stack trace: #0 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php(77): Swift_ByteStream_FileByteStream->_getReadHandle() #1 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(660): Swift_ByteStream_FileByteStream->read(8192) #2 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(337): Swift_Mime_SimpleMimeEntity->_readStream(Object(Swift_ByteStream_FileByteStream)) #3 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(448): Swift_Mime_SimpleMimeEntity->getBody() #4 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(463): Swift_Mime_SimpleMimeEntity->toString() #5 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ in /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php on line 133 

The full path exists on the server, although the error message says "there is no such file or directory. What could be the problem? Thanks to everyone in advance! And Merry Christmas!

+5
source share
4 answers

You need to specify the full path to uploads not the real path, because this will be interpreted as relative to the class file that your application is trying to open.

Try using realpath before passing the path to Swift.

$ path = realpath ('uploads /');

+9
source

Thank you all for your help! The problem was my distraction - I forgot to create the "upload" directory there. Now it works fine. Thanks!

+1
source

From the error messages, it seems that you have indicated the directory where the file path is required. Perhaps due to a missing variable that should contain the file name.

0
source

This works for me:

controller.php

 $mail = Yii::$app->mailer->compose('@app/mail/embed-mail', [ 'term' => Url::to('@webroot/images/term.png'), 'logo' => Url::to('@webroot/images/LOGO.jpg') ] 

And embed mail.php

 <img src="<?= $message->embed($terminal); ?>"/> <img src="<?= $message->embed($logo); ?>"/> 

I hope this works for you

0
source

Source: https://habr.com/ru/post/1333355/


All Articles