我是Laravel 4的菜鸟和接触形式的东西让我有些麻烦使它工作.发现很少的东西,都使用控制器,但我只需要在路线中.
如何使用简单的联系表单(名称,电子邮件和消息)将路径发送到管理员电子邮箱?
干杯
这是使用您的路线发送电子邮件的快速而肮脏的方式:
创建您的路线
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);
});
});
创建一个 app/views/contact.php
<html> <body> <form action="/contact" method="POST"> Your form </form> </body> </html>
创建 app/views/emails/contact.php
<html> <body> Message: {{$data}} </body> </html>
你需要配置
app/config/mail.php