AnchovyLegend
AnchovyLegend

Reputation: 12538

Sending basic mail with Laravel

I am trying to set up my mailer with the Laravel framework. I set up a very basic example to send a test mail, just to verify all is working as it should. Although, I am unable to get it to work, it is generating the error shown below. Note, I am using a working mailer configuration in the config file, that I have used previously, which leads me to believe it has something to do with how I am setting things up within the laravel framework.

I appreciate any help, thanks in advance!

View:

<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:

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

Controller:

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

Email View, views/emails/verification.blade.php:

This is a test email

Stacktrace/ Error:

#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

Upvotes: 0

Views: 1019

Answers (1)

Jonathan Crowe
Jonathan Crowe

Reputation: 5803

You are posting to your controller but your route is set up to only accept get request:

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

simply change that to

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

and it should work

The first line of your stack trace:

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

shows that you are receiving a "MethodNotAllowedHttpException" which indicates that you are sending a request to your server using an HTTP method that is not supported by that route

Upvotes: 4

Related Questions