Friday, 23 August 2013

Laravel 4 form data submit and update the database and also send an email with the help of post data.

Laravel 4 form data submit and update the database and also send an email
with the help of post data.

Here what I am trying to do is. There is a form with 3 text fields and I
have to submit that form so that I can retrieve the form post data and
send mail to the recipients. But I need to store the post value in the
variable and I can use these variables to update the database and as well
as sending an email with this data.
If someone could help me with this. It would be of great help.
I'm getting this error Symfony \ Component \ HttpKernel \ Exception \
MethodNotAllowedHttpException
Routes.php:
<?php
Route::get('mail,new',array('as' => 'new_mail' , 'uses' =>
'sendmail@new' ));
Route::post('formtest/submit','sendmail@create');
Route::get('sendmail', function(){
$data = array('detail' => 'email' );
$body = 'body here';
$recipients = 'abc@a.com,def@xyz.com';
$subject = 'test mail';
$date = new DateTime();
$d = $date->format('U = Y-m-d H:i:s');
Mail::queue('emails.sendmail', $data, function($message)
{
$message->to('abc@ymail.com', 'Pradeep G')->subject('test
--mail');
});
DB::table('sentmail')->insert(
array('recipients' => $recipients, 'subject' => $subject,
'body'=>$body, 'created_at'=> $d, 'updated_at'=> $d )
);
return View::make('emails.sent');
});
Here are the files
Routes.php http://paste.laravel.com/LuO
Controller: controllers/Sendmail.php http://paste.laravel.com/LuN
views/home/ftest.blade.php
http://paste.laravel.com/LuM
Model : models/Sendmail.php http://paste.laravel.com/LuQ

No comments:

Post a Comment