Skip to content

Commit 022da3a

Browse files
authored
Merge pull request #6 from ntidev/add-user-loggued
Fix from in array and adding user logged for send email
2 parents 033b8e0 + 6d6c4a4 commit 022da3a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Service/Mailer.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public function __construct(ContainerInterface $container, EngineInterface $temp
5555
* @param array $attachments
5656
* @return bool
5757
*/
58-
public function sendFromTemplate($from, $to, $cc, $bcc, $subject, $template, $parameters = array(), $attachments = array()) {
58+
public function sendFromTemplate($from, $to, $cc, $bcc, $subject, $template, $parameters = array(), $attachments = array(), $smtp = null) {
5959
$html = $this->templating->render($template, $parameters);
60-
return $this->sendEmail($from, $to, $cc, $bcc, $subject, $html, $attachments);
60+
return $this->sendEmail($from, $to, $cc, $bcc, $subject, $html, $attachments, $smtp);
6161
}
6262

6363
/**
@@ -72,8 +72,8 @@ public function sendFromTemplate($from, $to, $cc, $bcc, $subject, $template, $pa
7272
* @param array $attachments
7373
* @return bool
7474
*/
75-
public function sendEmail($from, $to, $cc, $bcc, $subject, $html, $attachments = array()) {
76-
return $this->processEmail($from, $to, $cc, $bcc, $subject, $html, $attachments);
75+
public function sendEmail($from, $to, $cc, $bcc, $subject, $html, $attachments = array(), $smtp = null) {
76+
return $this->processEmail($from, $to, $cc, $bcc, $subject, $html, $attachments, $smtp);
7777
}
7878

7979
/**
@@ -295,7 +295,7 @@ private function embedBase64Images(\Swift_Message $message, $body)
295295
* @param array $attachments
296296
* @return bool
297297
*/
298-
private function processEmail($from, $to, $cc = array(), $bcc = array(), $subject, $html = "", $attachments = array()) {
298+
private function processEmail($from, $to, $cc = array(), $bcc = array(), $subject, $html = "", $attachments = array(), $smtp = null) {
299299

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

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

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

0 commit comments

Comments
 (0)