smtp class SMTP4PHP.php HELP needed

smtp class SMTP4PHP.php --HELP needed-- (sourceforge.php SMTP4PHP.php-2011-release.zip)
Throws following error, which I don’t understand – can someone help me with its iterpretation? :

Fatal error: Uncaught exception ‘ErrorException’ with message ‘stream_socket_client() [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol’ in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/SMTP4PHP.php:722 Stack trace: #0 [internal function]: exception_error_handler(2, ‘stream_socket_c…’, ‘/home/vg011web0…’, 722, Array) #1 /home/vg011web00/68/65/2926568/web/auxlib/usit2013/SMTP4PHP.php(722): stream_socket_client(‘ssl://smtp.u-si…’, 0, ‘’, 30, 5) #2 /home/vg011web00/68/65/2926568/web/auxlib/usit2013/SMTP4PHP.php(751): SMTP4PHP\SMTP->_connect() #3 /home/vg011web00/68/65/2926568/web/auxlib/usit2013/usage-exmpl-2.php(84): SMTP4PHP\SMTP->send(Object(SMTP4PHP\eMail)) #4 {main} thrown in /home/vg011web00/68/65/2926568/web/auxlib/usit2013/SMTP4PHP.php on line 722
------------------------ my test script (came with SMTP4PHP.php) ----------------------------------------------------

[php]
require_once($_SERVER[‘DOCUMENT_ROOT’].’/auxlib/usit2013/SMTP4PHP.php’);
define(‘DISPLAY_ERRORS’, true);
define(‘DISPLAY_EXCEPTIONS’, true);
set_time_limit(0);
ini_set(‘memory_limit’,-1);
ini_set(‘max_execution_time’,0);
ini_set(‘ignore_user_abort’,‘On’);
ini_set(‘display_errors’, (DISPLAY_ERRORS)?(1):(0));
ini_set(‘display_startup_errors’, (DISPLAY_ERRORS)?(1):(0));
error_reporting((DISPLAY_ERRORS)?(1):(0));
ignore_user_abort (true);
date_default_timezone_set(‘America/New_York’);
// Copyright © 2011 - 2012, Raul IONESCU [email protected],Bucharest, ROMANIA
/*
GMail - TLS encryption example

define(‘SMTP_SERVER’,‘tls://smtp.gmail.com’);
define(‘SMTP_SERVER_PORT’,587);

GMail - SSL encryption example

define(‘SMTP_SERVER’,‘ssl://smtp.gmail.com’);
define(‘SMTP_SERVER_PORT’,465);
Yahoo Mail - SSL encryption example

define(‘SMTP_SERVER’,‘ssl://smtp.mail.yahoo.com’);
define(‘SMTP_SERVER_PORT’,465);
Windows Live.com - TLS encryption example

define(‘SMTP_SERVER’,‘tls://smtp.live.com’);
define(‘SMTP_SERVER_PORT’,587);
/
define(‘SMTP_SERVER’,‘ssl://smtp.u-sit.net’);
define(‘SMTP_SERVER_PORT’, 587); //25 or 587
define(‘SMTP_USER’,‘[email protected]’);
define(‘SMTP_PASSWORD’,‘xxxxx’);
define(‘FROM_NAME’,‘usit’);
define(‘FROM_EMAIL’,‘[email protected]’);
use SMTP4PHP\User;
/

//NOTE: Only if backward compatibility is really needed.
//use SMTP4PHP\eMailUser;
*/
use SMTP4PHP\eMailUser;
use SMTP4PHP\eMail;
use SMTP4PHP\SMTP;
$e = new eMail();
$e->from = new User(FROM_NAME, FROM_EMAIL);
$e->to = new User(FROM_NAME, FROM_EMAIL);
$e->subject = ‘SMTP4PHP Test mail’;

// EXAMPLE: add inline image example
$e->htmlMessage = ‘This is a HTML message!
’;
echo 'L.80

';
$e->txtMessage = ‘This is a TEXT message from usage-exmpl-2.php!’;
// EXAMPLE: add attachment example
$e->addAttachment(‘Attachment.zip’);
$smtp = new SMTP(SMTP_SERVER, SMTP_SERVER_PORT, SMTP_USER, SMTP_PASSWORD);
/* NOTE: ALL emails are sent through the same connection, speeding up transmission. /
echo $smtp->send($e) ? 'Mail sent!

’ : 'Mail failed!

';
try {
$smtp->send($e);
} //

OR $smtp->send($e,$e2);*/ }
catch(Exception $e) { }

var_dump($smtp->SMTPlog);
[/php]

Have you tried using port 465 instead of 587?

It throws the same error.

Thanks for your usual interest w@tt.

usit

More information. SMTP4PHP.php is much too large for the file-size limits in reply boxes. I had wanted to include it here. So I’m sending a small snippet that shows how stream_socket_client is built in SMTP4PHP. This is the only place it’s mentioned in the class definition and this is where the error is thrown.

[php] protected function _connect()
{
if(empty($this->smtpConnect)) //ERROR THROWN HERE {
$this->smtpConnect = stream_socket_client((($this->encryption == self::ENCRYPTION_SSL)?($this->encryption):(‘tcp’)).’://’.$this->SMTPserver.(($this->SMTPport)?(’:’.$this->SMTPport):(’’)), $errno, $errstr, $this->SMTPconnectionTimeout, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT);
if(empty($this->smtpConnect)) { throw new Exception(‘SMTP connection error!’.($errstr)?(’ (’.$errstr.’)’):(’’)); }
stream_set_blocking($this->smtpConnect, true);

             $smtpResponse = trim($this->_read());
             $xxLO = ($this->esmtp = (stripos($smtpResponse,'ESMTP') !== FALSE))?('EHLO'):('HELO'); 
             $smtpResponse = trim($this->_exec($xxLO.' '.$this->ip,'250'));

             if($this->encryption == self::ENCRYPTION_TLS)
                    {
                     $this->_exec('STARTTLS','220');
                     if(!stream_socket_enable_crypto($this->smtpConnect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { throw new Exception('Unexpected TLS encryption error!'); }
                    }
                    
             $this->_authenticate($smtpResponse);
            }        
      }[/php]

I’m new enough to OOP that I’m confused by the different ways objects are named in the test script and in this class definition; e.g., with and without underscores used to divide/or not divide a name…

Unfortunately I don’t think I can help with this one. From what I found on Google I would say check that your SSL versions are compatible. E.g. SSL23 vs SSL3 (I also can’t help with this, this is more of a sys admin type of thing. Try contacting your host?)

Thanks w@tt,
I’ve sent a query to my ISP system administrator.
usit

Sponsor our Newsletter | Privacy Policy | Terms of Service