2017-05-09 30 views
0

我使用vue.js作爲我的前端和流明作爲我的api服務。現在我需要從流明發送電子郵件。這是我爲此做的。發送電子郵件從流明

.ENV文件

MAIL_DRIVER=smtp 
MAIL_HOST=smtp.gmail.com 
MAIL_PORT=587 
MAIL_USERNAME=********@gmail.com 
MAIL_PASSWORD=********** 
MAIL_FROM_ADDRESS=******@gmail.com 
MAIL_FROM_NAME=Sample Email App 
MAIL_ENCRYPTION=tls 

,然後編輯的文件bootstrap\app.php和未註釋以下行。

$app->register(App\Providers\AppServiceProvider::class); 
$app->withFacades(); 
Dotenv::load(__DIR__.'/../'); 
$app->withEloquent(); 

在控制器中,我用下面的代碼

use Illuminate\Support\Facades\Mail; 

private function sendActivationEmail($email = null){ 
     $email_sent = false; 
     if($email != null){ 
      // send email 
      Mail::raw('Raw string email', function($msg) { 
       $msg->to(['[email protected]']); $msg->from(['[email protected]']); 
      }); 

     } 
     return $email_sent; 
    } 

不幸的是,這是行不通的。誰能告訴我我錯了哪裏?

回答

0

註冊MailServiceProvider在引導/ app.php文件

$app->register(\Illuminate\Mail\MailServiceProvider::class); 
$app->configure('mail'); 

試寄存器功能內添加以下代碼AppServiceProvider.php

$this->app->singleton('mailer', function ($app) { 
      $app->configure('services'); 
      return $app->loadComponent('mail', 'Illuminate\Mail\MailServiceProvider', 'mailer'); 
     }); 

如果不工作的上述配置後,嘗試mail發送功能

Mail::send('user.emails.registration' , $data, function($msg) use ($to,$from,$subject) 
       { 
        $msg->to($to)->from($from)->subject($subject); 
       }); 
+0

不幸的是,沒有工作... '[20 17-10-20 18:55:25] lumen.ERROR:Symfony \ Component \ Debug \ Exception \ FatalThrowableError:Class'Illuminate \ Mail \ MailServiceProvider'找不到/ api/vendor/laravel/lumen-framework/src/Application .php:164 堆棧跟蹤: #0 /api/bootstrap/app.php(267):Laravel \ Lumen \ Application-> register('Illuminate \\ Mail ...')' –