简体   繁体   中英

Laravel: Mail connection error

i have a laravel 5.2 project working in a BLUEHOST shared server, and i having troubles configuring my email app, i'm not using another mail service (like mailgun) just the laravel's service, i tried it with my gmail account and their configurations and this worked fine (just for testing), so i need setup it with the BLUEHOST mail service.

I have this data form my email account configuration provided by BLUEHOST:

Email Settings

Mail Server Username: info@domain.com

Standard (without SSL)

Incoming Mail Server: mail.domain.com
Supported Ports: 143 (IMAP), 110 (POP3)
Outgoing Mail Server: mail.domain.com
Supported Port: 26 (server requires authentication)

Private (with SSL)

Incoming Mail Server: box668.bluehost.com (SSL)
Supported Ports: 993 (IMAP), 995 (POP3)
Outgoing Mail Server: box668.bluehost.com (SSL)
Supported Port: 465 (server requires authentication)
Supported Incoming Mail Protocols: POP3, IMAP
Supported Outgoing Mail Protocols: SMTP

My config/mail.php:

<?php

return [

    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'mail.domain.com'),

    'port' => env('MAIL_PORT', 465),

    'from' => ['address' => 'info@domain.com', 'name' => 'Some name'],

    'encryption' => env('MAIL_ENCRYPTION', 'ssl'),

    'username' => env('MAIL_USERNAME'),

    'password' => env('MAIL_PASSWORD'),

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

];

My .env email setup:

MAIL_DRIVER=smtp
MAIL_HOST=mail.domain.com
MAIL_PORT=465
MAIL_USERNAME=info@domain.com
MAIL_PASSWORD=info123+
MAIL_ENCRYPTION=ssl

I tried both options (Standard (without SSL) and Private (with SSL)) however i got this error:

Swift_TransportException in StreamBuffer.php line 269:
Connection could not be established with host mail.domain.com [ #0]

What's wrong? or my customer must buy a Mailgun's subscription?

I just figured this out for myself! I'm going to reiterate what Matthijs said and then my original contribution is bolded below -- that's what fixed it for me.

This is what I did, I don't know what you've already tried, but this worked for me.

I ssh'd into my server and cd into my laravel app. I should mention I'm hosted on Vultr not Bluehost, but it should work the same... I think?

cd /var/www/laravel

You're going to want to open your env file and make some configurations.

ls -a
nano .env

Make the changes on your server and then run the artisan config cache command

php artisan cache:command

If you're running through GMail, you need to make you're accepting less secure applications.

If this still isn't working then you need to actually go into your config folder and alter your mail.php file to match the information in your env file. Here's what mine looks like:

'driver' => env('MAIL_DRIVER', 'smtp'),


'host' => env('MAIL_HOST', 'smtp.gmail.com'),


'port' => env('MAIL_PORT', 587),


'from' => [
    'address' => env('MAIL_FROM_ADDRESS', 'spkellydev@gmail.com'),
    'name' => env('MAIL_FROM_NAME', 'Sean!'),
],


'encryption' => env('MAIL_ENCRYPTION', 'tls'),


'username' => env('MAIL_USERNAME'),

'password' => env('MAIL_PASSWORD'),


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

and then I have some custom settings under that which shouldn't be relevant at all. Hope this helps, friend!

Sometime it's possible to be "cache" in the laravel.

Use this command and try again:

php artisan config:clear

If not work, try to restart you xampp.

Another option to check if the problem is with your host or your configuration is to use a Gmail server to send a test email.

Puts this in your .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls

Create or use any gmail account and enable the less secure apps more information here

first login to your gmail account and under My account > Sign In And Security > Sign In to google, enable two step verification, then you can generate app password, and you can use that app password in .env file.

Your .env file will then look something like this

MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USERNAME=myemail@gmail.com MAIL_PASSWORD=apppassword MAIL_ENCRYPTION=tls

Don't forget to run php artisan config:cache after you make changes in your .env file (or restart your server).

Source here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM