2016-08-25 42 views
0

我是Laravel的新手。我試圖發送電子郵件附件在我的應用程序中發送郵件laravel 4.2

這裏我試試。

在我app/config/mail

'driver' => 'mail', 

這是我的路線

Route::get('join-us', '[email protected]'); 
Route::post('joinRequest', '[email protected]'); 

,這是形式

{{ 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('[email protected]', '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

看這裏http://stackoverflow.com/questions/5832487/php-mail-function-doesnt-工作 –

+0

@Andrej Ludinovskov你可能沒有得到我的問題我試圖通過Laravel 4.2發送它不是原生PHP –

+0

但你使用本地PHP函數郵件作爲驅動程序。這意味着你正確設置了它。 –

回答

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

而且我寫的,其中位於view.emails文件夾forgot_password.blade.php電子郵件模板。 另外請確保您正確配置配置郵件文件。如果可能的話使用SMTP司機

'driver' => 'smtp', 

我用我的mail.php下面的代碼

'host' => 'smtp.gmail.com', 
'port' => 587, 
'from' => array('address' => '[email protected]', 'name' => 'ABC'), 
'encryption' => 'tls', 
'username' => '[email protected]', 
'password' => 'yourpassword', 
'sendmail' => '/usr/sbin/sendmail -bs', 
'pretend' => false,