Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bvfi-dev's avatar

Sending E-Mail throws a 504

Im trying to get the Email Verification to work, but Im having trouble. I shiuld mention Im using the Laravel Livewire Jetstream starter pack. The email verification from jetstream's side is enabled. First I had trouble with Authenticating the Email Credentials and it would throw an Email error, but after I fixed them, I now get 504 Gateway Time-out error. In the log file, it just says the Connection timeout'ed, which is correct. I click to send a mail, wait 30 seconds and get a timeout. My Mail is set up in Plesk, using Roundcube, and I can recieve and send emails. I can basically login to the webmail and use it. I believe there is some configuration in Laravel I missed, but what? Both my development and production environment are hosted on an owned server, on a custom domain. In the config/mail.php:

'default' => env('MAIL_MAILER', 'smtp'),
'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'url' => env('MAIL_URL'),
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'local_domain' => env('MAIL_EHLO_DOMAIN'),
        ],

So then this uses the .env values, which are:

MAIL_MAILER=smtp
MAIL_HOST=sub.domain.de
MAIL_PORT=465
[email protected]
MAIL_PASSWORD="random password"
MAIL_ENCRYPTION=ssl
[email protected]
MAIL_FROM_NAME="${APP_NAME}"

The host url, port, username and password is 100% correct, as I have a similar configuration for a different email for a CakePHP application. When I test the credentials there, it works fine (This is only for the cakePHP application):

'default' => [
            'className' => 'Smtp',
            'host' => 'ssl://sub.domain.de',
            'port' => 465,
            'timeout' => 30,
            'username' => '[email protected]',
            'password' => 'some random password',
            'client' => null,
        ],

I figured it has to be the SSL certificates, since my dev env doesnt have valid SSL certificates, but my live site does. Unfortunately, that was not it, I tested it on my production site, so now Im at a loss. It has to be something stupid, but what exactly? I have a stack trace from the production site, this is thrown when I try to send an email to a user:

[2024-05-21 15:30:34] production.ERROR: Connection could not be established with host "ssl://sub.domain.de:465": stream_socket_client(): Unable to connect to ssl://sub.domain.de:465 (Connection timed out) {"userId":29,"exception":"[object] (Symfony\Component\Mailer\Exception\TransportException(code: 0): Connection could not be established with host \"ssl://sub.domain.de:465\": stream_socket_client(): Unable to connect to ssl://sub.domain.de:465 (Connection timed out) at /vendor/symfony/mailer/Transport/Smtp/Stream/SocketStream.php:154)
[stacktrace]
#0 [internal function]: Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream->Symfony\Component\Mailer\Transport\Smtp\Stream\{closure}()
#1 /vendor/symfony/mailer/Transport/Smtp/Stream/SocketStream.php(157): 
stream_socket_client()
#2 /vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(275): 
Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream->initialize()
#3 /vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(213): 
Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->start()
#4 /vendor/symfony/mailer/Transport/AbstractTransport.php(69): 
Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->doSend()
#5 /vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(137): 
Symfony\Component\Mailer\Transport\AbstractTransport->send()
#6 /vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(573): 
Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->send()
#7 /vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(335):
 Illuminate\Mail\Mailer->sendSymfonyMessage()
#8 /vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php(66): 
Illuminate\Mail\Mailer->send()
#9 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(148): 
Illuminate\Notifications\Channels\MailChannel->send()
#10 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(106): 
Illuminate\Notifications\NotificationSender->sendToNotifiable()
#11 /vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php(19): 
Illuminate\Notifications\NotificationSender->Illuminate\Notifications\{closure}()
#12 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(101): 
Illuminate\Notifications\NotificationSender->withLocale()
#13 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(79): 
Illuminate\Notifications\NotificationSender->sendNow()
#14 /vendor/laravel/framework/src/Illuminate/Notifications/ChannelManager.php(39): 
Illuminate\Notifications\NotificationSender->send()
#15 /vendor/laravel/framework/src/Illuminate/Notifications/RoutesNotifications.php(18): 
Illuminate\Notifications\ChannelManager->send()
#16 /vendor/laravel/framework/src/Illuminate/Auth/MustVerifyEmail.php(38):
 App\Models\User->notify()
#17 /vendor/laravel/fortify/src/Http/Controllers/EmailVerificationNotificationController.php(27):
Illuminate\Foundation\Auth\User->sendEmailVerificationNotification()
#18 /vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): 
Laravel\Fortify\Http\Controllers\EmailVerificationNotificationController->store()
#19 /vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): 
Illuminate\Routing\Controller->callAction()
#20 /vendor/laravel/framework/src/Illuminate/Routing/Route.php(259): 
Illuminate\Routing\ControllerDispatcher->dispatch()
#21 /vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): 
Illuminate\Routing\Route->runController()
#22 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(806): 
Illuminate\Routing\Route->run() 

P.S. Clearing cache, config, doesnt seem to change anything.

0 likes
2 replies
bvfi-dev's avatar
bvfi-dev
OP
Best Answer
Level 3

Unblocking port 587 from the mails's side and using that port seem to have fixed this issue.

hanafi's avatar

@bvfi-dev can i know how do you do this? im having issue with digitalocean

Please or to participate in this conversation.