/** * Initializes this mailer based on the specified settings or the stored transport settings * @param bool $use_smtp TRUE if sender should use SMTP * @param string $smtp_server The SMTP server * @param int $smtp_port The SMTP port * @param string $smtp_encryption The SMTP encryption type * @param string $smtp_username The SMTP username * @param string $smtp_password The SMTP password * @param bool $use_sendmail TRUE if sender should fall back on sendmail if SMTP fails * @param bool $use_phpmail TRUE if sender should fall back on phpmail if SMTP/Sendmail fails * @return bool TRUE if operation was successful, else FALSE */ public function init($use_smtp = NULL, $smtp_server = NULL, $smtp_port = NULL, $smtp_encryption = NULL, $smtp_username = NULL, $smtp_password = NULL, $use_sendmail = NULL, $use_phpmail = NULL) { $connections = array(); $use_smtp = isset($use_smtp) ? $use_smtp : gu_config::get('use_smtp'); $smtp_server = isset($smtp_server) ? $smtp_server : gu_config::get('smtp_server'); $smtp_port = isset($smtp_port) ? (int) $smtp_port : (int) gu_config::get('smtp_port'); $smtp_encryption = isset($smtp_encryption) ? $smtp_encryption : gu_config::get('smtp_encryption'); $smtp_username = isset($smtp_username) ? $smtp_username : gu_config::get('smtp_username'); $smtp_password = isset($smtp_password) ? $smtp_password : gu_config::get('smtp_password'); $use_sendmail = isset($use_sendmail) ? $use_sendmail : gu_config::get('use_sendmail'); $use_phpmail = isset($use_phpmail) ? $use_phpmail : gu_config::get('use_phpmail'); if (!($use_smtp || $use_sendmail || $use_phpmail)) { return gu_error(t('No method of mail transportation has been configured')); } // Add the SMTP connection if details have been given if ($use_smtp) { switch ($smtp_encryption) { case 'SSL': $enc = Swift_Connection_SMTP::ENC_SSL; case 'TLS': $enc = Swift_Connection_SMTP::ENC_TLS; default: $enc = Swift_Connection_SMTP::ENC_OFF; } $server = $smtp_server != '' ? $smtp_server : Swift_Connection_SMTP::AUTO_DETECT; $port = $smtp_port > 0 ? $smtp_port : Swift_Connection_SMTP::AUTO_DETECT; $smtp = new Swift_Connection_SMTP($server, $port, $enc); if ($smtp_username != '' && $smtp_password != '') { $smtp->setUsername($smtp_username); $smtp->setPassword($smtp_password); } $connections[] =& $smtp; gu_debug(t('Created SMTP connection (%:% Enc:% User:% Pass:%)', array($smtp->getServer(), $smtp->getPort(), $smtp_encryption, $smtp->getUsername(), str_mask($smtp->getPassword())))); } // Add the SendMail connection option if ($use_sendmail) { $connections[] = new Swift_Connection_Sendmail(Swift_Connection_Sendmail::AUTO_DETECT); } // Fall back on mail() if all else fails if ($use_phpmail) { $connections[] = new Swift_Connection_NativeMail(); } // And instantiate swift with these connections try { $this->swift = new Swift(new Swift_Connection_Multi($connections)); } catch (Swift_ConnectionException $e) { gu_debug($e->getMessage()); return gu_error(t("Unable to initialize mailer. Check transport settings.")); } // Enable level 3 logging $log =& Swift_LogContainer::getLog(); $log->setLogLevel(3); return TRUE; }
public function testStrMask() { $string = '123123123123'; $masked_string = '123.123-123/123'; $this->assertEquals($masked_string, str_mask($string, '###.###-###/###')); }
/** * Format the given string as phone number (Brazil) * * @param $telefone * @return string */ function format_telefone($telefone) { return str_mask($telefone, '(##) #####-####'); }