setUsername($config['options']['username']); empty($config['options']['password']) or $connection->setPassword($config['options']['password']); if ( ! empty($config['options']['auth'])) { list ($class, $params) = arr::callback_string($config['options']['auth']); if ($class === 'PopB4Smtp') { require Kohana::find_file('vendor', 'swift/Swift/Authenticator/$PopB4Smtp$'); } $class = 'Swift_Authenticator_'.$class; $connection->attachAuthenticator(($params === NULL) ? new $class : new $class($params[0])); } $connection->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']); break; case 'sendmail': $connection = new Swift_Connection_Sendmail ( empty($config['options']) ? Swift_Connection_Sendmail::AUTO_DETECT : $config['options'] ); $connection->setTimeout(5); break; default: $connection = new Swift_Connection_NativeMail($config['options']); break; } return email::$mail = new Swift($connection); } public static function send($to, $from, $subject, $message, $html = FALSE) { (email::$mail === NULL) and email::connect(); $html = ($html === TRUE) ? 'text/html' : 'text/plain'; $message = new Swift_Message($subject, $message, $html, '8bit', 'utf-8'); if (is_string($to)) { $recipients = new Swift_Address($to); } elseif (is_array($to)) { if (isset($to[0]) AND isset($to[1])) { $to = array('to' => $to); } $recipients = new Swift_RecipientList; foreach ($to as $method => $set) { if ( ! in_array($method, array('to', 'cc', 'bcc'))) { $method = 'to'; } $method = 'add'.ucfirst($method); if (is_array($set)) { $recipients->$method($set[0], $set[1]); } else { $recipients->$method($set); } } } if (is_string($from)) { $from = new Swift_Address($from); } elseif (is_array($from)) { $from = new Swift_Address($from[0], $from[1]); } return email::$mail->send($message, $recipients, $from); } }