【问题标题】:Laravel 4 from contact form to admin emailLaravel 4 从联系表格到管理员电子邮件
【发布时间】:2014-03-01 04:14:55
【问题描述】:

我第一次尝试使用 Laravel 的 Mail 类并且遇到了一些困难。我有一个简单的联系表格,应该作为电子邮件发送给管理员。这是我尝试过的

Controller(一旦我可以让它工作,将被重构为模型)

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);
}

查看

 {{ 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')

当我填写我们的联系表并点击发送时,我收到此错误:

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

【问题讨论】:

    标签: php email laravel laravel-4 swiftmailer


    【解决方案1】:

    将数据变量设置为数组:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-19
      • 2018-02-24
      • 1970-01-01
      • 2012-02-25
      • 2019-07-26
      • 1970-01-01
      • 2022-07-06
      相关资源
      最近更新 更多