Skip to content

Instantly share code, notes, and snippets.

@ahmed-bhs
Last active October 6, 2018 19:06
Show Gist options
  • Save ahmed-bhs/c8f712bb887ba1b1d34eaa072197d80e to your computer and use it in GitHub Desktop.
Save ahmed-bhs/c8f712bb887ba1b1d34eaa072197d80e to your computer and use it in GitHub Desktop.
<?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