-
-
Save kevyworks/e9d875b2c4e4d3cba91227e6e1cd46f9 to your computer and use it in GitHub Desktop.
Email notification in laravel
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 Eder\Jobs; | |
use Eder\Jobs\Job; | |
use Illuminate\Contracts\Mail\Mailer; | |
use Illuminate\Queue\SerializesModels; | |
use Illuminate\Queue\InteractsWithQueue; | |
use Illuminate\Contracts\Bus\SelfHandling; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
use BMO\Identity\Notification; | |
class SendNotificationEmail extends Job implements SelfHandling, ShouldQueue | |
{ | |
use InteractsWithQueue, SerializesModels; | |
protected $emailInfo; | |
protected $data; | |
protected $notification; | |
/** | |
* Create a notification job instance. | |
* | |
* @param Notification $notification | |
* @return void | |
*/ | |
public function __construct(Notification $notification, $emailInfo, array $data) | |
{ | |
$this->notification = $notification; | |
$this->emailInfo = $emailInfo; | |
$this->data = $data; | |
} | |
/** | |
* Execute the job. | |
* get messageId from ses after send email | |
* | |
* @param Mailer $mailer | |
* @return void | |
*/ | |
public function handle(Mailer $mailer) | |
{ | |
$emailInfo = $this->emailInfo; | |
try { | |
$sesMessages = $mailer->send($emailInfo['template'], $this->data, function ($message) use ($emailInfo) { | |
$message | |
->to($emailInfo['email'], $emailInfo['name']) | |
->subject($emailInfo['subject']); | |
}); | |
} catch (Exception $e) { | |
\Log::error('send notifications email error' . $e->getMessage()); | |
} | |
if ($sesMessages && $sesMessages->get('MessageId')) { | |
$this->notification->ses_message_id = $sesMessages->get('MessageId'); | |
} | |
$this->notification->sns_notification_type = ''; | |
$this->notification->save(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment