Overview

Namespaces

  • Avisota
    • Event
    • Message
    • Queue
    • Recipient
    • RecipientSource
    • Renderer
    • Templating
    • Test
      • Database
      • Imap
      • Message
      • Queue
      • Renderer
      • Transport
    • Transport

Classes

  • AbstractSwiftTransport
  • AbstractTransport
  • QueueTransport
  • SmtpTransport
  • SwiftTransport
  • TransportStatus

Interfaces

  • TransportInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: 
  3: /**
  4:  * Avisota newsletter and mailing system
  5:  *
  6:  * PHP Version 5.3
  7:  *
  8:  * @copyright  bit3 UG 2013
  9:  * @author     Tristan Lins <tristan.lins@bit3.de>
 10:  * @package    avisota-core
 11:  * @license    LGPL-3.0+
 12:  * @link       http://avisota.org
 13:  */
 14: 
 15: namespace Avisota\Transport;
 16: 
 17: use Avisota\Renderer\MessageRendererInterface;
 18: 
 19: /**
 20:  * Transport using swift smtp transport.
 21:  *
 22:  * @package avisota-core
 23:  */
 24: class SmtpTransport extends AbstractSwiftTransport
 25: {
 26:     /**
 27:      * @var string
 28:      */
 29:     protected $host;
 30: 
 31:     /**
 32:      * @var int
 33:      */
 34:     protected $port;
 35: 
 36:     /**
 37:      * @var string
 38:      */
 39:     protected $username;
 40: 
 41:     /**
 42:      * @var string
 43:      */
 44:     protected $password;
 45: 
 46:     /**
 47:      * @var "ssl"|"tls"
 48:      */
 49:     protected $encryption;
 50: 
 51:     /**
 52:      * @var \Swift_Mailer|null
 53:      */
 54:     protected $swiftMailer;
 55: 
 56:     /**
 57:      * @param string $host
 58:      * @param null   $port
 59:      * @param null   $username
 60:      * @param null   $password
 61:      * @param null   $encryption
 62:      *
 63:      * @return SmtpTransport
 64:      */
 65:     public function __construct(
 66:         $host = 'localhost',
 67:         $port = null,
 68:         $username = null,
 69:         $password = null,
 70:         $encryption = null,
 71:         MessageRendererInterface $renderer
 72:     ) {
 73:         $this->host       = $host;
 74:         $this->port       = $port;
 75:         $this->username   = $username;
 76:         $this->password   = $password;
 77:         $this->encryption = $encryption;
 78:         $this->setRenderer($renderer);
 79:     }
 80: 
 81:     /**
 82:      * @param string $host
 83:      */
 84:     public function setHost($host)
 85:     {
 86:         $this->host = $host;
 87:         $this->resetMailer();
 88:         return $this;
 89:     }
 90: 
 91:     /**
 92:      * @return string
 93:      */
 94:     public function getHost()
 95:     {
 96:         return $this->host;
 97:     }
 98: 
 99:     /**
100:      * @param int $port
101:      */
102:     public function setPort($port)
103:     {
104:         $this->port = $port;
105:         $this->resetMailer();
106:         return $this;
107:     }
108: 
109:     /**
110:      * @return int
111:      */
112:     public function getPort()
113:     {
114:         return $this->port;
115:     }
116: 
117:     /**
118:      * @param string $username
119:      */
120:     public function setUsername($username)
121:     {
122:         $this->username = $username;
123:         $this->resetMailer();
124:         return $this;
125:     }
126: 
127:     /**
128:      * @return string
129:      */
130:     public function getUsername()
131:     {
132:         return $this->username;
133:     }
134: 
135:     /**
136:      * @param string $password
137:      */
138:     public function setPassword($password)
139:     {
140:         $this->password = $password;
141:         $this->resetMailer();
142:         return $this;
143:     }
144: 
145:     /**
146:      * @return string
147:      */
148:     public function getPassword()
149:     {
150:         return $this->password;
151:     }
152: 
153:     /**
154:      * @param string $encryption
155:      */
156:     public function setEncryption($encryption)
157:     {
158:         $encryption = strtolower($encryption);
159:         if ($encryption != 'ssl' && $encryption != 'tls') {
160:             $encryption = null;
161:         }
162:         $this->encryption = $encryption;
163:         $this->resetMailer();
164:         return $this;
165:     }
166: 
167:     /**
168:      * @return string
169:      */
170:     public function getEncryption()
171:     {
172:         return $this->encryption;
173:     }
174: 
175:     /**
176:      * @return \Swift_Mailer
177:      */
178:     protected function createMailer()
179:     {
180:         $transport = new \Swift_SmtpTransport($this->host);
181:         if ($this->port) {
182:             $transport->setPort($this->port);
183:         }
184:         if ($this->username) {
185:             $transport->setUsername($this->username);
186:         }
187:         if ($this->password) {
188:             $transport->setPassword($this->password);
189:         }
190:         if ($this->encryption) {
191:             $transport->setEncryption($this->encryption);
192:         }
193: 
194:         return \Swift_Mailer::newInstance($transport);
195:     }
196: }
197: 
avisota/core API documentation generated by ApiGen 2.8.0