mardi 25 octobre 2016

Sending email in laravel 5 not working

After long searches in the forum, I can't find a helpful solution for my case.
I did alot of functions for sending emails in laravel and always that works fine.
This time, I got an error as you see below:

ErrorException in StreamBuffer.php line 95:
stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Here my .env file

APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:FMtA/k/okcPZB/HbWGbw5YiBM4EC3njxxLbgcdM1GrA=
APP_URL=http://localhost

DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=myDB
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=suckerblood2010@gmail.com
MAIL_PASSWORD=<<Here_my_password>>
MAIL_ENCRYPTION=tls

MAIL_SENDER=Administration

Here my function to send the mail (in the controller Auth):

public function register(Request $request)
{
    $this->validateLogin($request);

    $token = hash('sha256', str_random(100) . time(), false);
    $user = new User();
    $user->email = $request->get('email');
    $user->password = bcrypt($request->get('password'));
    $user->remember_token = $token;
    //$user->save();

    $sent = Mail::send('auth.emails.createAccount', ['token' => $token], function ($m) use ($user) {
        $m->from(getenv('MAIL_USERNAME'), getenv('MAIL_SENDER'));

        $m->to($user->email, $user->email)->subject(config('constants.AccountCreated'));
    });

    if($sent == 1)
    {
        $msg = Lang::get('messages.EmailSent');
        $this->showLoginForm($msg);
    }
    else
    {
        return redirect('/login')->withErrors([
            'email' => Lang::get('messages.UserAddingError')
        ]);
    }
}

I tried to change the protocol from tls to ssl, even the prot from 587 to 465
I have this problem only with this project and I can't understand why, despite all the searches I made...

Any suggestion please?
Thanks alot :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire