Created
October 29, 2019 13:59
-
-
Save dersonsena/df8874678a56a151830dfcf2cb2afd2b to your computer and use it in GitHub Desktop.
This file contains 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 GoSale\RabbitMQ; | |
abstract class HandlerAbstract implements HandlerInterface | |
{ | |
/** | |
* @var array | |
*/ | |
protected $payload; | |
public function __construct($payload) | |
{ | |
$this->payload = $payload; | |
} | |
} |
This file contains 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 GoSale\RabbitMQ; | |
interface HandlerInterface | |
{ | |
public function handle(); | |
} |
This file contains 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; | |
use GoSale\RabbitMQ\HandlerAbstract; | |
use Swift_Mailer; | |
use Swift_Message; | |
use Swift_SmtpTransport; | |
final class WelcomeClientMail extends HandlerAbstract | |
{ | |
public function handle() | |
{ | |
// Create the Transport | |
$transport = new Swift_SmtpTransport( | |
getenv('MAILER_SMTP_HOST'), | |
getenv('MAILER_SMTP_PORT'), | |
getenv('MAILER_SMTP_ENCRYPT') ?? null | |
); | |
$transport->setStreamOptions([ | |
'ssl' => [ | |
'allow_self_signed' => true, | |
'verify_peer' => false, | |
'verify_peer_name' => false, | |
] | |
]); | |
$transport->setUsername(getenv('MAILER_SMTP_USERNAME')); | |
$transport->setPassword(getenv('MAILER_SMTP_PASSWORD')); | |
// Create the Mailer using your created Transport | |
$mailer = new Swift_Mailer($transport); | |
// Create a message | |
$message = (new Swift_Message('Welcome to the Go! Sale')) | |
->setFrom([getenv('MAILER_SMTP_USERNAME') => 'Go! Sale']) | |
->setTo([$this->payload->email => $this->payload->name]) | |
->setBody("Hello {$this->payload->name}. Welcome to the Go! Sale."); | |
// Send the message | |
$result = $mailer->send($message); | |
print_r($this->payload); | |
var_dump($result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment