问题
Im a noob with Laravel 4 and the contact form things is giving me some trouble to make it work. Found few things, all using controllers but I just need it in the route.
How to do the route for a simple contact form (name,email and message) to send the datas to an admin email box?
Cheers
回答1:
Here's a quick and dirty way to send e-mails using just your routes:
Create your routes
Route::get('contact', function() {
return View::make('contact');
});
Route::post('contact', function() {
$fromEmail = Input::get('email');
$fromName = Input::get('name');
$subject = Input::get('subject');
$data = Input::get('message');
$toEmail = 'manager@company.com';
$toName = 'Company Manager';
Mail::send('emails.contact', $data, function($message) use ($toEmail, $toName, $fromEmail, $fromName, $subject)
{
$message->to($toEmail, $toName)
$message->from($fromEmail, $fromName);
$message->subject($subject);
});
});
Create a app/views/contact.php
<html>
<body>
<form action="/contact" method="POST">
Your form
</form>
</body>
</html>
Create app/views/emails/contact.php
<html>
<body>
Message: {{$data}}
</body>
</html>
And you need to configure
app/config/mail.php
来源:https://stackoverflow.com/questions/20395884/contact-form-laravel-4