too long

I am trying to send a message to an email using smtp.mailtrap.io in Laravel. I have followed a youtube tutorial and keep getting the following error.

Connection could not be established with host smtp.mailtrap.io

I have attached my code below for this.

PagesController

    <?php 

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Post;
use Mail;
use Session;

class PagesController extends Controller {

public function getIndex() {
$posts = Post::orderBy('created_at', 'desc')->limit(4)->get();
return view('welcome')->withPosts($posts);
}

public function getAbout() {
$first = 'Niamh';
$last = 'Flannery';

$fullname = $first . " " . $last;
$email = 'niamh3516@hotmail.co.uk';
$data = [];
$data['email'] = $email;
$data['fullname'] = $fullname;
return view('pages.about')->withData($data);
}

public function getContact() {
return view('contact');
}

public function postContact(Request $request) {
$this->validate($request, [
'email' => 'required|email',
'subject' => 'min:3',
'message' => 'min:10']);

$data = array(
'email' => $request->email,
'subject' => $request->subject,
'bodyMessage' => $request->message
);

Mail::send('emails.contact', $data, function($message) use ($data){
$message->from($data['email']);
$message->to('niamh3516@hotmail.co.uk');
$message->subject($data['subject']);
});

Session::flash('success', 'Your Email was Sent!');

return redirect('/');
}


}

Contact.blade.php

    <div class="row">
        <div class="col-md-12">
            <h1>Contact Me</h1>
            <hr>
            <form action="{{ url('contact') }}" method="POST">
                {{ csrf_field() }}
                <div class="form-group">
                    <label name="email">Email:</label>
                    <input id="email" name="email" class="form-control">
                </div>

                <div class="form-group">
                    <label name="subject">Subject:</label>
                    <input id="subject" name="subject" class="form-control">
                </div>

                <div class="form-group">
                    <label name="message">Message:</label>
                    <textarea id="message" name="message" class="form-control">Type your message here...</textarea>
                </div>

                <input type="submit" value="Send Message" class="btn btn-success">
            </form>
        </div>
    </div>

web.php

Route::get('contact', 'PagesController@getContact');

Route::post('contact', 'PagesController@postContact');

contact.php

<h3> You have a new contact via the contact form </h3>

<div>

{{$bodyMessage}}

</div>

<p> Sent Via {{$email}}</p>

.env

MAIL_DRIVER=smtp

MAIL_HOST=smtp.mailtrap.io

MAIL_PORT=25

MAIL_USERNAME=c388d55897e620

MAIL_PASSWORD=f3d7fa90a9c6ab

MAIL_ENCRYPTION=null

Use the following settings your .env file

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=587
MAIL_USERNAME=c388d55897e620
MAIL_PASSWORD=f3d7fa90a9c6ab
MAIL_ENCRYPTION=tls

And in your config/mail.php add this at the bottom

'stream' => [
      'ssl' => [
          'allow_self_signed' => true,
          'verify_peer' => false,
          'verify_peer_name' => false,
      ],
    ],

and check if this is correct

'sendmail' => '/usr/sbin/sendmail -bs',

Make sure ssl and smtp are enabled and properly configured on your localhost(check your php.ini)

If you are running the project from your Cpanel trying to use port 465 as priority among other ports provide by mailtrap, while running locally use 2525.