Laravel不发送电子邮件

时间:2014-03-31 09:06:02

标签: php email laravel laravel-4

我在使用Laravel 4从我的网站发送邮件时遇到了一些问题,我按照在线文档进行了操作但未成功通过Laravel发送邮件,我的代码如下所示。

Mail::send('emails.contactmail', $data, function($message)
{
    $name = Input::get('name');
    $email = Input::get('email');
    $message->from($email, $name);

    $message->to('info@mysite.org', 'Info at My Site')
            ->subject('Website contact form');
});

1 个答案:

答案 0 :(得分:0)

我在忘记密码的情况下使用以下代码发送临时密码

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'],'MyProject')->subject('Password Recovery ');
          });

          return Redirect::to('auth/login')->with('flash_message','Check your email account for temporary password');
}

我在forget_password.blade.php中写了一个电子邮件模板,该模板位于view.emails文件夹中。