title: Connection Could not be established with host smtp.gmail.com - Laravel
body: <p>I'm trying to send email by using gmail(personal email address) but failed as below error.
  there is no error when I using a public network to send the email but failed when I using office network that comes with firewall setting.</p>
  <p>I have tried the method to set the the mail_mailer to &quot;sendmail&quot; but still failed. Really appreciate if someone can help on this.</p>
  <p>Below is my code in .env and also mail.php</p>
  <p>code in .env</p>
  <pre><code>APP_NAME=KPI
  APP_ENV=local
  APP_KEY=base64:0SydcKbNLuXKE5PQgxlHIDWS/EGi8Sle2SrN2R+AGUo=
  APP_DEBUG=true
  APP_URL=http://localhost
  
  LOG_CHANNEL=stack
  LOG_LEVEL=debug
  
  DB_CONNECTION=mysql
  DB_HOST=127.0.0.1
  DB_PORT=3306
  DB_DATABASE=kpi
  DB_USERNAME=root
  DB_PASSWORD=
  
  BROADCAST_DRIVER=log
  CACHE_DRIVER=file
  QUEUE_CONNECTION=sync
  SESSION_DRIVER=file
  SESSION_LIFETIME=120
  
  MEMCACHED_HOST=127.0.0.1
  
  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=example@gmail.com
  MAIL_PASSWORD=example12345
  MAIL_ENCRYPTION=tls
  MAIL_FROM_ADDRESS=example@gmail.com
  MAIL_FROM_NAME=&quot;${APP_NAME}&quot;
  
  AWS_ACCESS_KEY_ID=
  AWS_SECRET_ACCESS_KEY=
  AWS_DEFAULT_REGION=us-east-1
  AWS_BUCKET=
  
  PUSHER_APP_ID=
  PUSHER_APP_KEY=
  PUSHER_APP_SECRET=
  PUSHER_APP_CLUSTER=mt1
  
  MIX_PUSHER_APP_KEY=&quot;${PUSHER_APP_KEY}&quot;
  MIX_PUSHER_APP_CLUSTER=&quot;${PUSHER_APP_CLUSTER}&quot;
  </code></pre>
  <p>code in mail.php</p>
  <pre><code>&lt;?php
  
  return [
  
      'default' =&gt; env('MAIL_DRIVER', 'smtp'),
  
      'mailers' =&gt; [
          'smtp' =&gt; [
              'transport' =&gt; 'smtp',
              'host' =&gt; env('MAIL_HOST', 'smtp.mailgun.org'),
              'port' =&gt; env('MAIL_PORT', 465),
              'encryption' =&gt; env('MAIL_ENCRYPTION', 'tls'),
              'username' =&gt; env('MAIL_USERNAME'),
              'password' =&gt; env('MAIL_PASSWORD'),
              'timeout' =&gt; null,
              'auth_mode' =&gt; null,
          ],
  
          'ses' =&gt; [
              'transport' =&gt; 'ses',
          ],
  
          'mailgun' =&gt; [
              'transport' =&gt; 'mailgun',
          ],
  
          'postmark' =&gt; [
              'transport' =&gt; 'postmark',
          ],
  
          'sendmail' =&gt; [
              'transport' =&gt; 'sendmail',
              'path' =&gt; '/usr/sbin/sendmail -bs',
          ],
  
          'log' =&gt; [
              'transport' =&gt; 'log',
              'channel' =&gt; env('MAIL_LOG_CHANNEL'),
          ],
  
          'array' =&gt; [
              'transport' =&gt; 'array',
          ],
      ],
  
     
  
      'from' =&gt; [
          'address' =&gt; env('MAIL_FROM_ADDRESS', 'hello@example.com'),
          'name' =&gt; env('MAIL_FROM_NAME', 'Example'),
      ],
      
      'stream' =&gt; [
          'ssl' =&gt; [
              'allow_self_signed' =&gt; true,
              'verify_peer' =&gt; false,
              'verify_peer_name' =&gt; false,
          ],
      ],
  
  
      'markdown' =&gt; [
          'theme' =&gt; 'default',
  
          'paths' =&gt; [
              resource_path('views/vendor/mail'),
          ],
      ],
  
  ];
  </code></pre>
  <p><a href="https://i.stack.imgur.com/YbbAl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YbbAl.png" alt="Error message" /></a></p>