From c1994bf9b83e34c5185a933f8f642e3ee11e6fe9 Mon Sep 17 00:00:00 2001
From: dogukanoksuz <me@dogukan.dev>
Date: Sun, 24 Sep 2023 09:55:45 +0000
Subject: [PATCH] fix: Application freezing issues on mail sending

---
 .env.example                                                  | 4 ++--
 app/Http/Controllers/Extension/Sandbox/InternalController.php | 2 ++
 app/Observers/UserObserver.php                                | 4 ++++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/.env.example b/.env.example
index 79ca560e..433a4933 100644
--- a/.env.example
+++ b/.env.example
@@ -90,11 +90,11 @@ MAIL_MAILER=smtp
 
 # MAIL HOST
 # Mail server
-MAIL_HOST=smtp.mailtrap.io
+MAIL_HOST=0.0.0.0
 
 # MAIL PORT
 # Mail server port
-MAIL_PORT=2525
+MAIL_PORT=1025
 
 # MAIL USERNAME
 # The user that exists on mail server
diff --git a/app/Http/Controllers/Extension/Sandbox/InternalController.php b/app/Http/Controllers/Extension/Sandbox/InternalController.php
index 3a007fe4..e6ba3e14 100644
--- a/app/Http/Controllers/Extension/Sandbox/InternalController.php
+++ b/app/Http/Controllers/Extension/Sandbox/InternalController.php
@@ -91,6 +91,8 @@ private function checkPermissions()
      */
     public function sendMail()
     {
+        if (! (bool) env('MAIL_ENABLED', false)) return;
+
         Mail::to(request('to'))->send(
             new ExtensionMail(
                 request('subject'),
diff --git a/app/Observers/UserObserver.php b/app/Observers/UserObserver.php
index dd391e8f..a655b04e 100644
--- a/app/Observers/UserObserver.php
+++ b/app/Observers/UserObserver.php
@@ -16,6 +16,8 @@ class UserObserver
      */
     public function created(User $user)
     {
+        if (! (bool) env('MAIL_ENABLED', false)) return;
+
         try {
             Mail::to($user->email)
                 ->send(new Information(
@@ -32,6 +34,8 @@ public function created(User $user)
      */
     public function updating(User $user)
     {
+        if (! (bool) env('MAIL_ENABLED', false)) return;
+
         if ($user->isDirty('password')) {
             try {
                 Mail::to($user->getOriginal('email'))