联系表格Laravel 4 [英] Contact form Laravel 4

查看:75
本文介绍了联系表格Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Laravel 4的菜鸟,与之联系的方式给我带来一些麻烦,使其无法正常工作. 发现了很少的东西,全部使用了控制器,但是我只需要在路由中使用.

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?

欢呼

推荐答案

这是一种仅使用您的路由发送电子邮件的快速而肮脏的方法:

Here's a quick and dirty way to send e-mails using just 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);
    });

});

创建一个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

这篇关于联系表格Laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆