1

How can I test email on localhost with Laravel 7? I have a Smtp4Dev server running which should catch communication on the specified port. I choose port 25. My Laravel 7 mail setting is below:

.env

MAIL_MAILER=smtp
MAIL_HOST=xxxxxxxxxx.contaboserver.net
MAIL_PORT=25
MAIL_USERNAME="noreplay@xxxxxxxxx.eu"
MAIL_PASSWORD="xxxxxxxxx"
MAIL_ENCRYPTION=
MAIL_FROM_ADDRESS="noreplay@xxxxxxxxx.eu"
MAIL_FROM_NAME="${APP_NAME}"

config/mail.php

'smtp' => [
    'transport' => 'smtp',
    'host' => env('MAIL_HOST'),
    'port' => env('MAIL_PORT'),
    'encryption' => env('MAIL_ENCRYPTION'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'timeout' => null,
    'auth_mode' => null,
    'stream' => [
        'ssl' => [
            'allow_self_signed' => true,
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ],
],

With these settings I am getting an error:

Failed to authenticate on SMTP server with username "noreplay@xxxxxxxxx.eu" using 3 possible authenticators. Authenticator CRAM-MD5 returned Expected response code 235 but got code "535", with message "535 5.7.0 Invalid login or password ". Authenticator LOGIN returned Expected response code 250 but got an empty response.

If I remove

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

I get an error

stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

I also run artisan config:clear. I don't know what should I do now. Why local Smtp4dev server requires authentication?

Čamo
  • 3,863
  • 13
  • 62
  • 114
  • if you have credential in env then make sure if password or username contain special character then you have quote .MAIL_PASSWORD="sf$#dgsd#$". – John Lobo Jun 03 '21 at 09:04
  • also check which port is used for mail server. sometimes it might differ i guess – John Lobo Jun 03 '21 at 09:10
  • Password is enclosed in quotation marks but I need to catch it in Smtp4Dev server which rund on local machine and listeningon port 25. I am not able to send anything with valid credentials from localhost to remote mail server. Swift has still some problem with it. – Čamo Jun 03 '21 at 11:04
  • do you have MAIL_ENCRYPTION=tls – John Lobo Jun 03 '21 at 11:07
  • I tried tls, ssl, null nothing works. I remember in the past time I switched encryption off and it worked. But not now. – Čamo Jun 03 '21 at 11:17

2 Answers2

1

try to change your MAIL_ENCRYPTION= with

MAIL_ENCRYPTION=ssl

and run

php artisan config:clear

if you are not using vhost, or getting null after dump the .MAIL_ENCRYPTION key reload your artisan serve or your xampp

antare74
  • 84
  • 5
0

With Laravel 6.x ,7.x and 8.x

it is advisable to use SSL over the default tls.

Most shared hosting providers sign emails with SSL so edit your .env file to have this

MAIL_ENCRYPTION=ssl
Barungi Stephen
  • 759
  • 8
  • 13
  • You can also run ```php artisan config:cache``` after adding it to your env file – Barungi Stephen Jun 03 '21 at 09:19
  • I tried tls, ssl, null nothing works. I remember in the past time I switched encryption off and it worked. But not now. – Čamo Jun 03 '21 at 11:16
  • I dont know but I have my own mail server. Is it necessary to allow something in there? Another application which is in production is able to send mail to this server, but not localhost. What is that if I have valid credentials? – Čamo Jun 03 '21 at 11:19