mardi 26 janvier 2016

Laravel 5 missmatch token in sending email

i'm using ajax to send email so i my problem is if i dont have

{!! csrf_field() !!}

in view i will get the token missmatch error.If i add input hidden token in view i will get this error

Swift_RfcComplianceException in MailboxHeader.php line 348: Address in mailbox given [] does not comply with RFC 2822, 3.6.2.

How can i fix it.Thanks for help.

here it's view

 <form action="{{ url('/findpass')}}" method="POST" id="forgotpassForm">
                                    {!! csrf_field() !!}
                                    <div class="form-group">
                                       <input class="form-control input-lg" placeholder="E-mail" name="emailForgot" type="email" id="emailForgot" required>
                                    </div>
                                    <input type="submit" class="btn btn-lg btn-primary btn-block" id="forgotpassBtn" value="Send email">
                            </form>

Ajax

$(document).ready(function() {
    $('#forgotpassBtn').click(function() {
        event.preventDefault();
        var email=$("#emailForgot").val();
        var _token = $("input[name='_token']").val();
        $.ajax({
            url: '/findpass',
            type: 'POST',
            data:{
                email:email,
                _token : _token  
            },
            success:function(data) {
                alert(data.mess);
                $("#forgotpass")[0].reset();
            },
            error:function() {
                alert("Error");
            }
        });


    });
});

Controller

public function resetPass()
    {
        $emailForgot=Input::get('emailForgot');
        $user= User::where('email', '=' , $emailForgot)->first();
        $data=['username'=>$user -> username,'email'=>$user -> email,'token'=>$user -> remember_token];
        Mail::send('ui.mail.reset',$data, function ($m) use ($user) {
            $m->from('ngohungphuc95@gmail.com', 'Reset password');
            $m->to($user->email, $user->full_name)->subject('Email reset password');
        });
        return response()->json(array('mess'=>'Mail send'));
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire