使用Laravel发送基本邮件

时间:2015-01-31 17:49:05

标签: php laravel swiftmailer

我正在尝试使用Laravel框架设置我的邮件程序。我设置了一个非常基本的示例来发送测试邮件,只是为了验证所有工作正常。虽然,我无法让它工作,但它产生的错误如下所示。请注意,我在配置文件中使用了一个工作邮件程序配置,我之前使用过,这让我相信它与我在laravel框架中设置的方式有关。

我感谢任何帮助,提前谢谢!

查看:

<form action="mailer" method="post">
    <input class="big_search" name="email" type="text" placeholder="Enter email address" />
    <input class="big_submit" value="START FREE TRIAL" type="submit">   
</form>

路线:

Route::get('/mailer', 'MyController@testEmail');

控制器:

class MyController extends BaseController {
    public function testEmail(){    
        Mail::send('emails.verification', array('key' => 'value'), function($message){
            $message->to('mymail@gmail.com', 'John Smith')->subject('Welcome!');
        });
    }
}

电子邮件查看,观看/电子邮件/ verification.blade.php:

This is a test email

Stacktrace /错误:

#13 Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:5762
#12 Illuminate\Routing\RouteCollection:methodNotAllowed in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:5758
#11 Illuminate\Routing\RouteCollection:getOtherMethodsRoute in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:5736
#10 Illuminate\Routing\RouteCollection:match in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:5060
#9 Illuminate\Routing\Router:findRoute in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:5048
#8 Illuminate\Routing\Router:dispatchToRoute in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:5040
#7 Illuminate\Routing\Router:dispatch in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:715
#6 Illuminate\Foundation\Application:dispatch in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:696
#5 Illuminate\Foundation\Application:handle in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:7812
#4 Illuminate\Session\Middleware:handle in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:8419
#3 Illuminate\Cookie\Queue:handle in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:8366
#2 Illuminate\Cookie\Guard:handle in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:11029
#1 Stack\StackedHttpKernel:handle in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:657
#0 Illuminate\Foundation\Application:run in C:\xampp\htdocs\www\test\laravel-master\public\index.php:49

1 个答案:

答案 0 :(得分:4)

您要发布到您的控制器,但您的路线设置为仅接受获取请求:

Route::get('/mailer', 'MyController@testEmail')

只需将其更改为

即可
Route::post('/mailer', 'MyController@testEmail')

它应该有效

堆栈跟踪的第一行:

#13 Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException in C:\xampp\htdocs\www\test\laravel-master\bootstrap\compiled.php:5762

表示您收到“MethodNotAllowedHttpException”,表示您正在使用该路由不支持的HTTP方法向您的服务器发送请求