我是Laravel的新手。我正在尝试发送带附件的电子邮件
这是我尝试的。
在app/config/mail
'driver' => 'mail',
这是我的路线
Route::get('join-us', 'handleFormController@joinus');
Route::post('joinRequest', 'handleFormController@getJoinRequest');
,这是表格
{{ Form::open(array('url'=>'joinRequest', 'files'=>'true')) }}
@foreach($errors->all('
:message
') as $message) {{ $message }}
@endforeach
<div class="form-group pull-right ">
{{ Form::label('name', ' ') }}
<div class="col-xs-12">
{{ Form::text('name', '', array('class'=>'form-control1 row input-sm', 'placeholder'=>'الاسم')) }}
</div>
</div>
<div class="form-group pull-right ">
{{ Form::label('email', ' ') }}
<div class="col-xs-12">
{{ Form::text('email', '', array('class'=>'form-control1 row input-sm', 'placeholder'=>'البريد الإلكتروني')) }}
</div>
</div>
<div class="form-group pull-right ">
{{ Form::label('job', ' ') }}
<div class="col-xs-12">
{{ Form::text('job', '', array('class'=>'form-control1 row input-sm', 'placeholder'=>'المهنة او الوظيفة الحاليه')) }}
</div>
</div>
<div class="form-group pull-right ">
{{ Form::label('comment', ' ') }}
<div class="col-xs-12">
{{ Form::textarea('comment', '', array('class'=>'form-control1 row input-sm', 'placeholder'=>'اترك تعليق')) }}
</div>
</div>
{{--<div class="form-group pull-right ">
{{ Form::label('resume', ' ') }}
<div class="col-xs-12">
{{ HTML::script('siteroot/fileinput.js') }}
{{ Form::file('resume', array('class'=>'file')) }}
</div>
</div>--}}
<div class="col-xs-12 pull-right">
{{ Form::submit('أرسال', array('class'=>'btn btn-primary pull-right')) }}
</div>
{{Form::close()}}
,这是我的控制器
public function getJoinRequest()
{
$data = Input::all();
$rules = array(
'name' => 'required|regex:/^[\pL\s\-]+$/u',
'email' => 'required|email',
'job' => 'required|alpha',
'comment' => 'required|min:25'
);
$validator = Validator::make($data, $rules);
if ($validator->passes()) {
Mail::send('emails.joinRetunMessage.hello', $data, function ($message) use ($data) {
$message->from($data['email'], $data['name']);
$message->to('johnef_sh@hotmail.com', 'El Arabia')->subject('Join us request');
/*$message->attach($data['resume']->getRealPath(), array(
'as' => 'resume.' . $data['resume']->getClientOriginalExtension(),
'mime' => $data['resume']->getMimeType())
);*/
});
return Redirect::to('/join-us')
->with('message', 'Your message has been sent. Thank You!');
} else {
return Redirect::to('/join-us')->withErrors($validator);
}
}
当我提交表单时,它返回页面没有任何错误,但邮件没有发送。
答案 0 :(得分:1)
我在忘记密码的情况下使用以下代码发送临时密码
public function postForgotPassword(ForgotPasswordRequest $request){
$email=$request->email;
$objUser=DB::table('users')
->where('email','=',$email)
->select('email','id','first_name','last_name','user_group_id')
->first();
$string = str_random(15);
$pass=\Hash::make($string);
$objUser2=User::find($objUser->id);
$CURRENT_TIMESTAMP=new DateTime();
$objUser2->temporary_pass=$pass;
$objUser2->pass_status=1;
$objUser2->updated_at=$CURRENT_TIMESTAMP;
$objUser2->save();
$data=array("email"=>$email,"pass"=>$string,"first_name"=>$objUser->first_name,"last_name"=>$objUser->last_name);
$email=array("email"=>$email);
Mail::send('emails.forgot_password',$data, function($message) use($email) {
$message->to($email['email'],'MoveInSpace')->subject('Password Recovery ');
});
return Redirect::to('auth/login')->with('flash_message','Check your email account for temporary password');
}
我在forget_password.blade.php中写了一个电子邮件模板,该模板位于view.emails文件夹中。 还要确保正确配置配置邮件文件。如果可能的话使用smtp驱动程序
'driver' => 'smtp',
我在mail.php中使用以下代码
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'abc@gmail.com', 'name' => 'ABC'),
'encryption' => 'tls',
'username' => 'abc@gmail.com',
'password' => 'yourpassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,