Support the ongoing development of Laravel.io →
posted 9 years ago
Mail
Last updated 1 year ago.
0

Maybe you need up the post_max_filesize or the upload_max_filesize in the PHP Enviroment.

If anybody knows how could change the max filesize to send as attachment it will be great..

Hope it helps you.

Last updated 1 year ago.
0

Not sure but I don't think could be the problem I'm trying to send 76kb of file. Anyway I'm checking now! Any other ideas?

Last updated 1 year ago.
0

Nothing!!! It doesn't work! I think I'm gonna get crazy!!! below all the error log :(

[2014-05-06 07:27:24] production.ERROR: exception 'ErrorException' with message 'fopen(Content-Type: application/pdf; name=invoice27.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=invoice27.pdf

JVBERi0xLjcKJeLjz9MKOSAwIG9iago8PCAvV........(file encoding).....ID4+CnN0YXJ0eHJlZgoyNzU1NAolJUVPRgo=): failed to open stream: Invalid argument' in /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php:138
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleError(2, 'fopen(Content-T...', '/Users/lucatrub...', 138, Array)
#1 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php(138): fopen('Content-Type: a...', 'rb')
#2 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php(86): Swift_ByteStream_FileByteStream->_getReadHandle()
#3 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/Base64ContentEncoder.php(36): Swift_ByteStream_FileByteStream->read(8190)
#4 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(559): Swift_Mime_ContentEncoder_Base64ContentEncoder->encodeByteStream(Object(Swift_ByteStream_FileByteStream), Object(Swift_Transport_StreamBuffer), 0, 78)
#5 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(534): Swift_Mime_SimpleMimeEntity->_bodyToByteStream(Object(Swift_Transport_StreamBuffer))
#6 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(574): Swift_Mime_SimpleMimeEntity->toByteStream(Object(Swift_Transport_StreamBuffer))
#7 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(534): Swift_Mime_SimpleMimeEntity->_bodyToByteStream(Object(Swift_Transport_StreamBuffer))
#8 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMessage.php(611): Swift_Mime_SimpleMimeEntity->toByteStream(Object(Swift_Transport_StreamBuffer))
#9 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Message.php(170): Swift_Mime_SimpleMessage->toByteStream(Object(Swift_Transport_StreamBuffer))
#10 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(329): Swift_Message->toByteStream(Object(Swift_Transport_StreamBuffer))
#11 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(433): Swift_Transport_AbstractSmtpTransport->_streamMessage(Object(Swift_Message))
#12 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(449): Swift_Transport_AbstractSmtpTransport->_doMailTransaction(Object(Swift_Message), 'luca.trubbiani@...', Array, Array)
#13 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(176): Swift_Transport_AbstractSmtpTransport->_sendTo(Object(Swift_Message), 'luca.trubbiani@...', Array, Array)
#14 /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(86): Swift_Transport_AbstractSmtpTransport->send(Object(Swift_Message), Array)
#15 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(307): Swift_Mailer->send(Object(Swift_Message), Array)
#16 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(134): Illuminate\Mail\Mailer->sendSwiftMessage(Object(Swift_Message))
#17 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(221): Illuminate\Mail\Mailer->send('emails.shop_inv...', Array, Object(Closure))
#18 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(96): Illuminate\Mail\Mailer->handleQueuedMessage(Object(Illuminate\Queue\Jobs\SyncJob), Array)
#19 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Queue/Jobs/SyncJob.php(52): Illuminate\Queue\Jobs\Job->resolveAndFire(Array)
#20 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php(15): Illuminate\Queue\Jobs\SyncJob->fire()
#21 [internal function]: Illuminate\Queue\SyncQueue->push('mailer@handleQu...', Array, NULL)
#22 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php(186): call_user_func_array(Array, Array)
#23 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(150): Illuminate\Queue\QueueManager->__call('push', Array)
#24 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(150): Illuminate\Queue\QueueManager->push('mailer@handleQu...', Array, NULL)
#25 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(214): Illuminate\Mail\Mailer->queue('emails.shop_inv...', Array, Object(Closure))
#26 /Users/lucatrubbiani/Sites/progetto/app/controllers/HomeController.php(40): Illuminate\Support\Facades\Facade::__callStatic('queue', Array)
#27 /Users/lucatrubbiani/Sites/progetto/app/controllers/HomeController.php(40): Illuminate\Support\Facades\Mail::queue('emails.shop_inv...', Array, Object(Closure))
#28 [internal function]: HomeController->home()
#29 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(231): call_user_func_array(Array, Array)
#30 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(93): Illuminate\Routing\Controller->callAction('home', Array)
#31 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(62): Illuminate\Routing\ControllerDispatcher->call(Object(HomeController), Object(Illuminate\Routing\Route), 'home')
#32 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Routing/Router.php(934): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'HomeController', 'home')
#33 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#34 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Routing/Route.php(105): call_user_func_array(Object(Closure), Array)
#35 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1000): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#36 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Routing/Router.php(968): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#37 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(738): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#38 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(708): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#39 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Http/FrameGuard.php(38): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#40 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Illuminate\Http\FrameGuard->handle(Object(Illuminate\Http\Request), 1, true)
#41 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#42 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#43 /Users/lucatrubbiani/Sites/progetto/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#44 /Users/lucatrubbiani/Sites/progetto/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(606): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#45 /Users/lucatrubbiani/Sites/progetto/public/index.php(49): Illuminate\Foundation\Application->run()
#46 {main} [] []

Don't know what to do!! help :( :( :(

Last updated 1 year ago.
0

Hi,

What is the folder where you have the attachement? I only see the following file:

    Mail::queue('emails.shop_invoice', $data, function($message) {
        $file = 'invoice27.pdf;
        ...
    });

You need to specify the full path of the file. And need to finish the last closing quotes as follow:

    Mail::queue('emails.shop_invoice', $data, function($message) {
        $file = 'path/invoice27.pdf';
        ...
    });

Hope it helps you.

Last updated 1 year ago.
0

It wasn't correct the code above...In my code I'm getting the full path but still doesn't work. The folder is under the /public directory.

        $data = array();
        Mail::queue('emails.shop_invoice', $data, function($message) {
            try {

                /** Config::get return the /upload real path
                 *
                 * return array(
                 *   'path' => public_path() . "/upload"
                 * );
                 *
                 **/
                  
                $file = Config::get('invoice.path') . '/39/company/1/invoice/' . 'invoice27' . '.pdf';
                $message->attach(\Swift_Attachment::fromPath($file));
                
                $message->to('[email protected]')->subject('test');
            } catch (Exception $e) {
                
            }
        });

On the error log I can see that the file is loaded correctly but than it raise an error exactly while is trying to send the message see below:

'fopen(Content-Type: application/pdf; name=invoice27.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=invoice27.pdf

JVBERi0xLjcKJeLjz9MKOSAwIG9iago8PCAvV........(file encoding).....ID4+CnN0YXJ0eHJlZgoyNzU1NAolJUVPRgo=): failed to open stream: Invalid argument' in /Users/lucatrubbiani/Sites/progetto/vendor/swiftmailer/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php:138

Any other ideas?

Last updated 1 year ago.
0

Can you describe your environment? (OS, Web Server, PHP version, Local host / VPS / Shared?)

Last updated 1 year ago.
0

of course! I'm developing a website in a Localhost and to send the email I'm using for now Gmail smtp.

The website is an ecommerce and what does is send an email after the payment is successful..For some reason I don't want to send the invoice in the email body ( as html ) but I would like to attach the invoice in pdf format.

I'm using OSX Maverick, the PHP version is ( PHP 5.4.24 (cli) (built: Jan 19 2014 21:32:15) ), Laravel 4.1 and Swift-5.1.0

That's all I think. If you need more spec I will be happy to give them to you.

Last updated 1 year ago.
0

Have you tried with another file or file extension attachment?

Last updated 1 year ago.
0

yes, I tried with an image but same things happen! Also the file I'm sending has 777 permissions.

Last updated 1 year ago.
0
Last updated 1 year ago.
0

It shouldn't be the same problem...I'm still searching a solution for it!!! Other ideas?

Last updated 1 year ago.
0

Echo $file and check that the file does exist

Check permissions on files/directories

Last updated 1 year ago.
0

The file has 777 permissions also the path is correct! if I cut and paste the path on firefox it show the pdf! Yesterday I had an update of swift mailer via composer..will see today if it works and I let you know...thanks to all for now.

Last updated 1 year ago.
0
Solution

After a long period stop programming I found the solution :), below the code that work


 $data = array();
 Swift_Preferences::getInstance()->setCacheType('disk')->setTempDir('/tmp');
 Mail::queue('emails.shop_invoice', $data, function($message) {
      try {
          $file = Config::get('invoice.path') . '/39/company/1/invoice/' . 'invoice27' . '.pdf';
          $message->attach($file, array('as' => 'invoice', 'mime' => 'application/pdf'));

          $message->to('[email protected]')->subject('test');
          } catch (Exception $e) {
              
       }
});

The problem was actually on this line of code

$message->attach($file, array('as' => 'invoice', 'mime' => 'application/pdf'));

the first parameter of the attach function get a path not a base64 data string. I did some search and I found before there was another method on Laravel called attachData() where the first paramter was a "data string".

thank you all guys. I hope this can help someone else. bye.

Last updated 1 year ago.
0

Hi luca83,

Did you have a html code in "emails.shop_invoice". Leaving this file empty might cause the file to be attached as base64.

Cheers

Last updated 1 year ago.
0

Oh yes thank You getmetorajesh! I was going crazy with this. It worked first but suddenly started adding attachment as base64 and I would have never figured out that empty template might be the culprit.

Last updated 1 year ago.
0

For some crazy reasons, i battled with this for a whole day. I hosted laravel on a shared hosting so i have a cpanel file-manager .

Especially if the image you try to upload is in your public directory as in my case. Make sure your public or www folder has at least a 755 permission.

using asset('images/whatever.jpg') is NOT going to work as it gives you an absolute path like http://whatever.com/images/imagename.jpg

using this works:

$message->embed(public_path().'/images/fixng_logo.png')

Note: public path returns /home/dirname/public but however if you are using a shared hosting and cpanel like mine, the public folder is called public_html so i used it as belows and this works for me.

$message->embed(public_path().'_html/images/logo.png')
Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

luca83 luca83 Joined 27 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.