public function getServiceConfig() { return array('factories' => array("Mail" => function ($sm) { $mail = new Mail(); $mail->setRenderer($sm->get("ViewRenderer")); /** * @var $sm \Zend\ServiceManager\ServiceLocatorInterface */ $config = $sm->get("config"); $env = $config["env"]["type"]; $transporterConfig = $config["WasabiMail"]["transporter"]; $transporter = null; //Production if ($env == "production") { $transporter = new Sendmail(); } elseif ($env == "develop") { $mailConfig = $transporterConfig["develop"]; $mail->setTo($mailConfig["to"]); $transporter = new \Zend\Mail\Transport\Smtp(); $options = new \Zend\Mail\Transport\SmtpOptions(); $options->setName($mailConfig["name"]); $options->setHost($mailConfig["host"]); $options->setPort($mailConfig["port"]); if (isset($mailConfig['connection_class'])) { $options->setConnectionClass($mailConfig['connection_class']); } if (isset($mailConfig['connection_config'])) { $options->{$mailConfig}['connection_config']; } $transporter->setOptions($options); } elseif ($env == "local") { $fileConfig = $transporterConfig["local"]; $options = new \Zend\Mail\Transport\FileOptions(); $options->setPath($fileConfig["base"] . $fileConfig["target"]); $options->setCallback(function (\Zend\Mail\Transport\File $transport) { return "Message_" . microtime(true) . "-" . mt_rand(0, 100) . ".txt"; }); $transporter = new \Zend\Mail\Transport\File($options); } $mail->setTransporter($transporter); return $mail; })); }