PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/application/models/Mail.php

https://github.com/besters/My-Base
PHP | 127 lines | 60 code | 16 blank | 51 comment | 0 complexity | ca8e92562011b672446a9d8594568810 MD5 | raw file
  1. <?php
  2. /**
  3. * Trida na generovani a posilani emailu
  4. */
  5. class Model_Mail
  6. {
  7. /**
  8. * View objekt
  9. * @var Zend_View
  10. */
  11. private $_view;
  12. /**
  13. * Mail objekt
  14. * @var Zend_Mail
  15. */
  16. private $_mail;
  17. /**
  18. * Vyrenderovana sablona
  19. * @var string
  20. */
  21. private $_bodyText;
  22. /**
  23. * Data do sablony
  24. * @var array
  25. */
  26. private $_data;
  27. const INVITE = '1';
  28. /**
  29. * Pripravi data a dalsi promenne
  30. *
  31. * @param array $data Data na vyplneni do sablony emailu
  32. * @return Model_Mail
  33. */
  34. public function prepare($data)
  35. {
  36. $this->_view = new Zend_View();
  37. $this->_view->setScriptPath(APP_PATH . '/modules/mybase/views/scripts/emails/');
  38. $this->_mail = new Zend_Mail('utf-8');
  39. $this->_data = $data;
  40. return $this;
  41. }
  42. /**
  43. * Generuje email
  44. *
  45. * @param const $type Typ emailu
  46. * @return Model_Mail
  47. */
  48. public function generate($type)
  49. {
  50. switch($type){
  51. case self::INVITE :
  52. $this->_invite();
  53. break;
  54. }
  55. return $this;
  56. }
  57. /**
  58. * Odesle E-mail
  59. *
  60. * @param string $recipient E-mail prijemce
  61. */
  62. public function send($recipient)
  63. {
  64. $smtpOptions = array(
  65. 'auth' => 'login',
  66. 'username' => 'mybase.unodor@gmail.com',
  67. 'password' => 'opticau51',
  68. 'ssl' => 'ssl',
  69. 'port' => 465
  70. );
  71. $mailTransport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $smtpOptions);
  72. $this->_mail->setBodyHtml($this->_bodyText);
  73. $this->_mail->addTo($recipient);
  74. $this->_mail->send($mailTransport);
  75. }
  76. /**
  77. * Nastavi odesilatele
  78. *
  79. * @param string $senderMail e-mail odesilatele
  80. * @param string $senderName jmeno odesilatele
  81. *
  82. * @return Model_Mail
  83. */
  84. public function from($senderMail, $senderName = 'MyBase.cz')
  85. {
  86. $this->_mail->setFrom($senderMail, $senderName);
  87. return $this;
  88. }
  89. /**
  90. * Generuje uvitaci email
  91. *
  92. * @return Model_Mail
  93. *
  94. * @todo neni kompletni
  95. */
  96. private function _invite()
  97. {
  98. $salt = 'ofsdmší&;516#@ešěýp-§)údjs861fds';
  99. $session = new Zend_Session_Namespace('Zend_Auth');
  100. $this->_view->assign('company', '***COMPANY***');
  101. $this->_view->assign('name', $this->_data['name']);
  102. $this->_view->assign('sender', $session->storage->name . ' ' . $session->storage->surname);
  103. $this->_view->assign('hash', md5($this->_data['idcompany'] . $this->_data['name'] . $this->_data['surname'] . $this->_data['email'] . $salt));
  104. $this->_view->assign('note', nl2br($this->_data['note']), true);
  105. $this->_view->assign('mail', $session->storage->email);
  106. $this->_mail->setSubject('[MyBase.cz] Your account has been created **ALPHA**');
  107. $this->from('invite@mybase.cz');
  108. $this->_bodyText = $this->_view->render('invite.phtml');
  109. return $this;
  110. }
  111. }