/** * Register the service provider. * * @return void */ public function register() { $this->registerSwiftMailer(); $this->app['mailer'] = $this->app->share(function ($app) { // Once we have create the mailer instance, we will set a container instance // on the mailer. This allows us to resolve mailer classes via containers // for maximum testability on said classes instead of passing Closures. $mailer = new Mailer($app['view'], $app['swift.mailer']); $mailer->setLogger($app['log'])->setQueue($app['queue']); $mailer->setContainer($app); // If a "from" address is set, we will set it on the mailer so that all mail // messages sent by the applications will utilize the same "from" address // on each one, which makes the developer's life a lot more convenient. $from = $app['config']['mail.from']; if (is_array($from) and isset($from['address'])) { $mailer->alwaysFrom($from['address'], $from['name']); } // Here we will determine if the mailer should be in "pretend" mode for this // environment, which will simply write out e-mail to the logs instead of // sending it over the web, which is useful for local dev enviornments. $pretend = $app['config']->get('mail.pretend', false); $mailer->pretend($pretend); return $mailer; }); }
/** * Set a few dependencies on the mailer instance. * * @param \Illuminate\Mail\Mailer $mailer * @param \Illuminate\Foundation\Application $app * @return void */ protected function setMailerDependencies($mailer, $app) { $mailer->setContainer($app); if ($app->bound('log')) { $mailer->setLogger($app['log']->getMonolog()); } if ($app->bound('queue')) { $mailer->setQueue($app['queue.connection']); } }
/** * Set a few dependencies on the mailer instance. * * @param \Illuminate\Mail\Mailer $mailer * @param \Illuminate\Foundation\Application $app * @return void */ protected function setMailerDependencies($mailer, $app) { $mailer->setContainer($app); if ($app->bound('Psr\\Log\\LoggerInterface')) { $mailer->setLogger($app->make('Psr\\Log\\LoggerInterface')); } if ($app->bound('queue')) { $mailer->setQueue($app['queue.connection']); } }
/** * Register the service provider. * * @return void */ public function register() { $this->app->singleton('mailer', function () { $view = $this->app->make('Illuminate\\Contracts\\View\\Factory'); $logger = $this->app->make('Psr\\Log\\LoggerInterface'); $swift = new \Swift_Mailer(new LogTransport($logger)); $events = $this->app->make('Illuminate\\Contracts\\Events\\Dispatcher'); $mailer = new Mailer($view, $swift, $events); $mailer->setLogger($logger); return $mailer; }); $this->app->alias('mailer', 'Illuminate\\Contracts\\Mail\\Mailer'); }
/** * Register the service provider. * * @return void */ public function register() { $this->registerSwiftMailer(); $this->app['mailer'] = $this->app->share(function ($app) { // Once we have create the mailer instance, we will set a container instance // on the mailer. This allows us to resolve mailer classes via containers // for maximum testability on said classes instead of passing Closures. $mailer = new Mailer($app['view'], $app['swift.mailer']); $mailer->setLogger($app['log'])->setQueue($app['queue']); $mailer->setContainer($app); $from = $app['config']['mail.from']; // If a "from" address is set, we will set it on the mailer so that all mail // messages sent by the applications will utilize the same "from" address // on each one, which makes the developer's life a lot more convenient. if (is_array($from) and isset($from['address'])) { $mailer->alwaysFrom($from['address'], $from['name']); } return $mailer; }); }
/** * Set the log writer instance. * * @param \Psr\Log\LoggerInterface $logger * @return $this * @static */ public static function setLogger($logger) { return \Illuminate\Mail\Mailer::setLogger($logger); }
// $transport = new MailgunTransport(getenv('MAILGUN_SECRET'), getenv('MAILGUN_DOMAIN')); // $transport = new MandrillTransport(getenv('MANDRILL_SECRET')); // $transport = new LogTransport($logger->getMonolog()); // SMTP specific configuration, remove these if you're not using SMTP $transport->setUsername(getenv('SMTP_USERNAME')); $transport->setPassword(getenv('SMTP_PASSWORD')); $transport->setEncryption(true); $swift = new SwiftMailer($transport); $finder = new FileViewFinder(new Filesystem(), ['views']); $resolver = new EngineResolver(); // determine which template engine to use $resolver->register('php', function () { return new PhpEngine(); }); $view = new Factory($resolver, $finder, new Dispatcher()); $mailer = new Mailer($view, $swift); $mailer->setLogger($logger); // $mailer->setQueue($app['queue']); // note: queue functionality is not available if the queue module is not set // $mailer->setContainer($app); // note: the message builder must be a callback if the container is not set // pretend method can be used for testing $mailer->pretend(false); // prepare email view data $data = ['greeting' => 'You have arrived, girl.']; $mailer->send('email.welcome', $data, function ($message) { $message->from(getenv('MAIL_FROM_ADDRESS'), 'Code Guy'); $message->to(getenv('MAIL_TO_ADDRESS'), 'Keira Knightley'); $message->subject('Yo!'); }); var_dump('Done'); }); $app->run();