Laravel 4从联系表单到管理员电子邮件 [英] Laravel 4 from contact form to admin email

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

问题描述

我第一次尝试使用Laravel's Mail课程,但遇到一些困难。我有一个简单的联系表格,应该作为电子邮件发送给管理员。这是我已经尝试过的



控制器(一旦我可以将其重新编入模型)

  public function store()
{
$ validation = new Services\Validators\Contact;

if($ validation-> passed())
{
$ fromEmail = Input :: get('email');
$ fromName = Input :: get('name');
$ subject =来自website.com的用户的电子邮件;
$ data = Input :: get('message');

$ toEmail ='test@dummyemail.com';
$ toName ='Mitch Glenn';

Mail :: send('emails.contact',$ data,function($ message)use($ toEmail,$ toName,$ fromEmail,$ fromName,$ subject){
$ ($ toEmail,$ toName);

$ message-> from($ fromEmail,$ fromName);

$ message-   subject($ subject);
});

返回重定向::到('/')
- >与('message','你的消息成功发送!
}

返回重定向:: back()
- > withInput()
- > withErrors($ validation-> errors);
}

查看

  {{Form :: open(array('action'=>'ContactController @ store','class'=>'row','id' =''contact'))}} 

{{Form :: label('name','Name')}}
{{Form :: text('name' '',array('class'=>'full'))}}

{{Form :: label('email','Email')}}
{{Form :: email('email','',array('class'=>'full'))}}

{{Form :: label('message','Message')} }
{{Form :: textarea('message','',array('class'=>'full'))}}

{{Form :: submit现在发送',array('class'=>'btn btn-large btn-primary'))}}

{{Form :: close()}}

@include('_partials.errors')

填写我们的联系表单并点击发送时,我得到这个错误:

 参数2传递给Illumin ate\Mail\Mailer :: send()必须是数组类型,字符串给定


解决方案

将数据变量设置为数组:

  $ data = array '=> Input :: get('message')); 


I'm trying to use Laravel's Mail class for the first time and am having some difficulties. I have a simple contact form that should be sent as an email to the admin. Here is what I have tried

Controller (Will be refactored into Model once I can get it working)

public function store()
{
    $validation = new Services\Validators\Contact;

    if($validation->passes())
    {
        $fromEmail = Input::get('email');
        $fromName = Input::get('name');
        $subject = "Email from user at website.com";
        $data = Input::get('message');

        $toEmail = 'test@dummyemail.com';
        $toName = 'Mitch Glenn';

        Mail::send('emails.contact', $data, function($message) use ($toEmail, $toName, $fromEmail, $fromName, $subject){

            $message->to($toEmail, $toName);

            $message->from($fromEmail, $fromName);

            $message->subject($subject);
        });

        return Redirect::to('/')
            ->with('message', 'Your message was successfully sent!');
    }

    return Redirect::back()
        ->withInput()
        ->withErrors($validation->errors);
}

View

 {{ Form::open(array('action' => 'ContactController@store', 'class' => 'row', 'id' => 'contact')) }}

    {{ Form::label('name', 'Name') }}
    {{ Form::text('name', '', array('class' => 'full')) }}

    {{ Form::label('email', 'Email') }}
    {{ Form::email('email', '', array('class' => 'full')) }}

    {{ Form::label('message', 'Message') }}
    {{ Form::textarea('message', '', array('class' => 'full')) }}

    {{ Form::submit('Send Now', array('class' => 'btn btn-large btn-primary')) }}

 {{ Form::close() }}

@include ('_partials.errors')

When I fill our the contact form and hit send, I get this error:

Argument 2 passed to Illuminate\Mail\Mailer::send() must be of the type array, string given

解决方案

Set your data variable to be an array:

$data = array( 'message' => Input::get('message') );

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

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