示例#1
0
 /**
  * Send a mail
  *
  * @param string $subject
  * @param string $content
  * @return bool|string false is everything was fine, or error string
  */
 public function send($subject, $content)
 {
     try {
         // Test with custom SMTP connection
         if ($this->smtp_checked) {
             $smtp = new Swift_Connection_SMTP($this->server, $this->port, $this->encryption == "off" ? Swift_Connection_SMTP::ENC_OFF : ($this->encryption == "tls" ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_SSL));
             $smtp->setUsername($this->login);
             $smtp->setpassword($this->password);
             $smtp->setTimeout(5);
             $swift = new Swift($smtp);
         } else {
             // Test with normal PHP mail() call
             $swift = new Swift(new Swift_Connection_NativeMail());
         }
         $message = new Swift_Message($subject, $content, 'text/html');
         if (@$swift->send($message, $this->email, 'no-reply@' . Tools::getHttpHost(false, false, true))) {
             $result = false;
         } else {
             $result = 'Could not send message';
         }
         $swift->disconnect();
     } catch (Swift_Exception $e) {
         $result = $e->getMessage();
     }
     return $result;
 }
 public static function sendMail($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption)
 {
     include INSTALL_PATH . '/../tools/swift/Swift.php';
     include INSTALL_PATH . '/../tools/swift/Swift/Connection/SMTP.php';
     include INSTALL_PATH . '/../tools/swift/Swift/Connection/NativeMail.php';
     $swift = NULL;
     $result = NULL;
     try {
         if ($smtpChecked) {
             $smtp = new Swift_Connection_SMTP($smtpServer, $smtpPort, $smtpEncryption == "off" ? Swift_Connection_SMTP::ENC_OFF : ($smtpEncryption == "tls" ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_SSL));
             $smtp->setUsername($smtpLogin);
             $smtp->setpassword($smtpPassword);
             $smtp->setTimeout(5);
             $swift = new Swift($smtp);
         } else {
             $swift = new Swift(new Swift_Connection_NativeMail());
         }
         $message = new Swift_Message($subject, $content, $type);
         if ($swift->send($message, $to, $from)) {
             $result = true;
         } else {
             $result = 999;
         }
         $swift->disconnect();
     } catch (Swift_Connection_Exception $e) {
         $result = $e->getCode();
     } catch (Swift_Message_MimeException $e) {
         $result = $e->getCode();
     }
     return $result;
 }
示例#3
0
 /**
  * 
  * @param $sender
  * @param $senderPass
  * @param $receiver
  * @param $subject
  * @param $message
  * @return unknown_type
  */
 public function email($sender, $senderPass, $receiver, $subject, $message, $replyTo = '*****@*****.**')
 {
     try {
         $smtp = new Swift_Connection_SMTP("smtp.gmail.com", 465, Swift_Connection_SMTP::ENC_SSL);
         $smtp->setTimeout(10);
         $smtp->setUsername($sender);
         $smtp->setPassword($senderPass);
         $smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
         $swift = new Swift($smtp, 'exambuff.co.uk');
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     $msgSubject = $subject;
     $msgBody = $message;
     $swfMessage = new Swift_Message($msgSubject, $msgBody);
     try {
         $swift->send($swfMessage, $receiver, $replyTo);
         return true;
     } catch (Exception $e) {
         if (!@$error) {
             $error = '';
         }
         $error .= $e->getMessage();
         log_message('error', $error);
     }
     return @$error;
 }
示例#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);
 }
示例#5
0
文件: Mail.php 项目: sealence/local
 public static function Send($id_lang, $template, $subject, $templateVars, $to, $toName = NULL, $from = NULL, $fromName = NULL, $fileAttachment = NULL, $modeSMTP = NULL, $templatePath = _PS_MAIL_DIR_)
 {
     $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_SMTP_ENCRYPTION', 'PS_MAIL_SMTP_PORT', 'PS_MAIL_METHOD', 'PS_MAIL_TYPE'));
     if (!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])) {
         $configuration['PS_MAIL_SMTP_ENCRYPTION'] = "off";
     }
     if (!isset($configuration['PS_MAIL_SMTP_PORT'])) {
         $configuration['PS_MAIL_SMTP_PORT'] = "default";
     }
     if (!isset($from)) {
         $from = $configuration['PS_SHOP_EMAIL'];
     }
     if (!isset($fromName)) {
         $fromName = $configuration['PS_SHOP_NAME'];
     }
     if (!empty($from) and !Validate::isEmail($from) or !empty($fromName) and !Validate::isMailName($fromName) or !is_array($to) and !Validate::isEmail($to) or !empty($toName) and !Validate::isMailName($toName) or !is_array($templateVars) or !Validate::isTplName($template) or !Validate::isMailSubject($subject)) {
         die(Tools::displayError('Error: mail parameters are corrupted'));
     }
     /* Construct multiple recipients list if needed */
     if (is_array($to)) {
         $to_list = new Swift_RecipientList();
         foreach ($to as $key => $addr) {
             $to_name = NULL;
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 die(Tools::displayError('Error: mail parameters are corrupted'));
             }
             if ($toName and is_array($toName) and Validate::isGenericName($toName[$key])) {
                 $to_name = $toName[$key];
             }
             $to_list->addTo($addr, $to_name);
         }
         $to_plugin = $to[0];
         $to = $to_list;
     } else {
         /* Simple recipient, one address */
         $to_plugin = $to;
         $to = new Swift_Address($to, $toName);
     }
     try {
         /* Connect with the appropriate configuration */
         if (intval($configuration['PS_MAIL_METHOD']) == 2) {
             $connection = new Swift_Connection_SMTP($configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], $configuration['PS_MAIL_SMTP_ENCRYPTION'] == "ssl" ? Swift_Connection_SMTP::ENC_SSL : ($configuration['PS_MAIL_SMTP_ENCRYPTION'] == "tls" ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
             $connection->setTimeout(4);
             if (!$connection) {
                 return false;
             }
             if (!empty($configuration['PS_MAIL_USER']) and !empty($configuration['PS_MAIL_PASSWD'])) {
                 $connection->setUsername($configuration['PS_MAIL_USER']);
                 $connection->setPassword($configuration['PS_MAIL_PASSWD']);
             }
         } else {
             $connection = new Swift_Connection_NativeMail();
         }
         if (!$connection) {
             return false;
         }
         $swift = new Swift($connection);
         /* Get templates content */
         $iso = Language::getIsoById(intval($id_lang));
         if (!$iso) {
             die(Tools::displayError('Error - No iso code for email !'));
         }
         $template = $iso . '/' . $template;
         if (!file_exists($templatePath . $template . '.txt') or !file_exists($templatePath . $template . '.html')) {
             die(Tools::displayError('Error - The following email template is missing:') . ' ' . $templatePath . $template . '.txt');
         }
         $templateHtml = file_get_contents($templatePath . $template . '.html');
         $templateTxt = strip_tags(html_entity_decode(file_get_contents($templatePath . $template . '.txt'), NULL, 'utf-8'));
         include_once dirname(__FILE__) . '/../mails/' . $iso . '/lang.php';
         global $_LANGMAIL;
         /* Create mail and attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME') . '] ' . ((is_array($_LANGMAIL) and key_exists($subject, $_LANGMAIL)) ? $_LANGMAIL[$subject] : $subject));
         $templateVars['{shop_logo}'] = file_exists(_PS_IMG_DIR_ . 'logo.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . 'logo.jpg'))) : '';
         $templateVars['{shop_name}'] = htmlentities(Configuration::get('PS_SHOP_NAME'), NULL, 'utf-8');
         $templateVars['{shop_url}'] = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__;
         $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $templateVars)), 'decorator');
         if ($configuration['PS_MAIL_TYPE'] == 3 or $configuration['PS_MAIL_TYPE'] == 2) {
             $message->attach(new Swift_Message_Part($templateTxt, 'text/plain', '8bit', 'utf-8'));
         }
         if ($configuration['PS_MAIL_TYPE'] == 3 or $configuration['PS_MAIL_TYPE'] == 1) {
             $message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8'));
         }
         if ($fileAttachment and isset($fileAttachment['content']) and isset($fileAttachment['name']) and isset($fileAttachment['mime'])) {
             $message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
         }
         /* Send mail */
         $send = $swift->send($message, $to, new Swift_Address($from, $fromName));
         $swift->disconnect();
         return $send;
     } catch (Swift_ConnectionException $e) {
         return false;
     }
 }
示例#6
0
 public static function sendMailTest($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption)
 {
     $swift = null;
     $result = false;
     try {
         if ($smtpChecked) {
             $smtp = new Swift_Connection_SMTP($smtpServer, $smtpPort, $smtpEncryption == 'off' ? Swift_Connection_SMTP::ENC_OFF : ($smtpEncryption == 'tls' ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_SSL));
             $smtp->setUsername($smtpLogin);
             $smtp->setpassword($smtpPassword);
             $smtp->setTimeout(5);
             $swift = new Swift($smtp, Configuration::get('PS_MAIL_DOMAIN'));
         } else {
             $swift = new Swift(new Swift_Connection_NativeMail(), Configuration::get('PS_MAIL_DOMAIN'));
         }
         $message = new Swift_Message($subject, $content, $type);
         if ($swift->send($message, $to, $from)) {
             $result = true;
         }
         $swift->disconnect();
     } catch (Swift_ConnectionException $e) {
         $result = $e->getMessage();
     } catch (Swift_Message_MimeException $e) {
         $result = $e->getMessage();
     }
     return $result;
 }
示例#7
0
 private function sendMail($customer_email, $body, $subject, $id_shop)
 {
     $method = (int) Configuration::get('PS_MAIL_METHOD');
     if ($method == 3) {
         return true;
     }
     try {
         if ($method == 2) {
             $server = Configuration::get('PS_MAIL_SERVER');
             $port = Configuration::get('PS_MAIL_SMTP_PORT');
             $encryption = Configuration::get('PS_MAIL_SMTP_ENCRYPTION');
             $user = Configuration::get('PS_MAIL_USER');
             $password = Configuration::get('PS_MAIL_PASSWD');
             if (empty($server) || empty($port)) {
                 return 205;
             }
             $connection = new Swift_Connection_SMTP($server, $port, $encryption == 'ssl' ? Swift_Connection_SMTP::ENC_SSL : ($encryption == 'tls' ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
             $connection->setTimeout(4);
             if (!$connection) {
                 return 206;
             }
             if (!empty($user)) {
                 $connection->setUsername($user);
             }
             if (!empty($password)) {
                 $connection->setPassword($password);
             }
         } else {
             $connection = new Swift_Connection_NativeMail();
             if (!$connection) {
                 return 207;
             }
         }
         $swift = new Swift($connection, Configuration::get('PS_MAIL_DOMAIN', null, null, $id_shop));
         $message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME', null, null, $id_shop) . '] ' . $subject);
         $message->setCharset('utf-8');
         $message->headers->setEncoding('Q');
         if (Context::getContext()->link instanceof Link === false) {
             Context::getContext()->link = new Link();
         }
         $message->attach(new Swift_Message_Part($body, 'text/html', '8bit', 'utf-8'));
         /* Send mail */
         $swift->send($message, $customer_email, new Swift_Address(Configuration::get('PS_SHOP_EMAIL'), Configuration::get('PS_SHOP_NAME', null, null, $id_shop)));
         $swift->disconnect();
         return true;
     } catch (Swift_Exception $e) {
         return 208;
     }
 }
示例#8
0
 /**
  * Sends notifications *now*
  * @param mixed $to string or array...the type of address (email, task ID, user ID) is specified below
  * @param integer $to_type type of $to address
  * @param integer $type type of notification
  * @param array $data additional info needed for notification
  * @access public
  * @return bool
  */
 function send_now($to, $to_type, $type, $data = array())
 {
     global $db, $fs, $proj;
     $emails = array();
     $jids = array();
     $result = true;
     if (defined('FS_NO_MAIL')) {
         return true;
     }
     switch ($to_type) {
         case ADDRESS_DONE:
             // from send_stored()
             list($emails, $jids) = $to;
             $data = unserialize($data['message_data']);
             $subject = $data['subject'];
             $body = $data['body'];
             break;
         case ADDRESS_EMAIL:
             // this happens on email confirmation, when no user exists
             $emails = is_array($to) ? $to : array($to);
             break;
         case ADDRESS_USER:
             // list of user IDs
             list($emails, $jids) = Notifications::user_to_address($to, $type);
             break;
         case ADDRESS_TASK:
             // now we need everyone on the notification list and the assignees
             list($emails, $jids) = Notifications::task_notifications($to, $type, ADDRESS_EMAIL);
             $data['task_id'] = $to;
             break;
     }
     if (isset($data['task_id'])) {
         $data['task'] = Flyspray::getTaskDetails($data['task_id']);
         // we have project specific options
         $pid = $db->x->GetOne('SELECT project_id FROM {tasks} WHERE task_id = ?', null, $data['task_id']);
         $data['project'] = new Project($pid);
     }
     if ($to_type != ADDRESS_DONE) {
         list($subject, $body) = Notifications::generate_message($type, $data);
     }
     if (isset($data['task_id'])) {
         // Now, we add the project contact addresses,
         // but only if the task is public
         $data['task'] = Flyspray::getTaskDetails($data['task_id']);
         if ($data['task']['mark_private'] != '1' && in_array($type, explode(' ', $data['project']->prefs['notify_types']))) {
             $proj_emails = preg_split('/[\\s,;]+/', $proj->prefs['notify_email'], -1, PREG_SPLIT_NO_EMPTY);
             $proj_jids = preg_split('/[\\s,;]+/', $proj->prefs['notify_jabber'], -1, PREG_SPLIT_NO_EMPTY);
             $emails = array_merge($proj_emails, $emails);
             if ($fs->prefs['global_email']) {
                 $emails[] = $fs->prefs['global_email'];
             }
             if ($fs->prefs['global_jabber']) {
                 $jids[] = $fs->prefs['global_jabber'];
             }
             $jids = array_merge($proj_jids, $emails);
         }
     }
     // Now we start sending
     if (count($emails)) {
         Swift_ClassLoader::load('Swift_Connection_Multi');
         Swift_ClassLoader::load('Swift_Connection_SMTP');
         $pool = new Swift_Connection_Multi();
         // first choose method
         if ($fs->prefs['smtp_server']) {
             $split = explode(':', $fs->prefs['smtp_server']);
             $port = null;
             if (count($split) == 2) {
                 $fs->prefs['smtp_server'] = $split[0];
                 $port = $split[1];
             }
             // connection... SSL, TLS or none
             if ($fs->prefs['email_ssl']) {
                 $smtp = new Swift_Connection_SMTP($fs->prefs['smtp_server'], $port ? $port : SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_SSL);
             } else {
                 if ($fs->prefs['email_tls']) {
                     $smtp = new Swift_Connection_SMTP($fs->prefs['smtp_server'], $port ? $port : SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_TLS);
                 } else {
                     $smtp = new Swift_Connection_SMTP($fs->prefs['smtp_server'], $port);
                 }
             }
             if ($fs->prefs['smtp_user']) {
                 $smtp->setUsername($fs->prefs['smtp_user']);
                 $smtp->setPassword($fs->prefs['smtp_pass']);
             }
             if (defined('FS_SMTP_TIMEOUT')) {
                 $smtp->setTimeout(FS_SMTP_TIMEOUT);
             }
             $pool->addConnection($smtp);
         } else {
             Swift_ClassLoader::load('Swift_Connection_NativeMail');
             // a connection to localhost smtp server as fallback, discarded if there is no such thing available.
             $pool->addConnection(new Swift_Connection_SMTP());
             $pool->addConnection(new Swift_Connection_NativeMail());
         }
         $swift = new Swift($pool);
         if (isset($data['task_id'])) {
             $swift->attachPlugin(new NotificationsThread($data['task_id'], $emails, $db), 'MessageThread');
         }
         if (defined('FS_MAIL_DEBUG')) {
             $swift->log->enable();
             Swift_ClassLoader::load('Swift_Plugin_VerboseSending');
             $view = new Swift_Plugin_VerboseSending_DefaultView();
             $swift->attachPlugin(new Swift_Plugin_VerboseSending($view), "verbose");
         }
         $message = new Swift_Message($subject, $body);
         // check for reply-to
         if (isset($data['project']) && $data['project']->prefs['notify_reply']) {
             $message->setReplyTo($data['project']->prefs['notify_reply']);
         }
         if (isset($data['project']) && isset($data['project']->prefs['bounce_address'])) {
             $message->setReturnPath($data['project']->prefs['bounce_address']);
         }
         $message->headers->setCharset('utf-8');
         $message->headers->set('Precedence', 'list');
         $message->headers->set('X-Mailer', 'Flyspray');
         // Add custom headers, possibly
         if (isset($data['headers'])) {
             $headers = array_map('trim', explode("\n", $data['headers']));
             if ($headers = array_filter($headers)) {
                 foreach ($headers as $header) {
                     list($name, $value) = explode(':', $header);
                     $message->headers->set(sprintf('X-Flyspray-%s', $name), $value);
                 }
             }
         }
         $recipients = new Swift_RecipientList();
         $recipients->addTo($emails);
         // && $result purpose: if this has been set to false before, it should never become true again
         // to indicate an error
         $result = $swift->batchSend($message, $recipients, $fs->prefs['admin_email']) === count($emails) && $result;
         if (isset($data['task_id'])) {
             $plugin =& $swift->getPlugin('MessageThread');
             if (count($plugin->thread_info)) {
                 $stmt = $db->x->autoPrepare('{notification_threads}', array('task_id', 'recipient_id', 'message_id'));
                 $db->x->executeMultiple($stmt, $plugin->thread_info);
                 $stmt->free();
             }
         }
         $swift->disconnect();
     }
     if (count($jids)) {
         $jids = array_unique($jids);
         if (!$fs->prefs['jabber_username'] || !$fs->prefs['jabber_password']) {
             return $result;
         }
         // nothing that can't be guessed correctly ^^
         if (!$fs->prefs['jabber_port']) {
             $fs->prefs['jabber_port'] = 5222;
         }
         require_once 'class.jabber2.php';
         $jabber = new Jabber($fs->prefs['jabber_username'], $fs->prefs['jabber_password'], $fs->prefs['jabber_security'], $fs->prefs['jabber_port'], $fs->prefs['jabber_server']);
         $jabber->SetResource('flyspray');
         $jabber->login();
         foreach ($jids as $jid) {
             $result = $jabber->send_message($jid, $body, $subject, 'normal') && $result;
         }
     }
     return $result;
 }
示例#9
0
 /**
  * Builds a Swift_Connection depending on the type (native, smtp, sendmail, multi, rotator)
  * Params depend on the connection type
  * 
  * - native:
  *    additional_params
  * 
  * - smtp:
  *     server (*)
  *     port
  *     encryption (SSL, TLS, or OFF)
  *     authentication:
  *       username (*)
  *       password
  *     timeout
  *     requires_ehlo
  *   
  * - sendmail:
  *     command
  *     flags
  *     timeout
  *     requires_ehlo
  *   
  * - multi:
  *     connections:
  *       connection_name1:
  *         type
  *         params
  *       connection_name2:
  *         type
  *         params
  *       etc...
  *     requires_ehlo
  *   
  * - rotator:
  *     connections:
  *       connection_name1:
  *         type
  *         params
  *       connection_name2:
  *         type
  *         params
  *       etc...
  *     requires_ehlo
  *  
  * (*) Mandatory !
  *
  * @param string $type
  * @param array $params
  * @return Swift_Connection
  */
 protected static function getConnection($type, $params = array())
 {
     switch ($type) {
         case 'native':
             $connection = new Swift_Connection_NativeMail();
             if (@$params['additional_params']) {
                 $connection->setAdditionalMailParams($params['additional_params']);
             }
             break;
         case 'smtp':
             if (!@$params['encryption']) {
                 $params['encryption'] = 'OFF';
             }
             $encryption = constant('Swift_Connection_SMTP::ENC_' . $params['encryption']);
             $connection = new Swift_Connection_SMTP($params['server'], @$params['port'], $encryption);
             if (@$params['authentication']) {
                 $connection->setUsername(@$params['authentication']['username']);
                 $connection->setPassword(@$params['authentication']['password']);
             }
             if (@$params['timeout']) {
                 $connection->setTimeout($params['timeout']);
             }
             if (@$params['requires_ehlo']) {
                 $connection->setRequiresEHLO(true);
             }
             break;
         case 'sendmail':
             $connection = new Swift_Connection_Sendmail();
             if (@$params['command']) {
                 $connection->setCommand($params['command']);
             }
             if (@$params['flags']) {
                 $connection->setFlags($params['flags']);
             }
             if (@$params['timeout']) {
                 $connection->setTimeout($params['timeout']);
             }
             if (@$params['requires_ehlo']) {
                 $connection->setRequiresEHLO(true);
             }
             break;
         case 'multi':
             $connection = new Swift_Connection_Multi();
             foreach ($params['connections'] as $id => $conn_info) {
                 $connection->addConnection(self::getConnection($conn_info['type'], $conn_info['params']));
             }
             if (@$params['requires_ehlo']) {
                 $connection->setRequiresEHLO(true);
             }
             break;
         case 'rotator':
             $connection = new Swift_Connection_Multi();
             foreach ($params['connections'] as $id => $conn_info) {
                 $connection->addConnection(self::getConnection($conn_info['type'], $conn_info['params']));
             }
             if (@$params['requires_ehlo']) {
                 $connection->setRequiresEHLO(true);
             }
             break;
     }
     return $connection;
 }
示例#10
0
 public static function SendReport($subject, $fileAttachment = NULL)
 {
     $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_SMTP_ENCRYPTION', 'PS_MAIL_SMTP_PORT', 'PS_MAIL_METHOD', 'PS_MAIL_TYPE'));
     if (!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])) {
         $configuration['PS_MAIL_SMTP_ENCRYPTION'] = 'off';
     }
     if (!isset($configuration['PS_MAIL_SMTP_PORT'])) {
         $configuration['PS_MAIL_SMTP_PORT'] = 'default';
     }
     $from = $configuration['PS_SHOP_EMAIL'];
     //if (!isset($fromName)) $fromName = $configuration['PS_SHOP_NAME'];
     $fromName = 'IndusDiva.com';
     if (!empty($from) and !Validate::isEmail($from)) {
         die(Tools::displayError('Error: parameter "from" is corrupted'));
     }
     if (!empty($fromName) and !Validate::isMailName($fromName)) {
         die(Tools::displayError('Error: parameter "fromName" is corrupted'));
     }
     if (!Validate::isMailSubject($subject)) {
         die(Tools::displayError('Error: invalid email subject'));
     }
     $to = array('*****@*****.**', '*****@*****.**');
     /* Construct multiple recipients list if needed */
     if (is_array($to)) {
         $to_list = new Swift_RecipientList();
         foreach ($to as $addr) {
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 die(Tools::displayError('Error: invalid email address'));
             }
             $to_list->addTo($addr, null);
         }
         $to = $to_list;
     }
     try {
         /* Connect with the appropriate configuration */
         if ($configuration['PS_MAIL_METHOD'] == 2) {
             if (empty($configuration['PS_MAIL_SERVER']) or empty($configuration['PS_MAIL_SMTP_PORT'])) {
                 die(Tools::displayError('Error: invalid SMTP server or SMTP port'));
             }
             $connection = new Swift_Connection_SMTP($configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], $configuration['PS_MAIL_SMTP_ENCRYPTION'] == "ssl" ? Swift_Connection_SMTP::ENC_SSL : ($configuration['PS_MAIL_SMTP_ENCRYPTION'] == "tls" ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
             $connection->setTimeout(4);
             if (!$connection) {
                 return false;
             }
             if (!empty($configuration['PS_MAIL_USER'])) {
                 $connection->setUsername($configuration['PS_MAIL_USER']);
             }
             if (!empty($configuration['PS_MAIL_PASSWD'])) {
                 $connection->setPassword($configuration['PS_MAIL_PASSWD']);
             }
         } else {
             $connection = new Swift_Connection_NativeMail();
         }
         if (!$connection) {
             return false;
         }
         $swift = new Swift($connection, Configuration::get('PS_MAIL_DOMAIN'));
         /* Create mail and attach differents parts */
         //$message = new Swift_Message('['.Configuration::get('PS_SHOP_NAME').'] '. $subject);
         $message = new Swift_Message($subject);
         if ($fileAttachment and isset($fileAttachment['content']) and isset($fileAttachment['name']) and isset($fileAttachment['mime'])) {
             $message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
         }
         /* Send mail */
         $send = $swift->send($message, $to, new Swift_Address($from, $fromName));
         $swift->disconnect();
         return $send;
     } catch (Swift_ConnectionException $e) {
         return false;
     }
 }
示例#11
0
 /**
  * Private function that emails the user with their activation key
  *
  * @param String $email
  * @param String $firstName
  * @todo add language lines for emails
  */
 private function emailActivation($email, $firstName, $key)
 {
     require_once $this->config->item('swift');
     require_once $this->config->item('swift_smtp');
     require_once $this->config->item('swift_auth');
     try {
         $smtp = new Swift_Connection_SMTP("smtp.gmail.com", 465, Swift_Connection_SMTP::ENC_SSL);
         $smtp->setTimeout(10);
         $smtp->setUsername("*****@*****.**");
         $smtp->setPassword("44naughty555");
         $smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
         $swift = new Swift($smtp, 'exambuff.co.uk');
     } catch (Exception $e) {
         $msg = $e->getMessage();
         log_message('error', 'Error setting up activation email ' . $msg);
     }
     $viewData['name'] = $firstName;
     $viewData['activationCode'] = $key;
     $msgSubject = "Activate your Exambuff account";
     $msgBody = $this->load->view('email/activation_request', $viewData, TRUE);
     $swfMessage = new Swift_Message($msgSubject, $msgBody);
     try {
         $swift->send($swfMessage, $email, '*****@*****.**');
     } catch (Exception $e) {
         $msg = $e->getMessage();
         log_message('error', 'Error while sending activation email ' . $msg);
     }
 }
示例#12
0
 /**
  * Private function that emails the user with their activation key
  *
  * @param String $email
  * @param String $firstName
  * @todo add language lines for emails
  */
 private function emailActivation($email, $firstName)
 {
     require_once $this->config->item('swift');
     require_once $this->config->item('swift_smtp');
     require_once $this->config->item('swift_auth');
     $this->load->model('activator');
     $this->activator->generateKey();
     $this->activator->set('email', $email);
     $this->activator->create();
     try {
         $smtp = new Swift_Connection_SMTP("smtp.gmail.com", 465, Swift_Connection_SMTP::ENC_SSL);
         $smtp->setTimeout(10);
         $smtp->setUsername("*****@*****.**");
         $smtp->setPassword("44naughty555");
         $smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
         $swift = new Swift($smtp, 'exambuff.co.uk');
     } catch (Exception $e) {
         $msg = $e->getMessage();
         log_message('error', $msg);
     }
     $message = new Swift_Message("test", "Dear {$firstName},\n Please go to " . app_base() . 'signup/activate/' . $this->activator->get('activationKey') . ' to finish your activation');
     $swift->send($message, $email, '*****@*****.**');
 }
示例#13
0
文件: pay.php 项目: cybercog/exambuff
 /**
  * Email the user a receipt for their payment 
  * 
  * @param $email
  * @param $items
  * @param $time
  * @param $transactionID
  * @param $method
  * @return unknown_type
  */
 private function _emailReceipt($recipientEmail)
 {
     require_once $this->config->item('swift');
     require_once $this->config->item('swift_smtp');
     require_once $this->config->item('swift_auth');
     try {
         $smtp = new Swift_Connection_SMTP("smtp.gmail.com", 465, Swift_Connection_SMTP::ENC_SSL);
         $smtp->setTimeout(10);
         $smtp->setUsername("*****@*****.**");
         $smtp->setPassword("gim3th3c@ash");
         $smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
         $swift = new Swift($smtp, 'exambuff.co.uk');
     } catch (Exception $e) {
         $msg = $e->getMessage();
         log_message('error', "Email to {$recipientEmail} failed due to {$msg}");
         return false;
     }
     $this->load->model('user');
     $user = new User();
     $user->retrieve($recipientEmail);
     $nameChunks = explode(' ', $user->get('name'), 2);
     $firstName = $nameChunks[0];
     $viewData['firstName'] = $firstName;
     $viewData['question'] = $this->scriptToPay->get('question');
     $msgSubject = "Payment receipt from Exambuff";
     $msgBody = $this->load->view('email/receipt', $viewData, TRUE);
     $swfMessage = new Swift_Message($msgSubject, $msgBody);
     try {
         if ($swift->send($swfMessage, $recipientEmail, '*****@*****.**')) {
             return true;
         }
         return false;
     } catch (Exception $e) {
         $msg = $e->getMessage();
         log_message('error', "Email to {$recipientEmail} failed due to {$msg}");
         return false;
     }
 }