laravel和swiftmail显示无法启动进程[系统找不到指定的路径]

时间:2018-04-12 09:24:44

标签: php laravel-5 swiftmailer

我正在编写一个使用laravel和swiftmailer向客户端发送邮件的应用程序,但是我无法启动Process [系统无法找到指定的路径。]错误。

这是我的代码

env设置

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

控制器

 $data = array('name'=>"Virat Gandhi");
 Mail::send('emails.mail', $data, function($message) {
     $message->to('chuditex2004@yahoo.com', 'Tutorials Point')->subject
           ('Laravel HTML Testing Mail');
              $message->from('chuksdsilent@gmail.com','Virat Gandhi');
           });
           echo "HTML Email Sent. Check your inbox.";

日志

  

Swift_TransportException:无法启动进程[系统   找不到指定的路径。 ]在档案中   C:\ XAMPP \ htdocs中\ tranxavApi \供应商\ swiftmailer \ swiftmailer \ LIB \类\雨燕\传输\ StreamBuffer.php   第299行堆栈跟踪:     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.照亮\ Mail \ Mailer-> sendSwiftMessage()C:\ xampp \ htdocs \ tranxavApi \ vendor \ laravel \ framework \ src \ Illuminate \ Mail \ Mailer.php:235     8.照亮\ 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.照亮\路由\中间件\ 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.照亮\ 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.照亮\ 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.照亮\ 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 \厂商\ laravel \框架\ SRC \照亮\路由\ 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.照亮\ 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.照亮\基础\ Http \ Middleware \ TransformsRequest-> handle()   C:\ XAMPP \ htdocs中\ tranxavApi \厂商\ laravel \框架\ SRC \照亮\管道\ Pipeline.php:149    35.照亮\ 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 \厂商\ laravel \框架\ SRC \照亮\管道\ 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.照亮\ Foundation \ Http \ Middleware \ ValidatePostSize-> handle()   C:\ XAMPP \ htdocs中\ tranxavApi \厂商\ laravel \框架\ SRC \照亮\管道\ Pipeline.php:149    41. Illuminate \ Pipeline \ Pipeline-> Illuminate \ Pipeline {closure}()C:\ xampp \ htdocs \ tranxavApi \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Pipeline.php:53    42.照亮\ 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 \厂商\ laravel \框架\ SRC \照亮\管道\ 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.照亮\ 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

2 个答案:

答案 0 :(得分:0)

当您没有为要用来发送电子邮件的gmail帐户启用两步验证(可以在此处完成)时,通常会出现此问题。因此,首先,启用两步验证,您将找到大量资源来启用两步验证。启用后,您必须创建一个应用密码。并在.env文件中使用应用密码。完成后,您的.env文件将类似于。

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

和您的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,

];

这样做之后,运行php artisan config:cache和php artisan config:clear,然后检查,电子邮件应该可以工作。

答案 1 :(得分:0)

我遇到了同样的问题,因为 SwiftMailer 忽略了 .env 文件中的正确环境。

但是改变了

'driver' => env('MAIL_DRIVER', 'mail'),

'driver' => env('MAIL_DRIVER', 'smtp'),

/config/mail.php 中为我解决了问题。

显然,自 5.4.5 版以来,SwiftMailer 中不推荐使用 mail 驱动程序,它导致驱动程序更改为 sendmail,即使我在我的 .env 中将其设置为 smtp .