/** * Instantiates and configures Swift Mailer. */ private function initializeMailer() { switch ($this->options['method']) { case 'smtp': $transport = \Swift_SmtpTransport::newInstance($this->options['host'], $this->options['port'], $this->options['encryption']); //->setUsername('*****@*****.**')->setPassword('pass'); break; case 'sendmail': $transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'); break; case 'exim': $transport = \Swift_SendmailTransport::newInstance('/usr/sbin/exim -bs'); break; case 'qmail': $transport = \Swift_SendmailTransport::newInstance('/usr/sbin/qmail -bs'); break; case 'postfix': $transport = \Swift_SendmailTransport::newInstance('/usr/sbin/postfix -bs'); break; case 'mail': default: $transport = \Swift_MailTransport::newInstance(); } // Create the Mailer using the created Transport $this->mailer = \Swift_Mailer::newInstance($transport); }
public function __construct($key) { parent::__construct(); $newPassword = uniqid(); $reset = \Pecee\Model\User\UserReset::confirm($key, $newPassword); if ($reset) { $user = ModelUser::getById($reset); if ($user->hasRow()) { // Send mail with new password // TODO: Move this shit to separate html template $user->setEmailConfirmed(true); $user->update(); $text = "Dear customer!\n\nWe've reset your password - you can login with your e-mail and the new password provided below:\nNew password: "******"\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team"; $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs'); $swift = \Swift_Mailer::newInstance($transport); $message = new \Swift_Message(lang('New password for NinjaImg')); $message->setFrom(env('MAIL_FROM')); $message->setSender(env('MAIL_FROM')); $message->setReplyTo(env('MAIL_FROM')); $message->setBody($text, 'text/plain'); $message->setTo($user->username); $swift->send($message); $this->setMessage('A new password has been sent to your e-mail.', 'success'); redirect(url('user.login')); } redirect(url('home')); } }
public function initialize() { require_once TD_INC . 'swift/swift_required.php'; if ($this->config['transport'] == 'smtp') { $this->transport = Swift_SmtpTransport::newInstance($this->config['smtp_host']); if ($this->config['smtp_port']) { $this->transport->setPort($this->config['smtp_port']); } if ($this->config['smtp_encryption']) { $this->transport->setEncryption($this->config['smtp_encryption']); } if ($this->config['smtp_user']) { $this->transport->setUsername($this->config['smtp_user']); } if ($this->config['smtp_pass']) { $this->transport->setPassword($this->config['smtp_pass']); } if ($this->config['smtp_timeout']) { $this->transport->setTimeout($this->config['smtp_timeout']); } } elseif ($this->config['transport'] == 'sendmail') { $this->transport = Swift_SendmailTransport::newInstance(); if ($this->config['sendmail_command']) { $this->transport->setCommand($this->config['sendmail_command']); } } elseif ($this->config['transport'] == 'mail') { $this->transport = Swift_MailTransport::newInstance(); } $this->mailer = Swift_Mailer::newInstance($this->transport); }
/** * Class constructor. * Load all data from configurations and generate the initial clases * to manage the email * * @param string Content type for message body. It usually text/plain or text/html. * Default is 'text/plain' but can be changed later */ public function __construct($content_type = 'text/plain') { $config = RMFunctions::configs(); $config_handler =& xoops_gethandler('config'); $xconfig = $config_handler->getConfigsByCat(XOOPS_CONF_MAILER); // Instantiate the Swit Transport according to our preferences // We can change this preferences later switch ($config['transport']) { case 'mail': $this->swTransport = Swift_MailTransport::newInstance(); break; case 'smtp': $this->swTransport = Swift_SmtpTransport::newInstance($config['smtp_server'], $config['smtp_port'], $config['smtp_crypt'] != 'none' ? $config['smtp_crypt'] : ''); $this->swTransport->setUsername($config['smtp_user']); $this->swTransport->setPassword($config['smtp_pass']); break; case 'sendmail': $this->swTransport = Swift_SendmailTransport::newInstance($config['sendmail_path']); break; } // Create the message object // Also this object could be change later with message() method $this->swMessage = Swift_Message::newInstance(); $this->swMessage->setReplyTo($xconfig['from']); $this->swMessage->setFrom(array($xconfig['from'] => $xconfig['fromname'])); $this->swMessage->setContentType($content_type); }
public function __construct(KConfig $config = null) { parent::__construct($config); $this->_message = Swift_Message::newInstance(); switch ($config->method) { case 'sendmail': // WIP required -bs or -t switch $transport = Swift_SendmailTransport::newInstance($config->sendmail); break; case 'smtp': if ($config->smtpauth == 1) { if ($config->smtpsecure != "none") { $transport = Swift_SmtpTransport::newInstance($config->smtphost, $config->smtpport, $config->smtpsecure)->setUsername($config->smtpuser)->setPassword($config->smtppass); } else { $transport = Swift_SmtpTransport::newInstance($config->smtphost, $config->smtpport)->setUsername($config->smtpuser)->setPassword($config->smtppass); } } else { if ($config->smtpsecure != "none") { $transport = Swift_SmtpTransport::newInstance($config->smtphost, $config->smtpport, $config->smtpsecure); } else { $transport = Swift_SmtpTransport::newInstance($config->smtphost, $config->smtpport); } } break; case 'spool': // TODO: Make spool options configurable. $transport = Swift_SpoolTransport::newInstance(new Swift_FileSpool('/var/spool/swift')); break; case 'mail': default: $transport = Swift_MailTransport::newInstance(); break; } $this->_mailer = Swift_Mailer::newInstance($transport); }
/** * @param array $to * @param string $fromEmail * @param string $fromName * @param string $subject * @param string $body * @param string $contentType * @param array $cc * @param array $bcc * @return mixed */ function send(array $to, $fromEmail, $fromName, $subject, $body, $contentType = 'text/html', $cc = [], $bcc = []) { $message = new \Swift_Message($subject, $body, $contentType); $message->setFrom($fromEmail, $fromName); foreach (['to' => 'addTo', 'cc' => 'addCc', 'bcc' => 'addBcc'] as $type => $method) { foreach (${$type} as $item) { if (is_array($item)) { $message->{$method}($item['email'], $item['name']); } else { $message->{$method}($item); } } } $mailer = new \Swift_SendmailTransport(); $mailer->send($message); }
/** * Parse the configuration file * * @param array $parsedConfig */ private function loadConfig($parsedConfig) { if (isset($parsedConfig['moduleConf']['Type']) && $parsedConfig['moduleConf']['Type'] == "smtp") { $this->transport = \Swift_SmtpTransport::newInstance(); if (isset($parsedConfig['moduleConf']['Host']) && $parsedConfig['moduleConf']['Host'] != "") { $this->transport->setHost($parsedConfig['moduleConf']['Host']); } if (isset($parsedConfig['moduleConf']['Port']) && $parsedConfig['moduleConf']['Port'] != "") { $this->transport->setPort($parsedConfig['moduleConf']['Port']); } if (isset($parsedConfig['moduleConf']['Username']) && $parsedConfig['moduleConf']['Username'] != "") { $this->transport->setUsername($parsedConfig['moduleConf']['Username']); } if (isset($parsedConfig['moduleConf']['Password']) && $parsedConfig['moduleConf']['Password'] != "") { $this->transport->setPassword($parsedConfig['moduleConf']['Password']); } if (isset($parsedConfig['moduleConf']['Encryption']) && $parsedConfig['moduleConf']['Encryption'] != "") { $this->transport->setEncryption($parsedConfig['moduleConf']['Encryption']); } } elseif (isset($parsedConfig['moduleConf']['Type']) && $parsedConfig['moduleConf']['Type'] == "sendmail") { $this->transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'); } else { $this->transport = \Swift_MailTransport::newInstance(); } }
public function executeEmailExpirationNotice(sfWebRequest $request) { $notices = $request->getParameter('expired'); $mail_count = 0; // prepare swift mailer require_once sfConfig::get('sf_lib_dir') . '/vendor/swift/swift_required.php'; # needed due to symfony autoloader $mailer = Swift_Mailer::newInstance(Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -t')); foreach ($notices as $emp_id => $notices) { $employee = EmployeePeer::retrieveByPK($emp_id); if ($employee) { foreach ($notices as $notice => $expired) { // queue an email of type $notice with this $employee's info switch ($notice) { case 'tb_date': $type = 'Tb'; break; case 'physical_date': $type = 'Physical'; break; } $mailBody = $this->getPartial('employee/emailExpired' . $type, array('name' => $employee->getFullname(), 'expiration' => $expired)); $to_address = $employee->getCompanyEmail() ? $employee->getCompanyEmail() : $employee->getPersonalEmail(); $message = Swift_Message::newInstance('Expired ' . $type . ' Notice')->setFrom(array('*****@*****.**' => 'North Country Kids, Inc.'))->setTo(array($to_address, '*****@*****.**'))->setBody($mailBody, 'text/html'); // queue it up $mailer->send($message); $mail_count++; } } } return $this->renderText($mail_count . ' messages have been sent.'); }
/** * Define the transport method * @param object $okt */ protected function setTransport() { switch ($this->okt->config->email['transport']) { default: case 'mail': $this->transport = Swift_MailTransport::newInstance(); break; case 'smtp': $this->transport = Swift_SmtpTransport::newInstance($this->okt->config->email['smtp']['host'], $this->okt->config->email['smtp']['port']); if (!empty($this->okt->config->email['smtp']['username'])) { $this->transport->setUsername($this->okt->config->email['smtp']['username']); } if (!empty($this->okt->config->courriel['smtp']['password'])) { $this->transport->setPassword($this->okt->config->email['smtp']['password']); } break; case 'sendmail': $command = '/usr/sbin/exim -bs'; if (!empty($this->okt->config->email['sendmail'])) { $command = $this->okt->config->email['sendmail']; } $this->transport = Swift_SendmailTransport::newInstance($command); break; } }
protected function getMailer() { if (empty($this->mailer)) { require_once PATH_SYSTEM . "/vendors/Swift-4.0.4/lib/swift_required.php"; switch ($this->emailMode) { case 'smtp': //Create the Transport $transport = Swift_SmtpTransport::newInstance($this->emailConfig['host'], $this->emailConfig['port']); if (!empty($this->emailConfig['user'])) { $transport->setUsername($this->emailConfig['user']); } if (!empty($this->emailConfig['password'])) { $transport->setPassword($this->emailConfig['password']); } if (!empty($this->emailConfig['timeout'])) { $transport->setTimeout($this->emailConfig['timeout']); } if (!empty($this->emailConfig['encryption'])) { $transport->setEncryption($this->emailConfig['encryption']); } $this->mailer = Swift_Mailer::newInstance($transport); break; case 'sendmail': $transport = Swift_SendmailTransport::newInstance(!empty($this->emailConfig['pathToSendmail']) ? $this->emailConfig['pathToSendmail'] : '/usr/sbin/sendmail -bs'); $this->mailer = Swift_Mailer::newInstance($transport); break; default: case 'mail': $transport = Swift_MailTransport::newInstance(); $this->mailer = Swift_Mailer::newInstance($transport); break; } } return $this->mailer; }
/** * Base constructor. * In the base constructor the bridge gets the mailer configuration. * * @param ConfigObject $config The base configuration. * * @throws SwiftMailerException */ public function __construct($config) { $this->config = $config; $transportType = strtolower($config->get('Transport.Type', 'mail')); $disableDelivery = $config->get('DisableDelivery', false); if ($disableDelivery) { $transportType = 'null'; } // create Transport instance switch ($transportType) { case 'smtp': $transport = \Swift_SmtpTransport::newInstance($config->get('Transport.Host', 'localhost'), $config->get('Transport.Port', 25), $config->get('Transport.AuthMode', null)); $transport->setUsername($config->get('Transport.Username', '')); $transport->setPassword($config->get('Transport.Password', '')); $transport->setEncryption($config->get('Transport.Encryption', null)); break; case 'mail': $transport = \Swift_MailTransport::newInstance(); break; case 'sendmail': $transport = \Swift_SendmailTransport::newInstance($config->get('Transport.Command', '/usr/sbin/sendmail -bs')); break; case 'null': $transport = \Swift_NullTransport::newInstance(); break; default: throw new SwiftMailerException('Invalid transport.type provided. Supported types are [smtp, mail, sendmail, null].'); break; } // create Mailer instance $this->mailer = \Swift_Mailer::newInstance($transport); // register plugins $this->registerPlugins($config); }
function __construct() { // include swift mailer require ENGINE_PATH . 'swiftmailer/classes/Swift.php'; Swift::init(); Swift::registerAutoload(); //Yii::import('system.vendors.swiftMailer.classes.Swift', true); //Yii::registerAutoloader(array('Swift','autoload')); require_once ENGINE_PATH . 'swiftmailer/swift_init.php'; //Yii::import('system.vendors.swiftMailer.swift_init', true); switch ($this->params['transportType']) { case 'smtp': $transport = Swift_SmtpTransport::newInstance($this->params['smtpServer'], $this->params['smtpPort'], $this->params['smtpSequre'])->setUsername($this->params['smtpUsername'])->setPassword($this->params['smtpPassword']); break; case 'sendmail': $transport = Swift_SendmailTransport::newInstance($this->params['sendmailCommand']); break; default: case 'mail': $transport = Swift_MailTransport::newInstance(); break; } $this->toEmail = 'noreplay@' . $_SERVER['HTTP_HOST']; $this->fromEmail = 'noreplay@' . $_SERVER['HTTP_HOST']; $this->path = "http://" . $_SERVER['HTTP_HOST'] . "/submit/mailtpl/"; $this->mailer = Swift_Mailer::newInstance($transport); $this->mes = Swift_Message::newInstance(); }
static function send($title, $body, $to_array, $attachment = null, $log = true) { $model = Config::find()->one(); // Create the message $message = \Swift_Message::newInstance()->setSubject($title)->setFrom(array($model->from_email => $model->from_name))->setTo($to_array)->setBody($body); // Optionally add any attachments if ($attachment) { if (is_array($attachment)) { foreach ($attachment as $file) { $message = $message->attach(Swift_Attachment::fromPath($file)); } } else { $message = $message->attach(Swift_Attachment::fromPath($attachment)); } } // Create the Transport switch ($model->type) { case 1: $transport = \Swift_SmtpTransport::newInstance($model->smtp, $model->port > 0 ?: 25)->setUsername($model->from_email)->setPassword($model->pass); break; case 2: $transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'); break; case 3: $transport = \Swift_MailTransport::newInstance(); break; } $mailer = \Swift_Mailer::newInstance($transport); $result = $mailer->send($message); //log send mail if (true === $log) { static::log($to_array, $title, $body, $attachment); } }
public function getTransport() { // Get Joomla mailer $config = JFactory::getConfig(); $jmailer = $config->get('mailer'); switch ($jmailer) { case 'sendmail': $this->transport = Swift_SendmailTransport::newInstance($config->get('sendmail') . ' -bs'); break; case 'smtp': $this->transport = Swift_SmtpTransport::newInstance($config->get('smtphost'), $config->get('smtpport')); if ($config->get('smtpauth') == 1) { $smtpUser = $config->get('smtpuser'); $smtpPass = $config->get('smtppass'); if (!empty($smtpUser) && !empty($smtpPass)) { $this->transport->setUsername($smtpUser)->setPassword($smtpPass); } $smtpEncryption = $config->get('smtpsecure'); if (!empty($smtpEncryption)) { $this->transport->setEncryption($smtpEncryption); } } break; default: case 'mail': $this->transport = Swift_MailTransport::newInstance(); break; } }
/** * Creates a SwiftMailer instance. * * @param string DSN connection string * @return object Swift object */ public static function connect($config = NULL) { // Load default configuration $config === NULL and $config = Kohana::$config->load('email'); switch ($config['driver']) { case 'smtp': // Set port $port = empty($config['options']['port']) ? 25 : (int) $config['options']['port']; // Create SMTP Transport $transport = Swift_SmtpTransport::newInstance($config['options']['hostname'], $port); if (!empty($config['options']['encryption'])) { // Set encryption $transport->setEncryption($config['options']['encryption']); } // Do authentication, if part of the DSN empty($config['options']['username']) or $transport->setUsername($config['options']['username']); empty($config['options']['password']) or $transport->setPassword($config['options']['password']); // Set the timeout to 5 seconds $transport->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']); break; case 'sendmail': // Create a sendmail connection $transport = Swift_SendmailTransport::newInstance(empty($config['options']) ? "/usr/sbin/sendmail -bs" : $config['options']); break; default: // Use the native connection $transport = Swift_MailTransport::newInstance(); break; } // Create the SwiftMailer instance return self::$_mail = Swift_Mailer::newInstance($transport); }
public function __construct() { parent::__construct(); $this->prependSiteTitle(lang('Recover log in')); if ($this->isPostBack()) { $this->post->email->addValidation(new ValidateInputNotNullOrEmpty()); if (!$this->hasErrors()) { $user = ModelUser::getByUsername($this->input('email')); if (!$user->hasRow()) { $this->setMessage('No user found', 'warning'); response()->refresh(); } if (!$this->hasErrors()) { $reset = new UserReset($user->id); $reset->save(); // TODO: Move this shit to seperate html template $text = "Dear customer!\n\nYou are receiving this mail, because you (or someone else) has requested a password reset for your user on NinjaImg.com.\n\nTo continue with the password reset, please click the link below to confirm the reset:\n\n" . sprintf('https://%s/reset/%s', $_SERVER['HTTP_HOST'], $reset->key) . "\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team"; $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs'); $swift = \Swift_Mailer::newInstance($transport); $message = new \Swift_Message(lang('Confirm password reset on NinjaImg')); $message->setFrom(env('MAIL_FROM')); $message->setSender(env('MAIL_FROM')); $message->setReplyTo(env('MAIL_FROM')); $message->setBody($text, 'text/plain'); $message->setTo($user->username); $swift->send($message); $this->setMessage('A password reset link has been sent to your e-mail', 'success'); // Send mail to user confirming reset... // Maybe show message with text that are active even when session disappear response()->refresh(); } } } }
/** * Sets up the Aimeos environemnt * * @param string $extdir Absolute or relative path to the Aimeos extension directory * @return \Aimeos\Slim\Bootstrap Self instance */ public function setup($extdir = '../ext') { $container = $this->app->getContainer(); $container['router'] = function ($c) { return new \Aimeos\Slim\Router(); }; $container['mailer'] = function ($c) { return \Swift_Mailer::newInstance(\Swift_SendmailTransport::newInstance()); }; $default = (require __DIR__ . DIRECTORY_SEPARATOR . 'aimeos-default.php'); $settings = array_replace_recursive($default, $this->settings); $container['aimeos'] = function ($c) use($extdir) { return new \Aimeos\Bootstrap((array) $extdir, false); }; $container['aimeos_config'] = function ($c) use($settings) { return new \Aimeos\Slim\Base\Config($c, $settings); }; $container['aimeos_context'] = function ($c) { return new \Aimeos\Slim\Base\Context($c); }; $container['aimeos_i18n'] = function ($c) { return new \Aimeos\Slim\Base\I18n($c); }; $container['aimeos_locale'] = function ($c) { return new \Aimeos\Slim\Base\Locale($c); }; $container['aimeos_page'] = function ($c) { return new \Aimeos\Slim\Base\Page($c); }; $container['aimeos_view'] = function ($c) { return new \Aimeos\Slim\Base\View($c); }; return $this; }
public function testGetSendMailInstanceSendMailQmail() { $this->config ->expects($this->once()) ->method('getSystemValue') ->with('mail_smtpmode', 'sendmail') ->will($this->returnValue('qmail')); $this->assertEquals(\Swift_SendmailTransport::newInstance('/var/qmail/bin/sendmail -bs'), self::invokePrivate($this->mailer, 'getSendMailInstance')); }
/** * @param string $transport_name the transport name */ protected function initTransport($transport_name) { if ('sendmail' == $transport_name) { $transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'); } else { $config = $this->transports_config[$transport_name]; $transport = \Swift_SmtpTransport::newInstance($config['hostname'], $config['port'], $config['security'])->setUsername($config['username'])->setPassword($config['password']); } $this->transports[$transport_name] = \Swift_Mailer::newInstance($transport); }
/** * Creates a SwiftMailer instance. * * @param string DSN connection string * @return object Swift object */ public static function connect($config = NULL) { if (!class_exists('Swift', FALSE)) { // Load SwiftMailer require_once Kohana::find_file('vendor', 'swiftmailer/swift_required'); } // Load default configuration $config === NULL and $config = Kohana::config('email'); switch ($config['driver']) { case 'smtp': // Set port $port = empty($config['options']['port']) ? NULL : (int) $config['options']['port']; // Create a SMTP connection $connection = Swift_SmtpTransport::newInstance($config['options']['hostname'], $port); if (!empty($config['options']['encryption'])) { // Set encryption switch (strtolower($config['options']['encryption'])) { case 'tls': case 'ssl': $connection->setEncryption($config['options']['encryption']); break; } } // Do authentication, if part of the DSN empty($config['options']['username']) or $connection->setUsername($config['options']['username']); empty($config['options']['password']) or $connection->setPassword($config['options']['password']); if (!empty($config['options']['auth'])) { // Get the class name and params list($class, $params) = arr::callback_string($config['options']['auth']); if ($class === 'PopB4Smtp') { // Load the PopB4Smtp class manually, due to its odd filename require Kohana::find_file('vendor', 'swift/Swift/Authenticator/$PopB4Smtp$'); } // Prepare the class name for auto-loading $class = 'Swift_Authenticator_' . $class; // Attach the authenticator $connection->attachAuthenticator($params === NULL ? new $class() : new $class($params[0])); } // Set the timeout to 5 seconds $connection->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']); break; case 'sendmail': // Create a sendmail connection $connection = Swift_SendmailTransport::newInstance($config['options']); break; default: // Use the native connection $connection = Swift_MailTransport::newInstance(); break; } // Create the SwiftMailer instance return email::$mail = Swift_Mailer::newInstance($connection); }
function sendMail($mail, $subject, $text) { $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs'); $swift = \Swift_Mailer::newInstance($transport); $message = new \Swift_Message($subject); $message->setFrom(env('MAIL_FROM')); $message->setSender(env('MAIL_FROM')); $message->setReplyTo(env('MAIL_FROM')); $message->setBody($text, 'text/plain'); $message->addTo($mail); $swift->send($message); }
/** * Mailer::sendMail() * * Sends a various messages to users * @return */ public static function sendMail() { require_once BASEPATH . 'lib/swift/swift_required.php'; if (Registry::get("Core")->mailer == "SMTP") { $SSL = Registry::get("Core")->is_ssl ? 'ssl' : null; $transport = Swift_SmtpTransport::newInstance(Registry::get("Core")->smtp_host, Registry::get("Core")->smtp_port, $SSL)->setUsername(Registry::get("Core")->smtp_user)->setPassword(Registry::get("Core")->smtp_pass); } elseif (Registry::get("Core")->mailer == "SMAIL") { $transport = Swift_SendmailTransport::newInstance(Registry::get("Core")->sendmail); } else { $transport = Swift_MailTransport::newInstance(); } return Swift_Mailer::newInstance($transport); }
public function testGetBackend() { $settings = (require dirname(dirname(__DIR__)) . '/src/aimeos-default.php'); $settings['disableSites'] = false; $container = new \Slim\Container(); $container['aimeos'] = new \Aimeos\Bootstrap(); $container['aimeos_context'] = new \Aimeos\Slim\Base\Context($container); $container['aimeos_config'] = new \Aimeos\Slim\Base\Config($container, $settings); $container['mailer'] = \Swift_Mailer::newInstance(\Swift_SendmailTransport::newInstance()); $context = $container['aimeos_context']->get(false, array(), 'backend'); $object = new \Aimeos\Slim\Base\Locale($container); $this->assertInstanceOf('\\Aimeos\\MShop\\Locale\\Item\\Iface', $object->getBackend($context, 'unittest')); }
/** * Creates a SwiftMailer instance. * * @param string DSN connection string * @return object Swift object */ public static function mailer() { if (Email::$_mailer) { return Email::$_mailer; } // Load default configuration $config = Kohana::$config->load('html-email')->as_array(); switch ($config['driver']) { case 'smtp': $transport = Swift_SmtpTransport::newInstance(Arr::path($config, 'options.hostname', 'localhost'), Arr::path($config, 'options.port', 25), Arr::path($config, 'options.encryption')); $transport->setTimeout(Arr::path($config, 'options.timeout', 5)); $user = Arr::path($config, 'options.username'); $pass = Arr::path($config, 'options.password'); if ($user and $pass) { $transport->setUsername($user); $transport->setPassword($pass); } break; case 'sendmail': $transport = Swift_SendmailTransport::newInstance(Arr::get($config, 'options', '/usr/sbin/sendmail -bs')); break; case 'postmark': $transport = Openbuildings\Postmark\Swift_PostmarkTransport::newInstance(Arr::get($config, 'options')); break; case 'null': $transport = Swift_NullTransport::newInstance(); break; default: // Use the native connection $transport = Swift_MailTransport::newInstance(); break; } // Create the SwiftMailer instance self::$_mailer = Swift_Mailer::newInstance($transport); if (Arr::get($config, 'inline_css')) { self::$_mailer->registerPLugin(new Openbuildings\Swiftmailer\CssInlinerPlugin()); } if ($filter = Arr::get($config, 'filter')) { self::$_mailer->registerPlugin(new Openbuildings\Swiftmailer\FilterPlugin(Arr::get($filter, 'whitelist', array()), Arr::get($filter, 'blacklist', array()))); } if ($google_campaign = Arr::path($config, 'google_campaign.campaigns')) { self::$_mailer->registerPlugin(new Openbuildings\Swiftmailer\GoogleCampaignPlugin(array(), array('share' => $google_campaign['share'], 'abandoned_cart' => $google_campaign['abandoned_cart']))); } if ($logger = Arr::get($config, "logger")) { if ($logger === TRUE) { self::$_mailer->registerPlugin(new Swift_Plugins_Fullloggerplugin(new Email_Logger())); } else { self::$_mailer->registerPlugin(new $logger(new Email_Logger())); } } }
public function register(Application $app) { $app->setParameter('swiftmailer', ['initialized' => false, 'use_spool' => true, 'options' => []]); $app->singleton('mailer', function () use($app) { $app->setParameter('swiftmailer.initialized', true); /** @var \Swift_Transport $transport */ $transport = $app->getParameter('swiftmailer.use_spool') ? $app->make('swiftmailer.transport_spool') : $app->make('swiftmailer.transport'); $mailer = new \Swift_Mailer($transport); if ($address = $app->getParameter('swiftmailer.options.delivery_address')) { $mailer->registerPlugin(new \Swift_Plugins_RedirectingPlugin($address)); } return $mailer; }); $app->singleton('swiftmailer.transport', function () use($app) { $options = array_merge(['transport' => 'smtp', 'host' => 'localhost', 'port' => false, 'timeout' => 30, 'encryption' => null, 'username' => null, 'password' => null, 'delivery_address' => null], $app->getParameter('swiftmailer.options', [])); switch ($options['transport']) { case 'gmail': case 'smtp': if ($options['transport'] == 'gmail') { $options['encryption'] = 'ssl'; $options['host'] = 'smtp.gmail.com'; } if (false === $options['port']) { $options['port'] = 'ssl' === $options['encryption'] ? 465 : 25; } $transport = \Swift_SmtpTransport::newInstance($options['host'], $options['port'], $options['encryption']); $transport->setUsername($options['username']); $transport->setPassword($options['password']); $transport->setTimeout($options['timeout']); return $transport; case 'sendmail': return \Swift_SendmailTransport::newInstance(); case 'mail': return \Swift_MailTransport::newInstance(); case 'null': return \Swift_NullTransport::newInstance(); } }); $app->singleton('swiftmailer.transport_spool', function () use($app) { $type = $app->getParameter('swiftmailer.options.spool_type', 'memory'); if ($type == 'memory') { $spool = new \Swift_MemorySpool(); } elseif ($type == 'file') { $spool = new \Swift_FileSpool($app->getParameter('swiftmailer.options.spool_path')); } else { throw new \LogicException(sprintf('Spool type "%s" not found', $type)); } return new \Swift_SpoolTransport($spool); }); }
/** * Creates a SwiftMailer instance. * * @return object Swift object */ public static function mailer() { if (!Email::$_mailer) { // Load email configuration, make sure minimum defaults are set $config = Kohana::$config->load('email')->as_array() + array('driver' => 'native', 'options' => array()); // Extract configured options extract($config, EXTR_SKIP); if ($driver === 'smtp') { // Create SMTP transport $transport = Swift_SmtpTransport::newInstance($options['hostname']); if (isset($options['port'])) { // Set custom port number $transport->setPort($options['port']); } if (isset($options['encryption'])) { // Set encryption $transport->setEncryption($options['encryption']); } if (isset($options['username'])) { // Require authentication, username $transport->setUsername($options['username']); } if (isset($options['password'])) { // Require authentication, password $transport->setPassword($options['password']); } if (isset($options['timeout'])) { // Use custom timeout setting $transport->setTimeout($options['timeout']); } } elseif ($driver === 'sendmail') { // Create sendmail transport $transport = Swift_SendmailTransport::newInstance(); if (isset($options['command'])) { // Use custom sendmail command $transport->setCommand($options['command']); } } else { // Create native transport $transport = Swift_MailTransport::newInstance(); if (isset($options['params'])) { // Set extra parameters for mail() $transport->setExtraParams($options['params']); } } // Create the SwiftMailer instance Email::$_mailer = Swift_Mailer::newInstance($transport); } return Email::$_mailer; }
protected static function getTransport() { $config = Config::get("mail"); if (empty($config->driver) || $config->driver == 'mail') { $transport = \Swift_MailTransport::newInstance(); } elseif ($config->driver == 'sendmail') { $transport = Swift_SendmailTransport::newInstance($config->sendmail); } elseif ($config->driver == 'smtp') { $transport = \Swift_SmtpTransport::newInstance()->setHost($config->host)->setPort($config->port)->setEncryption($config->encryption)->setUsername($config->username)->setPassword($config->password); } else { throw new \RuntimeException("Invalid transport."); } return $transport; }
static function sendEmail($email) { $mailType = config_item('email_method'); if ($mailType == 'smtp') { $transport = \Swift_SmtpTransport::newInstance(config_item('smtp_server'), config_item('smtp_port'))->setUsername(config_item('smtp_username'))->setPassword(config_item('smtp_password')); } elseif ($mailType == 'sendmail') { $transport = \Swift_SendmailTransport::newInstance(config_item('sendmail_path')); } else { $transport = \Swift_MailTransport::newInstance(); } //get the mailer $mailer = \Swift_Mailer::newInstance($transport); //send the message $mailer->send($email); }
public function Send($pFrom, $pFromName, $pTo, $pToName, $pSubject, $pBody, $pType = "text/html") { // create the mail transport using the 'newInstance()' method $transport = Swift_SendmailTransport::newInstance(); // create the mailer using the 'newInstance()' method $mailer = Swift_Mailer::newInstance($transport); // create a simple message using the 'newInstance()' method $message = Swift_Message::newInstance()->setSubject($pSubject)->setFrom(array($pFrom => $pFromName))->setTo(array($pTo => $pToName))->setBody($pBody)->setContentType("text/html"); // send the email message if ($mailer->send($message)) { return true; } else { return false; } }
/** * @param array $config * * @return \Swift_Mailer */ private function getCurrentMailer(array $config) { if ($this->mailer !== null) { return $this->mailer; } if ($config['mailer'] == 'smtp') { $transport = \Swift_SmtpTransport::newInstance($config['smtpHost'], $config['smtpPort'], $config['smtpSecurity']); $transport->setUsername($config['smtpUsername']); $transport->setPassword($config['smtpPassword']); } elseif ($config['mailer'] == 'mail') { $transport = \Swift_MailTransport::newInstance(); } else { $transport = \Swift_SendmailTransport::newInstance(); } return \Swift_Mailer::newInstance($transport); }