示例#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
 /**
  * Envía un email a través de la configuración de campanias de la empresa que se pasa como parámetro. Utiliza el plugin sfSwiftPlugin
  * @param id_empresa, identificador de la empresa a través de la que se envia el mensaje.
  * @param asunto, asunto del mensaje
  * @param cuerpo, cuerpo del mensaje
  * @param lista_emails, lista de emails, a los que se envia el mensjae.
  * @return integer, número de mensajes enviados
  * @version 25-02-09
  * @author Ana Martin
  */
 public static function enviarEmailDefault($id_empresa, $asunto, $cuerpo, $lista_emails)
 {
     $empresa = EmpresaPeer::retrievebypk($id_empresa);
     if ($empresa instanceof Empresa) {
         $smtp_server = $empresa->getSmtpServer();
         $smtp_user = $empresa->getSmtpUser();
         $smtp_password = $empresa->getSmtpPassword();
         $smtp_port = $empresa->getSmtpPort();
         $sender_email = $empresa->getSenderAddress();
         $sender_name = $empresa->getSenderName();
         //$c = new Criteria();
         //$c->add(PlantillaPeer::ID_EMPRESA, $empresa->getIdEmpresa());
         //$plantilla = PlantillaPeer::doSelectOne($c);
         $plantilla = "";
         $cuerpo = MensajePeer::prepararMailingCuerpoDefault($cuerpo, $plantilla, $asunto);
         $smtp = new Swift_Connection_SMTP($smtp_server, $smtp_port);
         $smtp->setUsername($smtp_user);
         $smtp->setpassword($smtp_password);
         $mailer = new Swift($smtp);
         $message = new Swift_Message(utf8_decode($asunto));
         $message->attach(new Swift_Message_Part($cuerpo, "text/html"));
         $recipients = new Swift_RecipientList();
         foreach ($lista_emails as $email) {
             $recipients->addTo($email);
         }
         //Load the plugin with these replacements
         /*  $replacaments = array(
                        '{FECHA}' => date('d-m-Y') , 
                        '{ASUNTO}' => utf8_decode($asunto),
                        '{MENSAJE}' => utf8_decode($cuerpo),             
                     );
          	  $mailer->attachPlugin(new Swift_Plugin_Decorator($replacaments), "decorator");*/
         $enviado_por = new Swift_Address($sender_email, $sender_name);
         $cuantos = $mailer->send($message, $recipients, $enviado_por);
         $mailer->disconnect();
         return $cuantos;
     } else {
         return 0;
     }
 }
示例#4
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;
 }
示例#5
0
 private function openConnection()
 {
     $this->db = $this->Application->getModule('horuxDb')->DbConnection;
     //$this->db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
     $this->db->Active = true;
     $sql = "SELECT * FROM hr_config WHERE `id`=1";
     $cmd = $this->db->createCommand($sql);
     $data = $cmd->query();
     $data = $data->read();
     $this->mailer = $data['mail_mailer'];
     $this->mail_from = $data['mail_mail_from'];
     $this->from_name = $data['mail_from_name'];
     $this->sendmail_path = $data['mail_sendmail_path'];
     $this->smtp_auth = $data['mail_smtp_auth'];
     $this->smtp_safe = $data['mail_smtp_safe'];
     $this->smtp_username = $data['mail_smtp_username'];
     $this->smtp_password = $data['mail_smtp_password'];
     $this->smtp_host = $data['mail_smtp_host'];
     $this->smtp_port = $data['mail_smtp_port'];
     try {
         switch ($this->mailer) {
             case 'mail':
                 $this->swift = new Swift(new Swift_Connection_NativeMail());
                 break;
             case 'sendmail':
                 $this->swift = new Swift(new Swift_Connection_Sendmail($this->sendmail_path));
                 break;
             case 'smtp':
                 //! no authentication
                 $smtp = NULL;
                 switch ($this->smtp_safe) {
                     case 'none':
                         $smtp = new Swift_Connection_SMTP($this->smtp_host, $this->smtp_port);
                         break;
                     case 'ssl':
                         $smtp = new Swift_Connection_SMTP($this->smtp_host, $this->smtp_port, Swift_Connection_SMTP::ENC_SSL);
                         break;
                     case 'tls':
                         if ($this->smtp_port > 0) {
                             $smtp = new Swift_Connection_SMTP($this->smtp_host, $this->smtp_port, Swift_Connection_SMTP::ENC_TLS);
                         } else {
                             $smtp = new Swift_Connection_SMTP($this->smtp_host, Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
                         }
                         break;
                 }
                 if ($this->smtp_auth) {
                     $smtp->setUsername($this->smtp_username);
                     $smtp->setpassword($this->smtp_password);
                 }
                 $this->swift = new Swift($smtp);
                 break;
         }
         return true;
     } catch (Swift_ConnectionException $e) {
         echo "There was a problem communicating with : " . $e->getMessage();
         exit;
         return false;
     } catch (Swift_Message_MimeException $e) {
         echo "There was an unexpected problem building the email:" . $e->getMessage();
         exit;
         return false;
     }
 }
 function ResendEmailLog($id)
 {
     $emailLog = ClassRegistry::init('EmailLog');
     $data = $emailLog->findById($id);
     if ($data == false) {
         return false;
     }
     App::import('Vendor', 'Swift', array('file' => 'swift/Swift.php'));
     App::import('Vendor', 'Swift_Connection_SMTP', array('file' => 'swift/Swift/Connection/SMTP.php'));
     $html = $data['EmailLog']['text'];
     $subject = $data['EmailLog']['subject'];
     $to = $data['EmailLog']['to'];
     $from = $data['EmailLog']['from'];
     $from_text = $data['EmailLog']['fromtext'];
     $smtp = new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
     $smtp->setUsername("*****@*****.**");
     $smtp->setpassword("coda123456");
     $swift = new Swift($smtp);
     $message =& new Swift_Message($subject, $html, "text/html");
     $send = $swift->send($message, $to, new Swift_Address($from, $from_text));
     if ($send >= 1) {
         $this->updateEmailLog($id);
     }
     return $send;
 }