root 5 years ago
parent
commit
eee6351e35
2 changed files with 21 additions and 9 deletions
  1. 2 2
      app/Console/Commands/SendRemindMail.php
  2. 19 7
      app/Jobs/SendEmail.php

+ 2 - 2
app/Console/Commands/SendRemindMail.php

@@ -56,7 +56,7 @@ class SendRemindMail extends Command
                 'template_value' => [
                     'name' => config('v2board.app_name', 'V2Board')
                 ]
-            ])->delay(10);
+            ]);
         }
     }
 
@@ -73,7 +73,7 @@ class SendRemindMail extends Command
                 'template_value' => [
                     'name' => config('v2board.app_name', 'V2Board')
                 ]
-            ])->delay(10);
+            ]);
         }
     }
     

+ 19 - 7
app/Jobs/SendEmail.php

@@ -8,6 +8,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Queue\SerializesModels;
 use Illuminate\Support\Facades\Mail;
+use App\Models\MailLog;
 
 class SendEmail implements ShouldQueue
 {
@@ -33,12 +34,23 @@ class SendEmail implements ShouldQueue
         $params = $this->params;
         $email = $params['email'];
         $subject = $params['subject'];
-        Mail::send(
-            $params['template_name'], 
-            $params['template_value'],
-            function ($message) use($email, $subject) { 
-                $message->to($email)->subject($subject); 
-            }
-        );
+        try {
+            Mail::send(
+                $params['template_name'], 
+                $params['template_value'],
+                function ($message) use($email, $subject) { 
+                    $message->to($email)->subject($subject); 
+                }
+            );
+        } catch (\Exception $e) {
+            $error = $e->getMessage();
+        }
+
+        MailLog::create([
+            'email' => $params['email'],
+            'subject' => $params['subject'],
+            'template_name' => $params['template_name'],
+            'error' => isset($error) ? $error : NULL
+        ]);
     }
 }