init() public static method

This enables you to tweak the default configuration in a lazy way.
public static init ( mixed $callable )
$callable mixed A valid PHP callable that will be called when autoloading the first Swift class
Example #1
0
 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();
 }
Example #2
0
 /**
  * Constructor.
  */
 public function __construct($options)
 {
     // assign "email" subarray
     $this->options = $options['email'];
     \Swift::init('Koch\\Mail\\SwiftMailer::swiftmailerLazyConfiguration');
     $this->initializeMailer();
 }
Example #3
0
 /**
  * Swift初期化
  *
  * @param String $host
  * @param String $port
  * @param String $user
  * @param String $pass
  * @param String $charset
  * @return vold
  * @codeCoverageIgnore
  */
 public function __construct($host, $port, $user, $pass, $charset = 'iso-2022-jp')
 {
     $this->host = $host;
     $this->port = $port;
     $this->user = $user;
     $this->pass = $pass;
     $this->charset = $charset;
     $this->setPath();
     \Swift::init(function () use($charset) {
         \Swift_DependencyContainer::getInstance()->register('mime.qpheaderencoder')->asAliasOf('mime.base64headerencoder');
         \Swift_Preferences::getInstance()->setCharset($charset);
     });
 }
Example #4
0
 public function initMailer()
 {
     // メール送信時の文字エンコード指定(デフォルトはUTF-8)
     if (isset($this['config']['mail']['charset_iso_2022_jp']) && is_bool($this['config']['mail']['charset_iso_2022_jp'])) {
         if ($this['config']['mail']['charset_iso_2022_jp'] === true) {
             \Swift::init(function () {
                 \Swift_DependencyContainer::getInstance()->register('mime.qpheaderencoder')->asAliasOf('mime.base64headerencoder');
                 \Swift_Preferences::getInstance()->setCharset('iso-2022-jp');
             });
         }
     }
     $this->register(new \Silex\Provider\SwiftmailerServiceProvider());
     $this['swiftmailer.options'] = $this['config']['mail'];
     if (isset($this['config']['mail']['spool']) && is_bool($this['config']['mail']['spool'])) {
         $this['swiftmailer.use_spool'] = $this['config']['mail']['spool'];
     }
     // デフォルトはsmtpを使用
     $transport = $this['config']['mail']['transport'];
     if ($transport == 'sendmail') {
         $this['swiftmailer.transport'] = \Swift_SendmailTransport::newInstance();
     } elseif ($transport == 'mail') {
         $this['swiftmailer.transport'] = \Swift_MailTransport::newInstance();
     }
 }
Example #5
0
    {
        // Get a copy of the current message
        $message = clone $this->_message;
        // Load the mailer instance
        $mailer = Email::mailer();
        // Count the total number of messages sent
        $total = 0;
        foreach ($to as $email => $name) {
            if (ctype_digit((string) $email)) {
                // Only an email address was provided
                $email = $name;
                $name = NULL;
            }
            // Set the To addre
            $message->setTo($email, $name);
            // Send this email
            $total += $mailer->send($message, $failed);
        }
        return $total;
    }
}
// End email
// Load Swiftmailer
require Kohana::find_file('vendor/swiftmailer', 'lib/swift_required');
function swiftmailer_configurator()
{
    // Set the default character set for everything
    Swift_Preferences::getInstance()->setCharset(Kohana::$charset);
}
Swift::init('swiftmailer_configurator');
Example #6
0
    ClassLoader::scanAndRegister();
} catch (UnresolvableDependenciesException $e) {
    die($e->getMessage());
    // see #6343
}
/**
 * Include the Composer autoloader
 */
require_once TL_ROOT . '/vendor/autoload.php';
/**
 * Override some SwiftMailer defaults
 */
Swift::init(function () {
    $preferences = Swift_Preferences::getInstance();
    if (!Config::get('useFTP')) {
        $preferences->setTempDir(TL_ROOT . '/system/tmp')->setCacheType('disk');
    }
    $preferences->setCharset(Config::get('characterSet'));
});
/**
 * Define the relative path to the installation (see #5339)
 */
if (file_exists(TL_ROOT . '/system/config/pathconfig.php') && TL_SCRIPT != 'contao/install.php') {
    define('TL_PATH', include TL_ROOT . '/system/config/pathconfig.php');
} elseif (TL_MODE == 'BE') {
    define('TL_PATH', preg_replace('/\\/contao\\/[a-z]+\\.php$/i', '', Environment::get('scriptName')));
} else {
    define('TL_PATH', null);
    // cannot be reliably determined
}
/**
Example #7
0
<?php

/*
 * This file is part of SwiftMailer.
 * (c) 2004-2009 Chris Corbyn
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
/*
 * Autoloader and dependency injection initialization for Swift Mailer.
 */
if (defined('SWIFT_REQUIRED_LOADED')) {
    return;
}
define('SWIFT_REQUIRED_LOADED', true);
// Load Swift utility class
require __DIR__ . DS . 'swiftmailer' . DS . 'classes' . DS . 'Swift.php';
// Start the autoloader
Swift::registerAutoload();
// Load the init script to set up dependency injection
require __DIR__ . DS . 'swiftmailer' . DS . 'swift_init.php';
// Register the native quoted printable encoder to achieve much better
// performance. This requires PHP 5.3, but since this is a Laravel bundle
// I think it's safe to assume that that shouldn't be a problem.
Swift::init(function () {
    Swift_DependencyContainer::getInstance()->register('mime.qpcontentencoder')->asAliasOf('mime.nativeqpcontentencoder');
});
// Map the Message classes.
Autoloader::map(array('Message' => __DIR__ . DS . 'libraries' . DS . 'message.php', 'Swiftmailer\\Drivers\\Driver' => __DIR__ . DS . 'libraries' . DS . 'message' . DS . 'drivers' . DS . 'driver.php', 'Swiftmailer\\Drivers\\SMTP' => __DIR__ . DS . 'libraries' . DS . 'message' . DS . 'drivers' . DS . 'smtp.php', 'Swiftmailer\\Drivers\\Sendmail' => __DIR__ . DS . 'libraries' . DS . 'message' . DS . 'drivers' . DS . 'sendmail.php', 'Swiftmailer\\Drivers\\Mail' => __DIR__ . DS . 'libraries' . DS . 'message' . DS . 'drivers' . DS . 'mail.php'));
Example #8
0
 /**
  * Initialize a new Swift_Message, set the subject and body.
  *
  * @param   string  message subject
  * @param   string  message body
  * @param   string  body mime type
  * @return  void
  */
 public function __construct($subject = null, $message = null, $type = null)
 {
     \Swift::init(function () {
         // Set the default character set for everything
         \Swift_Preferences::getInstance()->setCharset('utf-8');
     });
     // Create a new message, match internal character set
     $this->swiftmessage = \Swift_Message::newInstance();
     if ($subject) {
         // Apply subject
         $this->subject($subject);
     }
     if ($message) {
         // Apply message, with type
         $this->message($message, $type);
     }
 }
Example #9
0
<?php

Swift::init(function () {
    $charset = Kohana::$charset;
    // Set the default character set for everything
    Swift_Preferences::getInstance()->setCharset($charset);
});
Example #10
0
<?php

require __DIR__ . '/../vendor/autoload.php';
\Swift::init(function () {
    \Swift_DependencyContainer::getInstance()->register('mime.qpheaderencoder')->asAliasOf('mime.base64headerencoder');
    \Swift_Preferences::getInstance()->setCharset('iso-2022-jp');
});
$message = \Swift_Message::newInstance()->setSubject('件名')->setFrom(['*****@*****.**' => 'テスト送信者'])->setTo(['*****@*****.**'])->setBody("メール本文です\n1234567890\nあいうえおかきくけko\n")->setCharset('iso-2022-jp')->setEncoder(new \Swift_Mime_ContentEncoder_PlainContentEncoder('7bit'));
$transport = \Swift_MailTransport::newInstance();
$mailer = \Swift_Mailer::newInstance($transport);
$mailer->send($message);
echo "sent\n";
Example #11
0
        return $this;
    }
    public function send(array &$failed = NULL)
    {
        return Email::mailer()->send($this->_message, $failed);
    }
    public function batch(array $to, array &$failed = NULL)
    {
        $message = clone $this->_message;
        $mailer = Email::mailer();
        $total = 0;
        foreach ($to as $email => $name) {
            if (ctype_digit((string) $email)) {
                $email = $name;
                $name = NULL;
            }
            $message->setTo($email, $name);
            $total += $mailer->send($message, $failed);
        }
        return $total;
    }
}
if (!class_exists("Swift")) {
    require JsonApiApplication::find_file("vendor" . DIRECTORY_SEPARATOR . "swiftmailer", "lib" . DIRECTORY_SEPARATOR . "swift_required");
}
function swiftmailer_configurator()
{
    Swift_Preferences::getInstance()->setCharset(JsonApiApplication::$charset);
}
Swift::init("swiftmailer_configurator");