Contact form Laravel 4

社会主义新天地 提交于 2019-12-10 20:54:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!