samedi 28 avril 2018

Laravel Swift_TransportException Connection could not be established with smtp.gmail.com [#0]

I've been stuck on a laravel error a while now, it states that connection could not be established [#0] instead of placing everything correctly in my env file. I'm posting my code here maybe someone can help me out with my error.

My Controller

<?php

namespace App\Http\Controllers;

use App\Order;
use Illuminate\Http\Request;
use App\Mail\OrderShipped;
use Carbon\Carbon;
use Illuminate\Support\Facades\Mail;
use App\User;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class OrderController extends Controller
{
    public function Orders($type='')
    {

        if($type =='pending'){
            $orders=Order::where('delivered','0')->get();
        }elseif ($type == 'delivered'){
            $orders=Order::where('delivered','1')->get();
        }else{
            $orders=Order::all();
        }
        return view('admin.orders.index',compact('orders'));
    }

    public function toggledeliver(Request $request,$orderId)
    {   
        $order=Order::find($orderId);
        if($request->has('delivered')){
            Mail::to($order->user)->send(new OrderShipped($order));
            $order->delivered=$request->delivered;            
        }else{
            $order->delivered="0";
        }
        $order->save();
        return back();
    }
}

The error occurs on Mail::to($order->user)->send(new OrderShipped($order)); line.

My OrderShipped:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class OrderShipped extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.email-shipped');
    }
}

My .env file:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:vmGDlc0kJ41pMM0jHoyi5PyCZ9FfQNrElxeCJKo5+PE=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=pharmacy
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
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=mygmail@gmail.com
MAIL_PASSWORD=XXXXXXXXXXXXXXXXXXX
MAIL_ENCRYPTION=tls

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

There is only 1 line in email-shipped.blade.php

<h1> Order Shipped </h1>

Please note that i've enabled 2 step verification in my gmail account and i've been placing my application generated password in my env file with my gmail account.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2KngGy0
via IFTTT

Aucun commentaire:

Enregistrer un commentaire