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 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图