You've patched this at the transport level; while that will work, it's
architecturally incorrect.
STARTTLS is a protocol level thing, so you code would be better suited
as a wrapper.
You can implement wrappers in user-space
(http://www.php.net/manual/en/function.stream-register-wrapper.php),
so you
Attached is a patch to enable (SIEVE) STARTTLS support for fsockopen
using stls://host.example.org
I'm pretty sure I've got it to conform to the RFC:
http://www.holtmann.org/email/sieve/draft-martin-managesieve-03.txt
Currently it only works with SIEVE, but it could be easily extended to
do SMTP