Пример #1
0
 public static function config($config = array())
 {
     if (!is_array($config)) {
         return false;
     }
     self::$config = $config;
     self::$mail = System::load_sys_class("phpmailer");
     self::$mail->IsSMTP();
     // 启用SMTP
     self::$mail->Host = $config['stmp_host'];
     //SMTP服务器
     self::$mail->SMTPAuth = true;
     //开启SMTP认证
     self::$mail->Username = $config['user'];
     // SMTP用户名
     self::$mail->Password = $config['pass'];
     // SMTP密码
     self::$mail->From = $config['from'];
     //发件人地址
     self::$mail->FromName = $config['fromName'];
     //发件人
     self::$mail->AddReplyTo($config['from'], $config['fromName']);
     //回复地址
     self::$mail->WordWrap = 50;
     //设置每行字符长度
 }
Пример #2
0
 /**
  * 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);
 }
Пример #3
0
 /**
  * Creates a SwiftMailer instance.
  *
  * @param   string  Config array mirroring format as described in config file
  * @return  object  Swift object
  */
 public static function connect($config = NULL)
 {
     if (!class_exists('Swift', FALSE)) {
         // Load SwiftMailer
         require Kohana::find_file('vendor', 'swift4/lib/swift_required');
         // Register the Swift ClassLoader as an autoload
         Swift::registerAutoload();
     }
     // 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'];
             //Set host
             $transport = Swift_SmtpTransport::newInstance()->setHost($config['options']['hostname']);
             //Set port if defined
             if ($port) {
                 $transport->setPort($port);
             }
             //Set encryption if defined
             if (!empty($config['options']['encryption'])) {
                 $enc = strtolower($config['options']['encryption']);
                 $transport->setEncryption($enc);
             }
             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
             $mailer = Swift_Mailer::newInstance($transport);
             break;
             //Sendmail
         //Sendmail
         case 'sendmail':
             $op = empty($config['options']) ? null : $config['options'];
             $transport = Swift_SendmailTransport::newInstance($op);
             break;
             //PHP mail :(
         //PHP mail :(
         default:
             $transport = Swift_MailTransport::newInstance();
             break;
     }
     // Create the SwiftMailer instance
     return email::$mail = $mailer;
 }
Пример #4
0
 /**
  * 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 Kohana::find_file('vendor', 'swift/Swift');
         // Register the Swift ClassLoader as an autoload
         spl_autoload_register(array('Swift_ClassLoader', 'load'));
     }
     // 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'];
             if (empty($config['options']['encryption'])) {
                 // No encryption
                 $encryption = Swift_Connection_SMTP::ENC_OFF;
             } else {
                 // Set encryption
                 switch (strtolower($config['options']['encryption'])) {
                     case 'tls':
                         $encryption = Swift_Connection_SMTP::ENC_TLS;
                         break;
                     case 'ssl':
                         $encryption = Swift_Connection_SMTP::ENC_SSL;
                         break;
                 }
             }
             // Create a SMTP connection
             $connection = new Swift_Connection_SMTP($config['options']['hostname'], $port, $encryption);
             // 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 = new Swift_Connection_Sendmail(empty($config['options']) ? Swift_Connection_Sendmail::AUTO_DETECT : $config['options']);
             // Set the timeout to 5 seconds
             $connection->setTimeout(5);
             break;
         default:
             // Use the native connection
             $connection = new Swift_Connection_NativeMail($config['options']);
             break;
     }
     // Create the SwiftMailer instance
     return email::$mail = new Swift($connection);
 }