Search code examples
laravel-5laravel-5.1email-verification

Trying to make Email verification in Laravel 5.1


I've got an error

Swift_TransportException in StreamBuffer.php line 265: Connection could not be established with host mailtrap.io [ #0]

May know what's the meaning of this? Glad that you could help me. thank you ^^


Solution

  • Mailing configuration can been seen at 2 places:

    1. .env file
    2. mail.php file located in config folder

    You can update either of them, but it is strictly recommended to edit the .env file so as to avoid touching the default configurations.

    Open .env file. You will see the mail configs in the bottom like so:

    MAIL_DRIVER=smtp
    MAIL_HOST=mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=null
    MAIL_PASSWORD=null
    MAIL_ENCRYPTION=null
    

    Now, login to your mailtrap.io account. From the Integrations dropdown, you need to select the Laravel option. When selected, the configs are provided below like this:

    return array(
      "driver" => "smtp",
      "host" => "mailtrap.io",
      "port" => 2525,
      "from" => array(
          "address" => "[email protected]",
          "name" => "Example"
      ),
      "username" => "your_username",
      "password" => "your_password",
      "sendmail" => "/usr/sbin/sendmail -bs",
      "pretend" => false
    );
    

    Now open the mail.php file:

    Go down to line number 57, it should have 'from' => ['address' => null, 'name' => null],. You need to replace this with what is provided in the mailtrap.io config.

    So the updated from should be 'from' => ['address' => '[email protected]', 'name' => 'Example'],.

    Now, in your .env file, update the MAIL_USERNAME and MAIL_PASSWORD with the your_username and your_password respectively.

    So, your mailing config in .env file should like:

    MAIL_DRIVER=smtp
    MAIL_HOST=mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=your_username
    MAIL_PASSWORD=your_password
    MAIL_ENCRYPTION=null
    

    Done. You should now see the mails functioning without any further issues. Hope this helps you out.

    Cheers.