Details
Description
Granted I am sorta a php newbie... I need Authenication in the smtp transport. I played around with the smtp file and came up with this that I use now.
Is there any problem doing this?
$tr = new Zend_Mail_Transport_Smtp('mail.host.com', 25, '127.0.0.1', 'username', 'passwd');
then in the Zend/Mail/Transport/Smtp.php
/**
* Constructor.
*
* @param string $host
* @param int $port
* @param string $myName (for use with HELO)
* @param string $username
* @param string $passwd
*/
public function __construct($host = '127.0.0.1', $port=25, $myName='127.0.0.1', $username=null, $passwd=null)
{
$this->_host = $host;
$this->_port = $port;
$this->_myName = $myName;
////
$this->_username = $username;
$this->_passwd = $passwd;
////
}
/**
* Connect to the server with the parameters given
* in the constructor and send "HELO". The connection
* is immediately closed if an error occurs.
*
* @throws Zend_Mail_Transport_Exception
*/
public function connect()
{
$errno = null;
$errstr = null;
// open connection
$fp = stream_socket_client('tcp://'.$this->_host.':'.$this->_port, $errno, $errstr, self::CONNECTION_TIMEOUT);
if ($fp===false) {
if ($errno==0) {
$msg = 'Could not open socket';
} else {
$msg = $errstr;
}
throw new Zend_Mail_Transport_Exception($msg);
}
$this->_con = $fp;
try {
$res = stream_set_timeout($this->_con, self::COMMUNICATION_TIMEOUT );
if ($res === false) {
throw new Zend_Mail_Transport_Exception('Could not set Stream Timeout');
}
/**
* Now the connection is open. Wait for the welcome message:
* welcome message has error code 220
*/
$this->_expect(220);
$this->helo($this->_myName);
///////
if (isset($this->_username)) $this->authenticate($this->_username, $this->_passwd);
///////
} catch (Zend_Mail_Transport_Exception $e) {
fclose($fp);
throw $e;
}
}
/**
* Sends AUTH to the server and validates the response. If valid, username is sent to the
* server and validates the response. If valid, password is sent to the server and validates
* the response.
*
* @param string $username
* @param string $passwd
* @throws Zend_Mail_Transport_Exception
*/
public function authenticate($username, $passwd)
{
$this->_send('AUTH LOGIN');
$this->_expect(334);
$this->_send(base64_encode($username));
$this->_expect(334);
$this->_send(base64_encode($passwd));
$this->_expect(235);
}
Scheduling for 0.7.0 release.