Changeset 1903 for trunk/system/helpers/email.php
- Timestamp:
- 02/02/2008 09:37:18 PM (11 months ago)
- Files:
-
- 1 modified
-
trunk/system/helpers/email.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/helpers/email.php
r1893 r1903 21 21 * @return void 22 22 */ 23 public static function connect($ dsn= NULL)23 public static function connect($config = NULL) 24 24 { 25 25 // Load default configuration 26 ($ dsn === NULL) and $dsn = Config::item('email.dsn');26 ($config === NULL) and $config = Config::item('email'); 27 27 28 28 if ( ! class_exists('Swift', FALSE)) … … 35 35 } 36 36 37 if (substr($dsn, 0, 4) === 'smtp')37 switch ($config['driver']) 38 38 { 39 $dsn = parse_url($dsn); 39 case 'smtp': 40 // Create a SMTP connection 41 $connection = new Swift_Connection_SMTP 42 ( 43 $config['hostname'], 44 empty($config['options']['port']) ? 25 : $config['options']['port'] 45 ); 40 46 41 // Create the connection 42 $connection = new Swift_Connection_SMTP($dsn['host'], empty($dsn['port']) ? 25 : (int) $dsn['port']); 47 // Do authentication, if part of the DSN 48 empty($config['options']['username']) or $connection->setUsername($config['options']['username']); 49 empty($config['options']['password']) or $connection->setPassword($config['options']['password']); 43 50 44 // Do authentication, if part of the DSN 45 empty($dsn['user']) or $connection->setUsername($dsn['user']); 46 empty($dsn['pass']) or $connection->setPassword($dsn['pass']); 51 // Set the timeout to 5 seconds 52 $connection->setTimeout(5); 53 break; 54 case 'sendmail': 55 // Create a sendmail connection 56 $connection = new Swift_Connection_Sendmail 57 ( 58 empty($config['options']) ? Swift_Connection_Sendmail::AUTO_DETECT : $config['options'] 59 ); 47 60 48 // Set the timeout to 5 seconds 49 $connection->setTimeout(5); 50 } 51 elseif (substr($dsn, 0, 8) === 'sendmail') 52 { 53 if (($dsn = substr($dsn, 11)) === '') 54 { 55 // Auto-detect the paths 56 $dsn = Swift_Connection_Sendmail::AUTO_DETECT; 57 } 58 else 59 { 60 // Add the sendmail flags 61 $dsn.= ' -bs'; 62 } 63 64 // Use the sendmail connection 65 $connection = new Swift_Connection_Sendmail($dsn); 66 67 // Set the timeout to 5 seconds 68 $connection->setTimeout(5); 69 } 70 else 71 { 72 // Use the native connection 73 $connection = new Swift_Connection_NativeMail; 61 // Set the timeout to 5 seconds 62 $connection->setTimeout(5); 63 break; 64 default: 65 // Use the native connection 66 $connection = new Swift_Connection_NativeMail; 67 break; 74 68 } 75 69
