alex32's avatar

Email plain smtp | error

I need Laravel to send emails using plain smtp on port 25 - I know it's unsecure but I currently have a problem with the mailserver ssl certificate. Why laravel still want to use STARTTLS?

Thanks

Here is what I did:

.env

MAIL_MAILER=smtp
MAIL_HOST=mail.example.com
MAIL_PORT=25
[email protected]
MAIL_ENCRYPTION=null 

check config/mail.php

        'smtp' => [
            'transport' => 'smtp',
            'url' => env('MAIL_URL'),
            'host' => env('MAIL_HOST', 'mail.example.com'),
            'port' => env('MAIL_PORT', 25),                   
            'encryption' => env('MAIL_ENCRYPTION', 'null'),    
         ],

Error:

Symfony \ Component \ Mailer \ Exception \ TransportException
PHP 8.2.15
laravel 10.44.0
Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:0A000086:SSL routines::certificate verify failed


0 likes
8 replies
gych's avatar

Have you already tried to clear the config? php artisan config:clear

You can also try to use no value in the ENV file instead of null

MAIL_ENCRYPTION=
Snapey's avatar

Does the mail server you are trying to use accept port 25 ?

alex32's avatar

Hi both, thanks for your help. I tried MAIL_ENCRYPTION= and cleared the cache: same error Yes, port 25 is open in the firewall.

Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:0A000086:SSL routines::certificate verify failed

I've another website made in plain php-html where I send plain smtp emails and it works. Is there a way to bypass the SSL Symfony module?

Snapey's avatar

Yes, port 25 is open in the firewall.

thats not what I asked

Snapey's avatar

btw

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

is a string of null, not php null

alex32's avatar

@Snapey I tried the following, same error

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

My mailserver accept port 25, as below:

POP3	Details
Server Hostname	mail.example.com
Port	110
Port	995 (SSL)
SSL	    STARTTLS

IMAP	Details
Server Hostname	mail.example.com
Port	143
Port	993 (SSL)
SSL	    STARTTLS

SMTP	Details
Server Hostname	mail.example.com
Port	25
Port	587 (SSL)
Port	465 (SSL)
SSL	    STARTTLS

The Symfony error occurs when Fortify tries to send the email verification to the user.

app/ Http/ Middleware/ CheckIsAdmin .php


namespace App\Http\Middleware;
 
use Closure; 
use Illuminate\Http\Request; 
use Symfony\Component\HttpFoundation\Response; 
use Illuminate\Support\Facades\Log;


class CheckIsAdmin

{

    /**

     * Handle an incoming request. 
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next 
     */

    public function handle(Request $request, Closure $next): Response

    {

        if ($request->user()) {

            $uid= $request->user()->id;
 
            if ($uid != ADMIN) {  

                return redirect()->route('home');

            }

        }

        return $next($request);  // SSL ERROR
 

    }

}


Snapey's avatar

@alex32 email is sent from a listener. It shouldn't matter, but I'm just pointing out that its not done in the middleware

alex32's avatar

@Snapey Understood , I added the code to the handle() method, and the error points to this line number:

 return $next($request);  // SSL ERROR

I'm using the default Laravel Jetstream and Fortify is trying to verify the user by email. There must be a way to bypass the Symfony module and use the standard php mail() function instead. Do you know how it can be done? Thanks

Please or to participate in this conversation.