3 * @see https://github.com/zendframework/zend-mail for the canonical source repository
4 * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-mail/blob/master/LICENSE.md New BSD License
8 namespace Zend\Mail\Protocol\Smtp\Auth
;
10 use Zend\Mail\Protocol\Smtp
;
13 * Performs LOGIN authentication
15 class Login
extends Smtp
34 * @param string $host (Default: 127.0.0.1)
35 * @param int $port (Default: null)
36 * @param array $config Auth-specific parameters
38 public function __construct($host = '127.0.0.1', $port = null, $config = null)
40 // Did we receive a configuration array?
41 $origConfig = $config;
42 if (is_array($host)) {
43 // Merge config array with principal array, if provided
44 if (is_array($config)) {
45 $config = array_replace_recursive($host, $config);
51 if (is_array($config)) {
52 if (isset($config['username'])) {
53 $this->setUsername($config['username']);
55 if (isset($config['password'])) {
56 $this->setPassword($config['password']);
60 // Call parent with original arguments
61 parent
::__construct($host, $port, $origConfig);
65 * Perform LOGIN authentication with supplied credentials
68 public function auth()
70 // Ensure AUTH has not already been initiated.
73 $this->_send('AUTH LOGIN');
75 $this->_send(base64_encode($this->getUsername()));
77 $this->_send(base64_encode($this->getPassword()));
83 * Set value for username
85 * @param string $username
88 public function setUsername($username)
90 $this->username
= $username;
99 public function getUsername()
101 return $this->username
;
105 * Set value for password
107 * @param string $password
110 public function setPassword($password)
112 $this->password
= $password;
121 public function getPassword()
123 return $this->password
;