emailFrom = $args['email_from']; if(!empty($args['name_from'])) $this->nameFrom = $args['name_from']; $this->args = $args; $this->main(); } else { $this->setConnection(); //$this->main(); $this->sendEmailFromStack(); } } public function main(){ if($this->args['sendNow'] == 1){ $this->saveEmail(); $this->setConnection(); $this->sendEmail($this->getEmail()); } else { $this->saveEmail(); } } private function setConnection(){ //$this->connection = new Swift_Connection_SMTP(sfConfig::get('app_email_smtp_host')); //$this->connection->setUsername(sfConfig::get('app_email_smtp_user')); //$this->connection->setPassword(sfConfig::get('app_email_smtp_pass')); /* $this->connection = new Swift_Connection_SMTP('kkt.klape.eu'); $this->connection->setUsername('smtp_jakobson.cz'); $this->connection->setPassword('lsdfpa050jsr');*/ // $this->connection = new Swift_Connection_SMTP('smtp.mandrillapp.com', 465, Swift_Connection_SMTP::ENC_SSL); // $this->connection->setUsername('tom@tomatom.cz'); // $this->connection->setPassword('W7ApxvoihFIr-msQA81hmQ'); /* $this->connection = new Swift_Connection_SMTP('mail.suptech.cz', 465, Swift_Connection_SMTP::ENC_SSL); $this->connection->setUsername('pruzkumy@pharmalink.cz'); $this->connection->setPassword('Btg@x46C');*/ /* $this->connection = new Swift_Connection_SMTP('mail.jakobson.cz', 465, Swift_Connection_SMTP::ENC_SSL); $this->connection->setUsername('smtp_j@jakobson.cz'); $this->connection->setPassword('G5Swxex');*/ // $this->connection = new Swift_Connection_NativeMail(); $this->connection = new Swift_Connection_SMTP('ispc04.suptech.cz', 465, Swift_Connection_SMTP::ENC_SSL); $this->connection->setUsername('podpora@jakobson.cz'); $this->connection->setPassword('MuYsp!4A'); //if(empty($this->emailFrom)) $this->emailFrom = sfConfig::get('app_email_from_email'); //if(empty($this->nameFrom)) $this->nameFrom = sfConfig::get('app_email_from_name'); if(empty($this->emailFrom)) $this->emailFrom = 'podpora@jakobson.cz'; if(empty($this->nameFrom)) $this->nameFrom = 'Agentura Jakobson'; //$this->connType = sfConfig::get('app_email_content-type'); $this->connType = 'text/html'; $this->mailer = new Swift($this->connection); } public function setEmail(){ $this->saveEmail(); $this->sendEmail($this->getEmail()); } public function getEmail() { if(!$this->email instanceof EmailRow) { $this->email = Doctrine::getTable('EmailRow')->createQuery() ->orderBy('id DESC') ->fetchOne(); } return $this->email; } public function sendEmailFromStack(){ $emails = Doctrine::getTable('EmailRow')->createQuery("a")->where("a.sent = 0")->execute(); foreach($emails as $email){ if(strlen($email->email)) { $message = new Swift_Message($email->getSubject(), $email->getText(), $this->connType); $message->attach(new Swift_Message_Part($email->getHtml(), "text/html")); if($this->mailer->send( $message, new Swift_Address($email->getEmail(), $email->getName()), new Swift_Address($this->emailFrom, $this->nameFrom))) { $email->sent = 1; $email->setCountGo(($email->getCountGo()+1)); $email->save(); } else { echo 'CHYBA: email neodeslán -'; } echo $email->email."\n"; } else { sfContext::getInstance()->getLogger()->log('jnEmailFront - CHYBA: prázdná emailová adresa. email_row.id = '.$email->getId()); echo 'CHYBA: prázdná emailová adresa. email_row.id = '.$email->getId()."\n"; } } } private function getText($text){ return strip_tags($text); } public function saveEmail(){ $this->email = new EmailRow(); $this->email->setEmail($this->args['email']); $this->email->setName($this->args['name']); $this->email->setSubject($this->args['subject']); $this->email->setHtml($this->args['html']); $this->email->setText($this->getText($this->args['html'])); $this->email->setCountGo(0); $this->email->setDateInsert(date('Y-m-d H:i:s')); $this->email->save(); } private function sendEmail($email){ $message = new Swift_Message($this->args['subject'], $email->getText(), $this->connType); $message->attach(new Swift_Message_Part($email->getHtml(), "text/html")); if($this->mailer->send( $message, new Swift_Address($email->getEmail(), $email->getName()), new Swift_Address($this->emailFrom, $this->nameFrom))) { $email->sent = 1; } if(is_null($email->getDateFirstGo())) { $email->setDateFirstGo(date('Y-m-d H:i:s')); } $email->setDateLastGo(date('Y-m-d H:i:s')); $email->setCountGo(($email->getCountGo()+1)); $email->save(); } } ?>