dongling2038 2016-10-09 14:26
浏览 79
已采纳

使用laravel时发送邮件时出错

I was building a website which can send mail to my account on the page view.
I have edited my .env file like this :

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=example@example.com
MAIL_PASSWORD=example
MAIL_ENCRYPTION=null

username and password is set as example for this question only, on original file I have given my original name and email.
And my mail.php file looks like this:

'from' => [
    'address' => 'hello@example.com',
    'name' => 'Example',
],

With other function ^^

MyRoute file looks like this:

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

Here also username and name is set as example || Its me on here only, on original file I have given my original name and email.

And my email/send.blade.php file is having only {{$name}}

I used the tutorial from youtube inorder to study this.

Still I get an error like this

MethodNotAllowedHttpException in RouteCollection.php line 218

How can I fix this error? Please help me.

  • 写回答

2条回答 默认 最新

  • dpjw67160 2016-10-09 19:04
    关注

    Try! This will work for sure

    // 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('no-reply@xxxxx.com',$name); 
         $message->to('kroy.webxpert@gmail.com')->subject('Test Mail'); 
      });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 给出完整的python代码并解释
  • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了
  • ¥20 firefly-rk3399上启动卡住了
  • ¥15 如何删除这个虚拟音频
  • ¥50 hyper默认的default switch
  • ¥15 网站打不开,提示502 Bad Gateway
  • ¥20 基于MATLAB的绝热压缩空气储能系统代码咨询
  • ¥15 R语言建立随机森林模型出现的问题
  • ¥15 关于#wpf#的问题:怎么更改LayoutGroup组件的标签页的字体颜色
  • ¥15 中级微观经济学,生产可能性边界问题