SSL error while sending mail using SwiftMailer on DigitalOcean droplet. How to debug?


I don’t know how to go about debugging this. Any help would be great!

I am using Laravel 4.2 (I know it’s high time I upgrade). I am sending mail using Gmail SMTP. I am able to send mail on local environment without issue, but on the production server it is throwing the following error:

[2020-11-20 15:55:52] production.ERROR: ErrorException: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14161044:SSL routines:state_machine:internal error in /var/www/
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleError(2, 'stream_socket_e...', '/var/www/domain...', 94, Array)
#1 /var/www/ stream_socket_enable_crypto(Resource id #10, true, 9)
#2 /var/www/ Swift_Transport_StreamBuffer->startTLS()
#3 /var/www/ Swift_Transport_EsmtpTransport->_doHeloCommand()
#4 /var/www/ Swift_Transport_AbstractSmtpTransport->start()
#5 /var/www/ Swift_Mailer->send(Object(Swift_Message), Array)
#6 /var/www/ Illuminate\Mail\Mailer->sendSwiftMessage(Object(Swift_Message)) #7 /var/www/ Illuminate\Mail\Mailer->send('emails.bulk-ord...', Array, Object(Closure))
#8 /var/www/ Illuminate\Support\Facades\Facade::__callStatic('send', Array)
#9 /var/www/ App\Libraries\Functions\sendMail('emails.bulk-ord...', Array, Array, 1)
#10 [internal function]: BulkOrderController->checkout()
#11 /var/www/ call_user_func_array(Array, Array)
#12 /var/www/ Illuminate\Routing\Controller->callAction('checkout', Array)
#13 /var/www/ Illuminate\Routing\ControllerDispatcher->call(Object(BulkOrderController), Object(Illuminate\Routing\Route), 'checkout')
#14 /var/www/ Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'BulkOrderContro...', 'checkout')
#15 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#16 /var/www/ call_user_func_array(Object(Closure), Array)
#17 /var/www/ Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#18 /var/www/ Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#19 /var/www/ Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#20 /var/www/ Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#21 /var/www/ Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#22 /var/www/ Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#23 /var/www/ Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#24 /var/www/ Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#25 /var/www/ Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#26 /var/www/ Illuminate\Foundation\Application->run()

The code is hosted on a DigitalOcean droplet (Ubuntu 20.04).

Contents of app/config/mail.php:


return array(
    'driver' => 'smtp',
    'host' => '',
    'port' => 587,
    'from' => array('address' => '', 'name' => 'Company Name'),
    'encryption' => 'tls',
    'username' => 'GmailUserName',
    'password' => 'GmailPassword',
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there @tuhinpaul,

Indeed as you mentioned, it would be best to go ahead and upgrade but it definitely can be challenging.

I could not replicate this myself, but you could try the suggestion from this discussion here:

Edit the config/mail.php file and add the following:

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

Note: this is not ideal as it is essentially disabling TLS and could have some security implications.

Let me know how it goes! Regards, Bobby