Last active
November 12, 2019 06:40
-
-
Save einnar82/e46ed729d927ef32bdc5aab21224a5fc to your computer and use it in GitHub Desktop.
Added error handling in Laravel Mail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Mail\API; | |
use App\Events\API\MessageSending; | |
use App\User; | |
use Illuminate\Bus\Queueable; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
use Illuminate\Mail\Mailable; | |
use Illuminate\Queue\SerializesModels; | |
use Illuminate\Contracts\Mail\Mailer as MailerContract; | |
class RegistrationDetails extends Mailable implements ShouldQueue | |
{ | |
use Queueable, SerializesModels; | |
public $tries = 3, $file; | |
/** | |
* Create a new message instance. | |
* | |
* @return void | |
*/ | |
public function __construct($file) | |
{ | |
$this->file = $file; | |
} | |
/** | |
* Build the message. | |
* | |
* @return $this | |
*/ | |
public function build() | |
{ | |
return $this->markdown('emails.registration.invite') | |
->attach(\Storage::disk('users')->url($this->file)); | |
} | |
/** | |
* Override send function | |
*/ | |
public function send(MailerContract $mailer) | |
{ | |
try { | |
parent::send($mailer); | |
User::where('qr_code', $this->file)->firstOrFail()->update(['mail_sent_at' => now()]); | |
\Log::debug('email sent'); | |
} catch (\Exception $error) { | |
\Log::debug($error->getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment