- Fixed some minor typos
This commit is contained in:
parent
f0b2ab10fd
commit
b284b67d91
|
@ -23,6 +23,8 @@ class EmailConfiguration
|
||||||
public $fromAddress = "";
|
public $fromAddress = "";
|
||||||
|
|
||||||
public $fromName = "";
|
public $fromName = "";
|
||||||
|
|
||||||
|
public $smtpVerifyPeer = false;
|
||||||
|
|
||||||
public function __construct($type = self::AUTH_TYPE_SMTP)
|
public function __construct($type = self::AUTH_TYPE_SMTP)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,17 +13,23 @@ class SymfonyMailer implements MailerInterface
|
||||||
|
|
||||||
public function __construct(EmailConfiguration $configuration) {
|
public function __construct(EmailConfiguration $configuration) {
|
||||||
$this->emailConfiguration = $configuration;
|
$this->emailConfiguration = $configuration;
|
||||||
$this->mailer = new Mailer(Transport::fromDsn(spritf("smtp://%s:%s@%s:%d", $this->emailConfiguration->smtpUsername, $this->emailConfiguration->smtpPassword, $this->emailConfiguration->smtpHost, $this->emailConfiguration->smtpPort)));
|
|
||||||
|
if ($this->emailConfiguration->smtpUsername) {
|
||||||
|
$this->mailer = new Mailer(Transport::fromDsn(sprintf("smtp://%s:%s@%s:%d?verify_peer=%s", $this->emailConfiguration->smtpUsername, $this->emailConfiguration->smtpPassword, $this->emailConfiguration->smtpHost, $this->emailConfiguration->smtpPort, $this->emailConfiguration->smtpVerifyPeer ? 'true' : 'false')));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->mailer = new Mailer(Transport::fromDsn(sprintf("smtp://%s:%d?verify_peer=%s", $this->emailConfiguration->smtpHost, $this->emailConfiguration->smtpPort, $this->emailConfiguration->smtpVerifyPeer ? 'true' : 'false')));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function send(string $subject, string $message, bool $html = true) : bool
|
public function send(string $subject, string $message, bool $html = true) : bool
|
||||||
{
|
{
|
||||||
$email = ( new Email() )
|
$email = ( new Email() )
|
||||||
->subject($subject)
|
->subject($subject)
|
||||||
->from($this->from)
|
->from(...$this->from())
|
||||||
->to(...( (array)$this->to ))
|
->to(...$this->to())
|
||||||
->cc(...($this->cc ?? []))
|
->cc(...$this->cc())
|
||||||
->bcc(...($this->bcc ?? []));
|
->bcc(...$this->bcc());
|
||||||
|
|
||||||
if ($html) {
|
if ($html) {
|
||||||
$email->html($message);
|
$email->html($message);
|
||||||
|
@ -38,7 +44,14 @@ class SymfonyMailer implements MailerInterface
|
||||||
|
|
||||||
$this->attachments = [];
|
$this->attachments = [];
|
||||||
|
|
||||||
return $this->mailer->send($email);
|
try {
|
||||||
|
$this->mailer->send($email);
|
||||||
|
}
|
||||||
|
catch(\Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attach(mixed $attachment) : self
|
public function attach(mixed $attachment) : self
|
||||||
|
@ -47,4 +60,35 @@ class SymfonyMailer implements MailerInterface
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function from() : array
|
||||||
|
{
|
||||||
|
return $this->arrayToAddress($this->from);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function to() : array
|
||||||
|
{
|
||||||
|
return $this->arrayToAddress($this->to);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function cc() : array
|
||||||
|
{
|
||||||
|
return $this->arrayToAddress($this->cc);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function bcc() : array
|
||||||
|
{
|
||||||
|
return $this->arrayToAddress($this->bcc);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function arrayToAddress(string|\Stringable|array $array) : array
|
||||||
|
{
|
||||||
|
$list = [];
|
||||||
|
|
||||||
|
foreach((array) $array as $addr => $name) {
|
||||||
|
$list[] = "$name <$addr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue