Skip to content

Commit

Permalink
Merge pull request #6 from ntidev/add-user-loggued
Browse files Browse the repository at this point in the history
Fix from in array and adding user logged for send email
  • Loading branch information
bvisonl authored Sep 6, 2019
2 parents 033b8e0 + 6d6c4a4 commit 022da3a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Service/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public function __construct(ContainerInterface $container, EngineInterface $temp
* @param array $attachments
* @return bool
*/
public function sendFromTemplate($from, $to, $cc, $bcc, $subject, $template, $parameters = array(), $attachments = array()) {
public function sendFromTemplate($from, $to, $cc, $bcc, $subject, $template, $parameters = array(), $attachments = array(), $smtp = null) {
$html = $this->templating->render($template, $parameters);
return $this->sendEmail($from, $to, $cc, $bcc, $subject, $html, $attachments);
return $this->sendEmail($from, $to, $cc, $bcc, $subject, $html, $attachments, $smtp);
}

/**
Expand All @@ -72,8 +72,8 @@ public function sendFromTemplate($from, $to, $cc, $bcc, $subject, $template, $pa
* @param array $attachments
* @return bool
*/
public function sendEmail($from, $to, $cc, $bcc, $subject, $html, $attachments = array()) {
return $this->processEmail($from, $to, $cc, $bcc, $subject, $html, $attachments);
public function sendEmail($from, $to, $cc, $bcc, $subject, $html, $attachments = array(), $smtp = null) {
return $this->processEmail($from, $to, $cc, $bcc, $subject, $html, $attachments, $smtp);
}

/**
Expand Down Expand Up @@ -295,7 +295,7 @@ private function embedBase64Images(\Swift_Message $message, $body)
* @param array $attachments
* @return bool
*/
private function processEmail($from, $to, $cc = array(), $bcc = array(), $subject, $html = "", $attachments = array()) {
private function processEmail($from, $to, $cc = array(), $bcc = array(), $subject, $html = "", $attachments = array(), $smtp = null) {

if($this->devMode) {
$to = $this->devTo;
Expand Down Expand Up @@ -364,8 +364,10 @@ private function processEmail($from, $to, $cc = array(), $bcc = array(), $subjec
$em = $this->container->get('doctrine')->getManager();

/** @var Smtp $smtp */
$uniqueId = (is_array($from) && count($from) > 0) ? $from[0] : $from;
$smtp = $em->getRepository(Smtp::class)->findOneBy(array("uniqueId" => strtolower($uniqueId)));
$uniqueId = (is_array($from) && count($from) > 0) ? key($from) : $from;
if(!$smtp) {
$smtp = $em->getRepository(Smtp::class)->findOneBy(array("uniqueId" => strtolower($uniqueId)));
}

if (!$smtp) {
$this->container->get('logger')->log(\Monolog\Logger::WARNING, "Unable to find an SMTP configuration with the UniqueID of {$from}");
Expand Down

0 comments on commit 022da3a

Please sign in to comment.