2016-10-09 4 views
1

ページビューで自分のアカウントにメールを送信できるウェブサイトを構築していました。
私はこのような私の.envファイル編集した:laravelを使用してメールを送信する際にエラーが発生しました

MAIL_DRIVER=smtp 
MAIL_HOST=smtp.gmail.com 
MAIL_PORT=587 
[email protected] 
MAIL_PASSWORD=example 
MAIL_ENCRYPTION=null 

をユーザー名とパスワードのみを、私は私の元の名前と電子メールを与えている元のファイル上でこの質問に対するとして設定されています。
そして、私のmail.phpファイルには、次のようになります^^

MyRouteファイルは次のようになり、他の機能で

'from' => [ 
    'address' => '[email protected]', 
    'name' => 'Example', 
], 

ここ
Route::get('/send', function() { 
    Mail::send('email.send', ['name' => 'Its me'], function($message) { 
     $message->to('[email protected]', 'Someone')->from('[email protected]')->subject('Worked'); 
    }); 
}); 

また、ユーザ名と名前を例に設定されています| |その私だけここに、元のファイルに私は私の元の名前と電子メールを与えている。

そして、私のemail/send.blade.phpファイルは、私はこれを勉強するtutorial from youtube INORDERを使用する唯一の{{$name}}

持っています。

はまだ私はこのエラーを修正することができますどのようにこの

MethodNotAllowedHttpException in RouteCollection.php line 218

のようなエラーが出ますか? 私を助けてください。

+0

確認のために働くあなたが私はそれのために任意のコントローラを使用didntのメール – darham

+0

@darhamを送信し、コントローラ/関数にあなたのルートを宣言していないように見えます。代わりに、私は直接ルート 'function()' – Advaith

+0

を使用しました。あなたはGmailの安全性の低いアプリケーションを許可しましたか?これは、私が思うようなエラーをpingして戻ってくる原因かもしれません。 – Adam

答えて

1

お試しください!これは

// Route::any : it means that it will allow all method like get,post,put,patch... 
Route::any('/send', function() 
{ 
    return Mail::send('email.send', ['name' => 'Its me'], function($message) 
    { 
    $name = "Name"; 
    $message->from('[email protected]',$name); 
    $message->to('[email protected]')->subject('Test Mail'); 
    }); 
}); 
1

それが動作します、これを試してみてください:

Route::match(['get','post'],'/send', function() { 
    Mail::send('email.send', ['name' => 'Its me'], function($message) { 
     $message->to('[email protected]', 'Someone')->from('[email protected]')->subject('Worked'); 
    }); 
}); 

OR

Route::any('/send', function() { 
     Mail::send('email.send', ['name' => 'Its me'], function($message) { 
      $message->to('[email protected]', 'Someone')->from('[email protected]')->subject('Worked'); 
     }); 
    }); 
+0

別のエラーが発生しました。 [このように](http://prntscr.com/cscwgx)。それにも解決策を教えてください – Advaith

関連する問題