Laravel 4联系表单错误:未定义的变量:电子邮件

时间:2016-07-24 20:17:01

标签: php laravel

提前感谢您的回答。我不知道我做了什么不好的联系表格,变量在views / emails / contact.blade.php

我的表格

{{ Form::open(array('action' => 'PagesController@contact','method' => 'POST', 'role' =>'form', 'class' =>'form-horizontal' )) }}
<div class="form-group">
    {{ Form::label('name', 'Nombre:', ['class' => '']) }}                       
    {{ Form::text('name', '', ['class' => 'form-control', 'maxlength' => 20]) }}
</div>

<div class="form-group">
    {{ Form::label('email', 'Email:', ['class' => '']) }}                   
    {{ Form::email('email', '', ['class' => 'form-control']) }}
</div>

<div class="form-group">
    {{ Form::label('subject', 'Asunto:', ['class' => '']) }}                    
    {{ Form::text('subject', '', ['class' => 'form-control']) }}
</div>
    <div class="form-group">    
    {{ Form::label('country', 'Pais:', ['class' => '']) }}                  
    {{ Form::text('country', '', ['class' => 'form-control']) }}
</div>

<div class="form-group">
    {{ Form::label('textarea', 'Message:', ['class' => '']) }}                          
    {{ Form::textarea('msg', '',  ['class' => 'form-control', 'placeholder' =>'Your Message', 'required'=>'true'])  }}
</div>


<div class="form-group">
    {{ Form::submit('Send', array('class' => 'btn btn-primary btn-md')) }}
</div>
{{ Form::close() }}

在views / emails / contact.blade.php

Name:   {{ $name }}
Email:  {{ $email }}
Country:    {{ $country }}
Subject:    {{ $subject }}
Message: {{ $msg }
{{ $detail }}

路线

Route::get('/contact', array('as' =>'contact', 'uses'=> 'PagesController@contact'));
Route::post('contact', 'PagesController@contact');

页面控制器

public function contact(){
    return View::make('contact');
}

public function postContact(){
    $user = array(
        'email'=>'africamia@gmail.com',
        'name'=>'Laravelovich'
    );

    // the data that will be passed into the mail view blade template
    $data = array(
        'detail'=>'Your awesome detail here',
        'name'  => $user['name']
    );

    // use Mail::send function to send email passing the data and using the $user variable in the closure

    Mail::send('emails.contact', $data, function($message) use ($user){
        $message->from('africamia@gmail.com', 'Admin');
        $message->to($user['email'], $user['name'])->subject('Welcome to My Laravel app!');
    });

    return View::make('gracias');
}

应用/配置/ mail.php

return array(   
'driver' = 'smtp',  
'host' = 'smtp.gmail.com',  
'port' = 587,   
'from' = array('address' = 'africamia@gmail.com', 'name' = 'Admin'),  
'encryption' = 'tls',   
'username' = 'africamia@gmail.com',   
'password' = '123456',   
'sendmail' =  '/usr/sbin/sendmail -bs',   
'pretend' = false,  
 ); 

1 个答案:

答案 0 :(得分:0)

您需要将emailcountrysubjectmsg添加到emails.contact PageController@postContact视图的数据中>