5
新手到Laravel電子郵件所以那種笑通過發送形式的文件,Laravel(本地主機)
我對mail.php配置是正確的,併成功地接收電子郵件,文本輸入Gmail,但不能完全確定如何完成文件的任務。我希望有一些幫助或參考鏈接。
在此先感謝!
守則routes.php文件
Route::get('/', function()
{
return View::make('form');
});
Route::post('/form', function()
{
$data = ['firstname' => Input::get('firstname'), 'username' => Input::get('username'), 'email' => Input::get('email'), 'resume' => Input::get('resume') ];
$rules = array(
'username' => 'Required|Min:7',
'email' => 'Required|Email',
'firstname' => 'Required',
'resume' => 'Required'
);
$validation = Validator::make(Input::all(), $rules);
if ($validation->fails())
{
// Validation has failed.
return Redirect::to('/')->withInput()->withErrors($validation);
}
else {
Mail::send('emails.welcome', $data, function($message)
{
$message->to('[email protected]');
$message->subject('Welcome to Laravel');
$message->from('[email protected]');
});
return Redirect::to('/')->withInput()->with('success', 'Thank you for your submission.');
}
//
});
守則form.blade.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Form</title>
</head>
<body>
@if(Session::has('success'))
<div class="alert-box success">
<h2>{{ Session::get('success') }}</h2>
</div>
@endif
{{ Form::open(array('url' => '/form')) }}
<p>{{ Form::label('email', 'E-Mail Address');}} <br>{{ Form::email('email', '[email protected]');}}</p>
{{ $errors->first('email') }}
<p>{{ Form::label('username', 'Username');}} <br> {{Form::text('username');}}</p>
{{ $errors->first('username') }}
<p>{{ Form::label('firstname', 'First Name');}} <br> {{Form::text('firstname');}}</p>
{{ $errors->first('firstname') }}
<p>{{ Form::file('resume'); }}</p>
<p>{{Form::submit('Send Details');}}</p>
{{ Form::close() }}
</body>
</html>