newInstance() публичный статический Метод

Create a new SmtpTransport instance.
public static newInstance ( string $host = 'localhost', integer $port = 25, string $security = null ) : Swift_SmtpTransport
$host string
$port integer
$security string
Результат Swift_SmtpTransport
Пример #1
0
 /**
  * Creates a new Mensaje entity.
  *
  */
 public function createAction(Request $request)
 {
     $entity = new Mensaje();
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     $em = $this->getDoctrine()->getManager();
     $categorias = $em->getRepository('GulloaStoreBackendBundle:Categoria')->findAll();
     if ($form->isValid()) {
         $emailname = 'no.reply.gulloadev';
         $emailpass = '******';
         $transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")->setUsername($emailname)->setPassword($emailpass)->setSourceIp('0.0.0.0');
         $asunto = $entity->getAsunto();
         $datos = $em->getRepository('GulloaStoreBackendBundle:Datos')->find(1);
         $mensaje = $this->renderView('GulloaStoreBackendBundle:Mail:mensaje.html.twig', array('entity' => $entity));
         $message = \Swift_Message::newInstance()->setSubject('[GulloaStore] ' . $asunto)->setFrom('*****@*****.**')->setTo($datos->getEmail())->setBody($mensaje, 'text/html');
         $mailer = \Swift_Mailer::newInstance($transport);
         $mailer->send($message);
         $this->addFlash('mailing', 'Mensaje enviado correctamente');
         $entity->setLeido(0)->setFecha(new \DateTime('now'));
         $em->persist($entity);
         $em->flush();
         return $this->redirect($this->generateUrl('mensaje'));
     }
     return $this->render('GulloaStoreBackendBundle:Tipo:new.html.twig', array('entity' => $entity, 'form' => $form->createView(), 'categorias' => $categorias));
 }
Пример #2
0
 /**
  * Send email using swift api.
  * 
  * @param $body
  * @param $recipients
  * @param $from
  * @param $subject
  */
 public function sendEmail($body, $recipients, $from, $subject)
 {
     $config = Zend_Registry::get('config');
     $failures = '';
     Swift_Preferences::getInstance()->setCharset('UTF-8');
     //Create the Transport
     $transport = Swift_SmtpTransport::newInstance($config->mail->server->name, $config->mail->server->port, $config->mail->server->security)->setUsername($config->mail->username)->setPassword($config->mail->password);
     $mailer = Swift_Mailer::newInstance($transport);
     $message = Swift_Message::newInstance();
     $headers = $message->getHeaders();
     $headers->addTextHeader("signed-by", Constant::EMAIL_DOMAIN);
     //Give the message a subject
     $message->setSubject($subject);
     //Set the From address with an associative array
     $message->setFrom($from);
     //Set the To addresses with an associative array
     $message->setTo($recipients);
     //Give it a body
     $message->setBody($body);
     $message->setContentType("text/html");
     //Send the message
     $myresult = $mailer->batchSend($message);
     if ($myresult) {
         return null;
     } else {
         return Constant::EMAIL_FAIL_MESSAGE;
     }
 }
Пример #3
0
 /**
  * Creates a SwiftMailer instance.
  *
  * @param   string  DSN connection string
  * @return  object  Swift object
  */
 public static function connect($config = NULL)
 {
     // Load default configuration
     $config === NULL and $config = Kohana::$config->load('email');
     switch ($config['driver']) {
         case 'smtp':
             // Set port
             $port = empty($config['options']['port']) ? 25 : (int) $config['options']['port'];
             // Create SMTP Transport
             $transport = Swift_SmtpTransport::newInstance($config['options']['hostname'], $port);
             if (!empty($config['options']['encryption'])) {
                 // Set encryption
                 $transport->setEncryption($config['options']['encryption']);
             }
             // Do authentication, if part of the DSN
             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
             $transport->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']);
             break;
         case 'sendmail':
             // Create a sendmail connection
             $transport = Swift_SendmailTransport::newInstance(empty($config['options']) ? "/usr/sbin/sendmail -bs" : $config['options']);
             break;
         default:
             // Use the native connection
             $transport = Swift_MailTransport::newInstance();
             break;
     }
     // Create the SwiftMailer instance
     return self::$_mail = Swift_Mailer::newInstance($transport);
 }
 /**
  * Create an object
  *
  * @param  ContainerInterface $container
  * @param  string $requestedName
  * @param  null|array $options
  * @return object|\Swift_Mailer
  * @throws ServiceNotFoundException if unable to resolve the service.
  * @throws ServiceNotCreatedException if an exception is raised when
  *     creating a service.
  * @throws ContainerException if any other error occurs
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null) : \Swift_Mailer
 {
     $mailConfig = $container->get('config')['mail'];
     $smtp = $mailConfig['smtp'];
     $transport = \Swift_SmtpTransport::newInstance($smtp['server'], $smtp['port'], $smtp['ssl'])->setUsername($smtp['username'])->setPassword($smtp['password']);
     return new \Swift_Mailer($transport);
 }
Пример #5
0
 public function register(Container $container)
 {
     $host = Config::get('mail.smtp.host');
     $port = Config::get('mail.smtp.port');
     $encryption = Config::get('mail.smtp.encryption');
     $username = Config::get('mail.smtp.username');
     $password = Config::get('mail.smtp.password');
     // The Swift SMTP transport instance will allow us to use any SMTP backend
     // for delivering mail such as Sendgrid, Amazon SMS, or a custom server
     // a developer has available. We will just pass the configured host.
     $transport = SmtpTransport::newInstance($host, $port);
     if (isset($encryption)) {
         $transport->setEncryption($encryption);
     }
     // Once we have the transport we will check for the presence of a username
     // and password. If we have it we will set the credentials on the Swift
     // transporter instance so that we'll properly authenticate delivery.
     if (isset($username)) {
         $transport->setUsername($username);
         $transport->setPassword($password);
     }
     $mailer = new Mailer(new Swift_Mailer($transport));
     $mailer->alwaysFrom(Config::get('mail.from.email'), Config::get('mail.from.name'));
     $container->mail = $mailer;
 }
Пример #6
0
 public function notifyAction()
 {
     $id = 1;
     $settings = R::load('settings', $id);
     $time_before = c::now()->modify('+' . $settings->time_before)->toDateString();
     $transport = \Swift_SmtpTransport::newInstance($settings->mail_host, $settings->mail_port)->setUsername($settings->mail_username)->setPassword($settings->mail_password);
     $mailer = \Swift_Mailer::newInstance($transport);
     $client = new \Services_Twilio($settings->twilio_sid, $settings->twilio_token);
     $recepients = R::findAll('recepients');
     $events = R::find("events", "is_enabled = 1 AND date = '{$time_before}'");
     foreach ($events as $event) {
         foreach ($recepients as $recepient) {
             $subject = preg_replace(array('/{title}/', '/{date}/'), array($event->title, $event->date), $settings->subject);
             $end_date = c::parse($event->date)->modify('+' . $event->days . ' days')->toDateString();
             $body_patterns = array('/{name}/', '/{title}/', '/{start_date}/', '/<!(\\w+) ({\\w+})>/');
             $body_replacements = array($settings->name, $event->title, $event->date, "\$1 {$end_date}");
             if ($event->days == 1) {
                 $body_replacements[3] = '';
             }
             $body = preg_replace($body_patterns, $body_replacements, $settings->msg_template);
             if ($recepient->email && $settings->mail_username && $settings->mail_password) {
                 $message = \Swift_Message::newInstance()->setSubject($subject)->setBody($body)->setFrom(array($settings->email => $settings->name))->setTo(array($recepient->email => $recepient->name));
                 try {
                     $response = $mailer->send($message);
                 } catch (\Exception $e) {
                     //todo: log error
                 }
             } else {
                 if ($recepient->phone_number && $settings->twilio_sid && $settings->twilio_token && $settings->twilio_phonenumber) {
                     $message = $client->account->messages->sendMessage($settings->twilio_phonenumber, $recepient->phone_number, $body);
                 }
             }
         }
     }
 }
Пример #7
0
 /**
  * Parse the configuration file
  *
  * @param array $parsedConfig
  */
 private function loadConfig($parsedConfig)
 {
     if (isset($parsedConfig['moduleConf']['Type']) && $parsedConfig['moduleConf']['Type'] == "smtp") {
         $this->transport = \Swift_SmtpTransport::newInstance();
         if (isset($parsedConfig['moduleConf']['Host']) && $parsedConfig['moduleConf']['Host'] != "") {
             $this->transport->setHost($parsedConfig['moduleConf']['Host']);
         }
         if (isset($parsedConfig['moduleConf']['Port']) && $parsedConfig['moduleConf']['Port'] != "") {
             $this->transport->setPort($parsedConfig['moduleConf']['Port']);
         }
         if (isset($parsedConfig['moduleConf']['Username']) && $parsedConfig['moduleConf']['Username'] != "") {
             $this->transport->setUsername($parsedConfig['moduleConf']['Username']);
         }
         if (isset($parsedConfig['moduleConf']['Password']) && $parsedConfig['moduleConf']['Password'] != "") {
             $this->transport->setPassword($parsedConfig['moduleConf']['Password']);
         }
         if (isset($parsedConfig['moduleConf']['Encryption']) && $parsedConfig['moduleConf']['Encryption'] != "") {
             $this->transport->setEncryption($parsedConfig['moduleConf']['Encryption']);
         }
     } elseif (isset($parsedConfig['moduleConf']['Type']) && $parsedConfig['moduleConf']['Type'] == "sendmail") {
         $this->transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
     } else {
         $this->transport = \Swift_MailTransport::newInstance();
     }
 }
Пример #8
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) {
             // Retrocompatibility
             if (Tools::strtolower($this->encryption) === 'off') {
                 $this->encryption = false;
             }
             $smtp = Swift_SmtpTransport::newInstance($this->server, $this->port, $this->encryption);
             $smtp->setUsername($this->login);
             $smtp->setpassword($this->password);
             $smtp->setTimeout(5);
             $swift = Swift_Mailer::newInstance($smtp);
         } else {
             // Test with normal PHP mail() call
             $swift = Swift_Mailer::newInstance(Swift_MailTransport::newInstance());
         }
         $message = Swift_Message::newInstance();
         $message->setFrom($this->email)->setTo('no-reply@' . Tools::getHttpHost(false, false, true))->setSubject($subject)->setBody($content);
         $message = new Swift_Message($subject, $content, 'text/html');
         if (@$swift->send($message)) {
             $result = true;
         } else {
             $result = 'Could not send message';
         }
         $swift->disconnect();
     } catch (Swift_SwiftException $e) {
         $result = $e->getMessage();
     }
     return $result;
 }
Пример #9
0
 public function initialize()
 {
     require_once TD_INC . 'swift/swift_required.php';
     if ($this->config['transport'] == 'smtp') {
         $this->transport = Swift_SmtpTransport::newInstance($this->config['smtp_host']);
         if ($this->config['smtp_port']) {
             $this->transport->setPort($this->config['smtp_port']);
         }
         if ($this->config['smtp_encryption']) {
             $this->transport->setEncryption($this->config['smtp_encryption']);
         }
         if ($this->config['smtp_user']) {
             $this->transport->setUsername($this->config['smtp_user']);
         }
         if ($this->config['smtp_pass']) {
             $this->transport->setPassword($this->config['smtp_pass']);
         }
         if ($this->config['smtp_timeout']) {
             $this->transport->setTimeout($this->config['smtp_timeout']);
         }
     } elseif ($this->config['transport'] == 'sendmail') {
         $this->transport = Swift_SendmailTransport::newInstance();
         if ($this->config['sendmail_command']) {
             $this->transport->setCommand($this->config['sendmail_command']);
         }
     } elseif ($this->config['transport'] == 'mail') {
         $this->transport = Swift_MailTransport::newInstance();
     }
     $this->mailer = Swift_Mailer::newInstance($this->transport);
 }
Пример #10
0
 public function __construct(LiveCart $application)
 {
     $this->application = $application;
     $this->set('request', $application->getRequest()->toArray());
     $this->url = $this->application->router->createFullUrl('/', null, true);
     $config = $this->application->getConfig();
     ClassLoader::ignoreMissingClasses();
     if ('SMTP' == $config->get('EMAIL_METHOD')) {
         $server = $config->get('SMTP_SERVER');
         if (!$server) {
             $server = ini_get('SMTP');
         }
         $this->connection = Swift_SmtpTransport::newInstance($server, $config->get('SMTP_PORT'));
         if ($config->get('SMTP_USERNAME')) {
             $this->connection->setUsername($config->get('SMTP_USERNAME'));
             $this->connection->setPassword($config->get('SMTP_PASSWORD'));
         }
     } else {
         if ('FAKE' == $config->get('EMAIL_METHOD')) {
             $this->connection = Swift_Connection_Fake::newInstance();
         } else {
             $this->connection = Swift_MailTransport::newInstance();
         }
     }
     $this->swiftInstance = Swift_Mailer::newInstance($this->connection);
     $this->message = Swift_Message::newInstance();
     $this->setFrom($config->get('MAIN_EMAIL'), $config->get('STORE_NAME'));
     ClassLoader::ignoreMissingClasses(false);
 }
Пример #11
0
 public function indexAction()
 {
     if ($this->request->isPost() == true) {
         require_once PUBLIC_PATH . 'library/swiftmailer/lib/swift_required.php';
         //Settings
         $mail_settings = $this->config->mail;
         // Create the SMTP configuration
         $transport = \Swift_SmtpTransport::newInstance($mail_settings->smtp->server, $mail_settings->smtp->port, $mail_settings->smtp->security);
         $transport->setUsername($mail_settings->smtp->username);
         $transport->setPassword($mail_settings->smtp->password);
         $form_data = $this->request->getPost();
         // Create the message
         $message = \Swift_Message::newInstance();
         $message->setTo(array($form_data['fromEmail']));
         $message->setSubject($form_data['title']);
         $message->setBody($form_data['content']);
         $message->setFrom($mail_settings->from_email, $mail_settings->from_name);
         // Send the email
         $mailer = \Swift_Mailer::newInstance($transport);
         $result = $mailer->send($message);
         if ($result) {
             $this->flash->success("Thank you, sent mail successful!");
             $tbl_contact = new \Modules\Frontend\Models\Contact();
             $tbl_contact->fullname = $form_data['fullName'];
             $tbl_contact->from_mail = $form_data['fromEmail'];
             $tbl_contact->title = $form_data['title'];
             $tbl_contact->content = $form_data['content'];
             $tbl_contact->status = '0';
             $tbl_contact->send_date = date('Y-m-d H:i:s');
             $tbl_contact->save();
         } else {
             $this->flash->error("Failed! Please send mail again!");
         }
     }
 }
Пример #12
0
 public function send($lastOverride = false)
 {
     $i18n = Localization::getTranslator();
     $lastFn = '/home/pi/phplog/last-tx-sent';
     $last = 0;
     if (file_exists($lastFn)) {
         $last = intval(trim(file_get_contents($lastFn)));
     }
     if ($lastOverride !== false) {
         $last = $lastOverride;
     }
     $csvMaker = Container::dispense('TransactionCSV');
     $config = Admin::volatileLoad()->getConfig();
     $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername($config->getEmailUsername())->setPassword($config->getEmailPassword());
     $msg = Swift_Message::newInstance()->setSubject($config->getMachineName() . $i18n->_(': Transaction Log'))->setFrom([$config->getEmailUsername() => $config->getMachineName()])->setTo(array($config->getEmailUsername()))->setBody($i18n->_('See attached for transaction log.'));
     $file = $csvMaker->save($last);
     if (!$file) {
         throw new Exception('Unable to save CSV');
     }
     $msg->attach(Swift_Attachment::fromPath($file));
     file_put_contents($lastFn, $csvMaker->getLastID());
     $mailer = Swift_Mailer::newInstance($transport);
     if (!$mailer->send($msg)) {
         throw new Exception('Unable to send: unkown cause');
     }
 }
Пример #13
0
 protected function getMailer()
 {
     if (empty($this->mailer)) {
         require_once PATH_SYSTEM . "/vendors/Swift-4.0.4/lib/swift_required.php";
         switch ($this->emailMode) {
             case 'smtp':
                 //Create the Transport
                 $transport = Swift_SmtpTransport::newInstance($this->emailConfig['host'], $this->emailConfig['port']);
                 if (!empty($this->emailConfig['user'])) {
                     $transport->setUsername($this->emailConfig['user']);
                 }
                 if (!empty($this->emailConfig['password'])) {
                     $transport->setPassword($this->emailConfig['password']);
                 }
                 if (!empty($this->emailConfig['timeout'])) {
                     $transport->setTimeout($this->emailConfig['timeout']);
                 }
                 if (!empty($this->emailConfig['encryption'])) {
                     $transport->setEncryption($this->emailConfig['encryption']);
                 }
                 $this->mailer = Swift_Mailer::newInstance($transport);
                 break;
             case 'sendmail':
                 $transport = Swift_SendmailTransport::newInstance(!empty($this->emailConfig['pathToSendmail']) ? $this->emailConfig['pathToSendmail'] : '/usr/sbin/sendmail -bs');
                 $this->mailer = Swift_Mailer::newInstance($transport);
                 break;
             default:
             case 'mail':
                 $transport = Swift_MailTransport::newInstance();
                 $this->mailer = Swift_Mailer::newInstance($transport);
                 break;
         }
     }
     return $this->mailer;
 }
Пример #14
0
 /**
  * @param $to
  * @param $subject
  * @param $body
  * @return bool
  */
 public function send($to, $subject, $body)
 {
     include_once "vendor/autoload.php";
     date_default_timezone_set("Asia/Colombo");
     $this->CI->config->load('send_grid');
     $username = $this->CI->config->item('send_grid_username');
     $password = $this->CI->config->item('send_grid_password');
     $smtp_server = $this->CI->config->item('send_grid_smtp_server');
     $smtp_server_port = $this->CI->config->item('send_grid_smtp_server_port');
     $sending_address = $this->CI->config->item('email_sender_address');
     $sending_name = $this->CI->config->item('email_sender_name');
     $from = array($sending_address => $sending_name);
     $to = array($to);
     $transport = Swift_SmtpTransport::newInstance($smtp_server, $smtp_server_port);
     $transport->setUsername($username);
     $transport->setPassword($password);
     $swift = Swift_Mailer::newInstance($transport);
     $message = new Swift_Message($subject);
     $message->setFrom($from);
     $message->setBody($body, 'text/html');
     $message->setTo($to);
     $message->addPart($body, 'text/plain');
     // send message
     if ($recipients = $swift->send($message, $failures)) {
         return true;
     } else {
         return false;
     }
 }
Пример #15
0
 public function EnviarCorreoConfirmacionTransaccion($nombre, $email, $id_transaccion)
 {
     //echo "Enviando Correos";
     //ini_set('max_execution_time', 28800); //240 segundos = 4 minutos
     //Enviar correo electr�nico
     $url = base_url();
     $transport = Swift_SmtpTransport::newInstance()->setHost('smtp.gmail.com')->setPort(465)->setEncryption('ssl')->setUsername('*****@*****.**')->setPassword('passsword');
     //Create the Mailer using your created Transport
     $mailer = Swift_Mailer::newInstance($transport);
     //$this->load->model("Solicitud_model", "solicitud");
     //$query = $this->solicitud->getAlumnosCorreo();
     //Pass it as a parameter when you create the message
     $message = Swift_Message::newInstance();
     //Give the message a subject
     //Or set it after like this
     $message->setSubject('Confirmacion Transaccion Agencia');
     //no_reply@ugto.mx
     $message->setFrom(array('*****@*****.**' => 'Agencia'));
     $message->addTo($email);
     //$message->addTo('*****@*****.**');
     //$message->addBcc('*****@*****.**');
     //Add alternative parts with addPart()
     $failedRecipients = array();
     $message->addPart("<h2>Gracias por su preferencia, </h2>" . $nombre . "\n                <br>\n                <h3>Su transaccion ha sido realizada con éxito.</h3>\n                <br>\n                No. Transaccion: " . $id_transaccion . "<br>\n                ---<br>\n                ", 'text/html');
     if (!$mailer->send($message)) {
         return FALSE;
     }
     return TRUE;
 }
Пример #16
0
 public static function getInstance($smtp_server, $smtp_port, $smtp_ssl = false)
 {
     if (is_null(self::$instance)) {
         self::$instance = Swift_SmtpTransport::newInstance($smtp_server, $smtp_port, $smtp_ssl ? 'ssl' : null);
     }
     return self::$instance;
 }
Пример #17
0
 public function action_request()
 {
     $id = (int) base64_decode($this->request->param('id'));
     $friendship = false;
     if ($id && $id != $this->user->id) {
         $friendship = ORM::factory('Friends')->setFriendship($this->user->id, $id);
     }
     if ($friendship) {
         $to = ORM::factory('User')->where('id', '=', $id)->find();
         // notify!
         if ($to->loaded() && $to->details->notify_friendship) {
             // SWIFTMAILER MAGIC
             $swc = (object) Kohana::$config->load('smtp.default');
             $transport = Swift_SmtpTransport::newInstance($swc->host, $swc->port, $swc->ssl ? 'ssl' : null)->setUsername($swc->user)->setPassword($swc->password);
             $mailer = Swift_Mailer::newInstance($transport);
             $body = $swc->body_friendship;
             $body = str_replace('%TO%', $to->username, $body);
             $body = str_replace('%FROM%', $this->user->username, $body);
             $message = Swift_Message::newInstance(__($this->user->username . ' möchte dein Freund auf ' . $this->project_config->project_name . ' werden'))->setFrom($swc->from)->setTo(array($to->email))->setBody($body, 'text/html');
             $result = $mailer->send($message);
         }
         $this->redirect('/user/show/' . ORM::factory('User')->getUsername($id));
     } else {
         $this->redirect('/user/show/' . ORM::factory('User')->getUsername($id));
     }
 }
Пример #18
0
 /**
  * Send an email
  * @param SwiftMessage $message
  * @return mixed - TRUE on success, or an array of failed addresses on error.
  */
 static function send($message)
 {
     try {
         require_once 'include/swiftmailer/swift_required.php';
         if (defined('SMTP_SERVER')) {
             $port = defined('SMTP_PORT') ? SMTP_PORT : 25;
             $transport = Swift_SmtpTransport::newInstance(SMTP_SERVER, $port);
             if (defined('SMTP_USERNAME') && SMTP_USERNAME) {
                 $transport->setUsername(SMTP_USERNAME);
             }
             if (defined('SMTP_PASSWORD') && SMTP_PASSWORD) {
                 $transport->setPassword(SMTP_PASSWORD);
             }
             if (defined('SMTP_ENCRYPTION') && SMTP_ENCRYPTION) {
                 $transport->setEncryption(SMTP_ENCRYPTION);
             }
         } else {
             $transport = Swift_MailTransport::newInstance();
         }
         $mailer = Swift_Mailer::newInstance($transport);
         $failures = array();
         $numSent = $mailer->send($message, $failures);
         if (empty($failures) && $numSent) {
             return TRUE;
         }
         return $failures;
     } catch (Exception $e) {
         trigger_error("Could not send email: " . $e->getMessage(), E_USER_WARNING);
         return FALSE;
     }
 }
Пример #19
0
 public static function send()
 {
     $transport = \Swift_SmtpTransport::newInstance('smtp.mail.ru', 465, 'ssl')->setUsername('*****@*****.**')->setPassword('');
     $mailer = \Swift_Mailer::newInstance($transport);
     $messages = \Swift_Message::newInstance('Wonderful Subject')->setFrom('*****@*****.**')->setTo(['*****@*****.**' => 'Работа'])->setContentType("text/html; charset=UTF-8")->setBody('Тестовое сообщение о БД', 'text/html');
     $result = $mailer->send($messages);
 }
Пример #20
0
 /**
  * Sends the digest
  */
 public function send()
 {
     $lastMonths = new \DateTime();
     $lastMonths->modify('-6 month');
     $parameters = array('modified_at >= ?0 AND digest = "Y" AND notifications <> "N"', 'bind' => array($lastMonths->getTimestamp()));
     $users = array();
     foreach (Users::find($parameters) as $user) {
         if ($user->email && strpos($user->email, '@') !== false && strpos($user->email, '@users.noreply.github.com') === false) {
             $users[trim($user->email)] = $user->name;
         }
     }
     $fromName = $this->config->mail->fromName;
     $fromEmail = $this->config->mail->fromEmail;
     $url = $this->config->site->url;
     $subject = 'Top Stories from Phosphorum ' . date('d/m/y');
     $lastWeek = new \DateTime();
     $lastWeek->modify('-1 week');
     $order = 'number_views + ' . '((IF(votes_up IS NOT NULL, votes_up, 0) - ' . 'IF(votes_down IS NOT NULL, votes_down, 0)) * 4) + ' . 'number_replies + IF(accepted_answer = "Y", 10, 0) DESC';
     $parameters = array('created_at >= ?0 AND deleted != 1 AND categories_id <> 4', 'bind' => array($lastWeek->getTimestamp()), 'order' => $order, 'limit' => 10);
     $e = $this->escaper;
     $content = '<html><head></head><body><p><h1 style="font-size:22px;color:#333;letter-spacing:-0.5px;line-height:1.25;font-weight:normal;padding:16px 0;border-bottom:1px solid #e2e2e2">Top Stories from Phosphorum</h1></p>';
     foreach (Posts::find($parameters) as $post) {
         $user = $post->user;
         if ($user == false) {
             continue;
         }
         $content .= '<p><a style="text-decoration:none;display:block;font-size:20px;color:#333;letter-spacing:-0.5px;line-height:1.25;font-weight:normal;color:#155fad" href="' . $url . '/discussion/' . $post->id . '/' . $post->slug . '">' . $e->escapeHtml($post->title) . '</a></p>';
         $content .= '<p><table width="100%"><td><table><tr><td>' . '<img src="https://secure.gravatar.com/avatar/' . $user->gravatar_id . '?s=32&amp;r=pg&amp;d=identicon" width="32" height="32" alt="' . $user->name . ' icon">' . '</td><td><a style="text-decoration:none;color:#155fad" href="' . $url . '/user/' . $user->id . '/' . $user->login . '">' . $user->name . '<br><span style="text-decoration:none;color:#999;text-decoration:none">' . $user->getHumanKarma() . '</span></a></td></tr></table></td><td align="right"><table style="border: 1px solid #dadada;" cellspacing=5>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Created</label><br>' . $post->getHumanCreatedAt() . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Replies</label><br>' . $post->number_replies . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Views</label><br>' . $post->number_views . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Votes</label><br>' . ($post->votes_up - $post->votes_down) . '</td>' . '</tr></table></td></tr></table></p>';
         $content .= $this->markdown->render($e->escapeHtml($post->content));
         $content .= '<p><a style="color:#155fad" href="' . $url . '/discussion/' . $post->id . '/' . $post->slug . '">Read more</a></p>';
         $content .= '<hr style="border: 1px solid #dadada">';
     }
     $textContent = strip_tags($content);
     $htmlContent = $content . '<p style="font-size:small;-webkit-text-size-adjust:none;color:#717171;">';
     $htmlContent .= PHP_EOL . 'This email was sent by Phalcon Framework. Change your e-mail preferences <a href="' . $url . '/settings">here</a></p>';
     foreach ($users as $email => $name) {
         try {
             $message = new \Swift_Message('[Phalcon Forum] ' . $subject);
             $message->setTo(array($email => $name));
             $message->setFrom(array($fromEmail => $fromName));
             $bodyMessage = new \Swift_MimePart($htmlContent, 'text/html');
             $bodyMessage->setCharset('UTF-8');
             $message->attach($bodyMessage);
             $bodyMessage = new \Swift_MimePart($textContent, 'text/plain');
             $bodyMessage->setCharset('UTF-8');
             $message->attach($bodyMessage);
             if (!$this->transport) {
                 $this->transport = \Swift_SmtpTransport::newInstance($this->config->smtp->host, $this->config->smtp->port, $this->config->smtp->security);
                 $this->transport->setUsername($this->config->smtp->username);
                 $this->transport->setPassword($this->config->smtp->password);
             }
             if (!$this->mailer) {
                 $this->mailer = \Swift_Mailer::newInstance($this->transport);
             }
             $this->mailer->send($message);
         } catch (\Exception $e) {
             echo $e->getMessage(), PHP_EOL;
         }
     }
 }
Пример #21
0
 public function respond(array $communication, \stdClass $msg)
 {
     $result = $this->generateResponse($communication);
     if (preg_match('/^\\s*re:/', $msg->subject)) {
         $subject = $msg->subject;
     } else {
         $subject = 'Re: ' . $msg->subject;
     }
     if (isset($this->config['name'])) {
         $from = array($this->config['email_address'] => $this->config['name']);
     } else {
         $from = array($this->config['email_address']);
     }
     $to = array($msg->from_email);
     if (isset($msg->headers->{'Message-Id'})) {
         $message_id = $msg->headers->{'Message-Id'};
     } else {
         $message_id = false;
     }
     // TODO - set reply to id
     $transport = \Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587);
     $transport->setUsername($this->config['mandrill_username']);
     $transport->setPassword($this->config['mandrill_password']);
     $swift = \Swift_Mailer::newInstance($transport);
     $message = new \Swift_Message($subject);
     $message->setFrom($from);
     $message->setBody($result);
     $message->setTo($to);
     $result = $swift->send($message);
 }
Пример #22
0
 public function action_profile()
 {
     $user_id = (int) base64_decode($this->request->param('id'));
     if ($user_id) {
         $user_id = $user_id - 1337;
         $backto = base64_decode($this->request->post('backto'));
         if ('POST' === $this->request->method() && strlen($this->request->post('comment')) >= 1) {
             try {
                 $values = array('content' => $this->request->post('comment'), 'user_id' => $user_id, 'author_id' => $this->user->id, 'created' => date('Y-m-d H:i:s'));
                 $comment = ORM::factory('User_Profile_Comment')->values($values, array_keys($values))->save();
                 if ($comment->saved()) {
                     // inform?
                     $receiver = ORM::factory('User', $user_id);
                     if ($receiver->loaded() && $receiver->details->notify_wall) {
                         // SWIFTMAILER MAGIC
                         $swc = (object) Kohana::$config->load('smtp.default');
                         $transport = Swift_SmtpTransport::newInstance($swc->host, $swc->port, $swc->ssl ? 'ssl' : null)->setUsername($swc->user)->setPassword($swc->password);
                         $mailer = Swift_Mailer::newInstance($transport);
                         $body = $swc->body_notify_wall;
                         $body = str_replace('%USERNAME%', $receiver->username, $body);
                         $body = str_replace('%FROM%', $this->user->username, $body);
                         $message = Swift_Message::newInstance($this->user->username . ' ' . __('hat dein Profil bei ' . $this->project_config->project_name . ' kommentiert'))->setFrom($swc->from)->setTo(array($receiver->email))->setBody($body, 'text/html');
                         $mailer->send($message);
                     }
                 }
             } catch (ORM_Validation_Exception $e) {
                 // shi...
             }
         }
         $this->redirect('user/show/' . $backto);
     }
     $this->redirect('/');
 }
Пример #23
0
 function __construct()
 {
     // include swift mailer
     require ENGINE_PATH . 'swiftmailer/classes/Swift.php';
     Swift::init();
     Swift::registerAutoload();
     //Yii::import('system.vendors.swiftMailer.classes.Swift', true);
     //Yii::registerAutoloader(array('Swift','autoload'));
     require_once ENGINE_PATH . 'swiftmailer/swift_init.php';
     //Yii::import('system.vendors.swiftMailer.swift_init', true);
     switch ($this->params['transportType']) {
         case 'smtp':
             $transport = Swift_SmtpTransport::newInstance($this->params['smtpServer'], $this->params['smtpPort'], $this->params['smtpSequre'])->setUsername($this->params['smtpUsername'])->setPassword($this->params['smtpPassword']);
             break;
         case 'sendmail':
             $transport = Swift_SendmailTransport::newInstance($this->params['sendmailCommand']);
             break;
         default:
         case 'mail':
             $transport = Swift_MailTransport::newInstance();
             break;
     }
     $this->toEmail = 'noreplay@' . $_SERVER['HTTP_HOST'];
     $this->fromEmail = 'noreplay@' . $_SERVER['HTTP_HOST'];
     $this->path = "http://" . $_SERVER['HTTP_HOST'] . "/submit/mailtpl/";
     $this->mailer = Swift_Mailer::newInstance($transport);
     $this->mes = Swift_Message::newInstance();
 }
Пример #24
0
 public function __construct($aConfigs = array())
 {
     $this->sName = "Mail";
     $this->sVersion = "1.0";
     $sFileName = $this->getBasePath() . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'swiftmailer' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'swift_required.php';
     if (!file_exists($sFileName)) {
         return false;
     }
     require_once $sFileName;
     parent::__construct($aConfigs);
     $sMethod = isset($this->aConfigs['method']) ? $this->aConfigs['method'] : "mail";
     if ($sMethod == "smtp") {
         $sPort = isset($this->aConfigs['port']) ? $this->aConfigs['port'] : 25;
         $mSecure = isset($this->aConfigs['authenticate']) ? $this->aConfigs['authenticate'] : "tls";
         $sHost = isset($this->aConfigs['host']) ? $this->aConfigs['host'] : "localhost";
         $sUserName = isset($this->aConfigs['user']) ? $this->aConfigs['user'] : "";
         $sPassword = isset($this->aConfigs['password']) ? $this->aConfigs['password'] : "";
         $transport = \Swift_SmtpTransport::newInstance($sHost, $sPort, $mSecure);
         $transport->setUserName($sUserName);
         $transport->setPassword($sPassword);
     } else {
         $transport = \Swift_MailTransport::newInstance();
     }
     $this->oMailer = \Swift_Mailer::newInstance($transport);
 }
Пример #25
0
 public function __construct()
 {
     // 设置邮件系统服务器、端口、加密方式以及用户账号信息
     $this->transport = \Swift_SmtpTransport::newInstance($this->host, $this->port, $this->encryption)->setUsername($this->username)->setPassword($this->password);
     // 传入上面配置好的参数用以得到一个Swift_Mailer实例化对象
     $this->mailer = \Swift_Mailer::newInstance($this->transport);
 }
Пример #26
0
 public static function createFromConfig(ConfigInterface $config)
 {
     $transport = $config->get('mailer_transport');
     $host = $config->get('mailer_host');
     $port = $config->get('mailer_port');
     // 25 or 465 (smtp)
     $username = $config->get('mailer_username');
     $password = $config->get('mailer_password');
     $authMode = $config->get('mailer_auth_mode');
     $encryption = $config->get('mailer_encryption');
     if ($transport == 'gmail') {
         $transport = 'smtp';
         $host = 'smtp.gmail.com';
         $authMode = 'login';
         $encryption = 'ssl';
         $port = 465;
     }
     $port = $port ? $port : 25;
     if ($transport == 'smtp') {
         $transport = \Swift_SmtpTransport::newInstance($host, $port)->setUsername($username)->setPassword($password);
     } elseif ($transport == 'mail') {
         $transport = \Swift_MailTransport::newInstance();
     } elseif ($transport == 'null') {
         $transport = \Swift_NullTransport::newInstance();
     } else {
         throw new \RuntimeException(sprintf('Unable to construct a transport of type "%s"', $transport));
     }
     return \Swift_Mailer::newInstance($transport);
 }
Пример #27
0
    /**
     * Base constructor.
     * In the base constructor the bridge gets the mailer configuration.
     *
     * @param ConfigObject $config The base configuration.
     *
     * @throws SwiftMailerException
     */
    public function __construct($config)
    {
        $this->config = $config;
        $transportType = strtolower($config->get('Transport.Type', 'mail'));
        $disableDelivery = $config->get('DisableDelivery', false);
        if ($disableDelivery) {
            $transportType = 'null';
        }
        // create Transport instance
        switch ($transportType) {
            case 'smtp':
                $transport = \Swift_SmtpTransport::newInstance($config->get('Transport.Host', 'localhost'), $config->get('Transport.Port', 25), $config->get('Transport.AuthMode', null));
                $transport->setUsername($config->get('Transport.Username', ''));
                $transport->setPassword($config->get('Transport.Password', ''));
                $transport->setEncryption($config->get('Transport.Encryption', null));
                break;
            case 'mail':
                $transport = \Swift_MailTransport::newInstance();
                break;
            case 'sendmail':
                $transport = \Swift_SendmailTransport::newInstance($config->get('Transport.Command', '/usr/sbin/sendmail -bs'));
                break;
            case 'null':
                $transport = \Swift_NullTransport::newInstance();
                break;
            default:
                throw new SwiftMailerException('Invalid transport.type provided.
												Supported types are [smtp, mail, sendmail, null].');
                break;
        }
        // create Mailer instance
        $this->mailer = \Swift_Mailer::newInstance($transport);
        // register plugins
        $this->registerPlugins($config);
    }
Пример #28
0
    public function sendAppointmentNotif($lead)
    {
    	$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
		->setUsername('*****@*****.**')
		->setPassword('rocketman88')
		;

		$mailer = Swift_Mailer::newInstance($transport);

		$body = "Howdy! \n\n" .
		"A new appointment request has been recorded. \n".
		"Below are the details: \n\n".
		"Preferred Date: ".$lead['date']."\n".
		"Preferred Time: ".$lead['time']."\n".
		"Name: ".$lead['fname']." ".$lead['lname']."\n".
		"Email: ".$lead['email']."\n".
		"Contact Number: ".$lead['contact']."\n".
		"Present Country: ".$lead['country']."\n".
		"Nationality: ".$lead['nationality']."\n".
		"Unit Interested in: ".$lead['unit']."\n".
		"Notes: ".$lead['notes']."\n\n".
		"This message was generated at DMCI Leasing Website.";

		$message = Swift_Message::newInstance('New Appointment Request Submitted in Leasing Website')
		->setFrom(array('*****@*****.**' => 'DMCI Leasing Webmaster'))
		->setTo(array('*****@*****.**' => 'DMCI Leasing Services'))
		->setBcc(array('*****@*****.**', '*****@*****.**', '*****@*****.**'))
		->setBody($body)
		;

		$result = $mailer->send($message);

		return $result;
    }
Пример #29
0
 /**
  * Class constructor.
  * Load all data from configurations and generate the initial clases
  * to manage the email
  * 
  * @param string Content type for message body. It usually text/plain or text/html.
  * 		Default is 'text/plain' but can be changed later
  */
 public function __construct($content_type = 'text/plain')
 {
     $config = RMFunctions::configs();
     $config_handler =& xoops_gethandler('config');
     $xconfig = $config_handler->getConfigsByCat(XOOPS_CONF_MAILER);
     // Instantiate the Swit Transport according to our preferences
     // We can change this preferences later
     switch ($config['transport']) {
         case 'mail':
             $this->swTransport = Swift_MailTransport::newInstance();
             break;
         case 'smtp':
             $this->swTransport = Swift_SmtpTransport::newInstance($config['smtp_server'], $config['smtp_port'], $config['smtp_crypt'] != 'none' ? $config['smtp_crypt'] : '');
             $this->swTransport->setUsername($config['smtp_user']);
             $this->swTransport->setPassword($config['smtp_pass']);
             break;
         case 'sendmail':
             $this->swTransport = Swift_SendmailTransport::newInstance($config['sendmail_path']);
             break;
     }
     // Create the message object
     // Also this object could be change later with message() method
     $this->swMessage = Swift_Message::newInstance();
     $this->swMessage->setReplyTo($xconfig['from']);
     $this->swMessage->setFrom(array($xconfig['from'] => $xconfig['fromname']));
     $this->swMessage->setContentType($content_type);
 }
Пример #30
0
 /**
  * Define the transport method
  * @param object $okt
  */
 protected function setTransport()
 {
     switch ($this->okt->config->email['transport']) {
         default:
         case 'mail':
             $this->transport = Swift_MailTransport::newInstance();
             break;
         case 'smtp':
             $this->transport = Swift_SmtpTransport::newInstance($this->okt->config->email['smtp']['host'], $this->okt->config->email['smtp']['port']);
             if (!empty($this->okt->config->email['smtp']['username'])) {
                 $this->transport->setUsername($this->okt->config->email['smtp']['username']);
             }
             if (!empty($this->okt->config->courriel['smtp']['password'])) {
                 $this->transport->setPassword($this->okt->config->email['smtp']['password']);
             }
             break;
         case 'sendmail':
             $command = '/usr/sbin/exim -bs';
             if (!empty($this->okt->config->email['sendmail'])) {
                 $command = $this->okt->config->email['sendmail'];
             }
             $this->transport = Swift_SendmailTransport::newInstance($command);
             break;
     }
 }