Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel and swiftmail shows Process could not be started [The system cannot find the path specified]

I am writing an app that send mail to the client using laravel and swiftmailer but I get Process could not be started [The system cannot find the path specified.] error.

Here is my code

env settings

MAIL_DRIVER = smtp
MAIL_HOST = smtp.gmail.com
MAIL_PORT = 587
MAIL_USERNAME = "*********"
MAIL_PASSWORD = *******
MAIL_ENCRYPTION = tls

controller

 $data = array('name'=>"Virat Gandhi");
 Mail::send('emails.mail', $data, function($message) {
     $message->to('[email protected]', 'Tutorials Point')->subject
           ('Laravel HTML Testing Mail');
              $message->from('[email protected]','Virat Gandhi');
           });
           echo "HTML Email Sent. Check your inbox.";

Log

Swift_TransportException: Process could not be started [The system cannot find the path specified. ] in file
C:\xampp\htdocs\tranxavApi\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php on line 299 Stack trace: 1. Swift_TransportException->() C:\xampp\htdocs\tranxavApi\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php:299 2. Swift_Transport_StreamBuffer->establishProcessConnection() C:\xampp\htdocs\tranxavApi\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php:58 3. Swift_Transport_StreamBuffer->initialize() C:\xampp\htdocs\tranxavApi\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php:126 4. Swift_Transport_AbstractSmtpTransport->start() C:\xampp\htdocs\tranxavApi\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\SendmailTransport.php:52 5. Swift_Transport_SendmailTransport->start() C:\xampp\htdocs\tranxavApi\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Mailer.php:67 6. Swift_Mailer->send() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php:451 7. Illuminate\Mail\Mailer->sendSwiftMessage() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php:235 8. Illuminate\Mail\Mailer->send() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:221 9. Illuminate\Support\Facades\Facade->__callStatic() C:\xampp\htdocs\tranxavApi\app\Http\Controllers\APIController.php:120 10. App\Http\Controllers\APIController->sendEmail() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54 11. call_user_func_array() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54 12. Illuminate\Routing\Controller->callAction() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php:45 13. Illuminate\Routing\ControllerDispatcher->dispatch() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Route.php:212 14. Illuminate\Routing\Route->runController() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Route.php:169 15. Illuminate\Routing\Route->run() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Router.php:658 16. Illuminate\Routing\Router->Illuminate\Routing{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30 17. Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php:41 18. Illuminate\Routing\Middleware\SubstituteBindings->handle() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149 19. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 20. Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php:57 21. Illuminate\Routing\Middleware\ThrottleRequests->handle() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149 22. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 23. Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:102 24. Illuminate\Pipeline\Pipeline->then() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Router.php:660 25. Illuminate\Routing\Router->runRouteWithinStack() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Router.php:635 26. Illuminate\Routing\Router->runRoute() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Router.php:601 27. Illuminate\Routing\Router->dispatchToRoute() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Router.php:590 28. Illuminate\Routing\Router->dispatch() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:176 29. Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30 30. Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() C:\xampp\htdocs\tranxavApi\vendor\fideloper\proxy\src\TrustProxies.php:56 31. Fideloper\Proxy\TrustProxies->handle() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149 32. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 33. Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:30 34. Illuminate\Foundation\Http\Middleware\TransformsRequest->handle() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149 35. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 36. Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:30 37. Illuminate\Foundation\Http\Middleware\TransformsRequest->handle() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149 38. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 39. Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php:27 40. Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149 41. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 42. Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php:46 43. Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149 44. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53 45. Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:102 46. Illuminate\Pipeline\Pipeline->then() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:151 47. Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter() C:\xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:116 48. Illuminate\Foundation\Http\Kernel->handle() C:\xampp\htdocs\tranxavApi\public\index.php:55

like image 786
shabz4real Avatar asked Apr 12 '18 09:04

shabz4real


1 Answers

This problem can generally occur when you do not enable two step verification for the gmail account (which can be done here) you are using to send an email. So first, enable two step verification, you can find plenty of resources for enabling two step verification. After you enable it, then you have to create an app password. And use the app password in your .env file. When you are done with it, your .env file will look something like.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=<<your email address>>
MAIL_PASSWORD=<<app password>>
MAIL_ENCRYPTION=tls

and your mail.php

<?php

return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => '<<your email>>', 'name' => '<<any name>>'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,

];

After doing so, run php artisan config:cache and php artisan config:clear, then check, email should work.

like image 138
Adarsh Bhatt Avatar answered Oct 01 '22 14:10

Adarsh Bhatt