transport = $mailjetTransport; $this->templating = $templating; $this->parameterBag = $parameterBag; $this->settingSolver = $settingSolver; $this->siteStore = $siteStore; } public function send($params = []) { $siteDefault = $this->siteStore->getOneDefault(); $emailSubjectPrefix = (isset($params[self::SUBJECT_PREFIX]) && $params[self::SUBJECT_PREFIX] && strlen($params[self::SUBJECT_PREFIX]) > 0) ? $params[self::SUBJECT_PREFIX] : $this->settingSolver->getSettingValue( $siteDefault, SiteSettingDefinition::SETTING_EMAIL_SUBJECT_PREFIX ); $emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen($params[self::FROM_EMAIL]) > 0) ? $params[self::FROM_EMAIL] : $this->settingSolver->getSettingValue( $siteDefault, SiteSettingDefinition::SETTING_EMAIL_FROM ); $emailFromName = (isset($params[self::FROM_NAME]) && $params[self::FROM_NAME] && strlen($params[self::FROM_NAME]) > 0) ? $params[self::FROM_NAME] : $this->settingSolver->getSettingValue( $siteDefault, SiteSettingDefinition::SETTING_EMAIL_FROM_NAME ); $message = new \Swift_Message($emailSubjectPrefix . $params[self::SUBJECT]); if ($this->parameterBag->get('mailjet.dev.redirect.active') == 1) { $message->addTo( $this->parameterBag->get('mailjet.dev.redirect.email'), isset($params[self::TO_NAME]) ?? null ); } else { $message->addTo( $params[self::TO_EMAIL], isset($params[self::TO_NAME]) ?? null ); } $contentData = []; if (isset($params[self::CONTENT_DATA])) { $contentData = $params[self::CONTENT_DATA]; } $message->addFrom($emailFrom, $emailFromName) ->setBody( $this->templating->render($params[self::CONTENT_TEMPLATE] . '-html.html.twig', $contentData), 'text/html' ) ->addPart($this->templating->render($params[self::CONTENT_TEMPLATE] . '-text.html.twig', $contentData)); if (isset($params[self::COPY_TO]) && strlen($params[self::COPY_TO])) { $message->addCc($params[self::COPY_TO]); } if (isset($params[self::COPY_HIDDEN_TO]) && strlen($params[self::COPY_HIDDEN_TO])) { $message->addBcc($params[self::COPY_HIDDEN_TO]); } if (isset($params[self::REPLY_TO]) && strlen($params[self::REPLY_TO])) { $message->addReplyTo($params[self::REPLY_TO]); } if (isset($params[self::ATTACHMENT_DATA]) && isset($params[self::ATTACHMENT_FILENAME]) && isset($params[self::ATTACHMENT_CONTENT_TYPE])) { $message->attach( \Swift_Attachment::newInstance( $params[self::ATTACHMENT_DATA], $params[self::ATTACHMENT_FILENAME], $params[self::ATTACHMENT_CONTENT_TYPE] ) ); } // Classique (SMTP) /*$transport = (new \Swift_SmtpTransport('smtp-placedulocal.alwaysdata.net', 587, 'tls')) ->setUsername('contact@placedulocal.fr') ->setPassword('7sgd5x2BVStJ69'); $mailer = new \Swift_Mailer($transport); return $mailer->send($message);*/ // Mailjet return $this->transport->send($message); } }