SMTP has STARTTLS extension example from https://bugs.php.net/bug.php?id=36445 (Note, for non-blocking, it may return 0. keep on calling until a result is true or false) # !/usr/bin/php5 <?php // Hello World! SMTP TLS Server // Tested on PHP 5.1.2-1+b1 (cli) (built: Mar 20 2006 04:17:24) $context = stream_context_create(); // local_cert must be in PEM format stream_context_set_option($context, 'ssl', 'local_cert', './server.pem'); // Pass Phrase (password) of private key stream_context_set_option($context, 'ssl', 'passphrase', 'comet'); stream_context_set_option($context, 'ssl', 'allow_self_signed', true); stream_context_set_option($context, 'ssl', 'verify_peer', false); // Create the server socket $server = stream_socket_server('tcp://0.0.0.0:9001', $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context); while(1){ if($client=stream_socket_accept($server)){ @fwrite($client,"220 ESMTP\r\n"); @fwrite($client,"250 STARTTLS\r\n"); ``` // Client should now send STARTTLS echo "1: " . @fgets($client); // We start the SSL Channel stream_socket_enable_crypto($client,true,STREAM_CRYPTO_METHOD_TLS_SERVER); echo "Error (if any): ".openssl_error_string()."\n"; @fwrite($client,"220 ESMTP\r\n"); echo "2: " . @fgets($client); } ``` } ?>
SMTP has STARTTLS extension
example from https://bugs.php.net/bug.php?id=36445
(Note, for non-blocking, it may return 0. keep on calling until a result is true or false)
!/usr/bin/php5