Last active
October 6, 2018 19:06
-
-
Save ahmed-bhs/c8f712bb887ba1b1d34eaa072197d80e to your computer and use it in GitHub Desktop.
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\MessageHandler; | |
use App\Message\SendNotification; | |
use Swift_Mailer; | |
class SendNotificationHandler | |
{ | |
/** | |
* @var Swift_Mailer | |
*/ | |
private $mailer; | |
public function __construct(Swift_Mailer $mailer) | |
{ | |
$this->mailer = $mailer; | |
} | |
public function __invoke(SendNotification $notification) | |
{ | |
foreach ($notification->getUsers() as $user) { | |
echo 'The mail has been sent with success !\r\n'; | |
$message = (new \Swift_Message('Mail object')) | |
->setFrom('[email protected]') | |
->setTo($user) | |
->setBody( | |
$notification->getMessage() | |
) | |
; | |
$this->mailer->send($message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment