Flourish PHP Unframework

fSMTP

class, v1.0.0b11

Creates a connection to an SMTP server to be used by fEmail

Changes:
1.0.0b11Enhanced the error checking for write() 6/3/11
1.0.0b10Added code to work around PHP bug #42682 (http://bugs.php.net/bug.php?id=42682) where stream_select() doesn't work on 64bit machines from PHP 5.2.0 to 5.2.5, improved timeouts while reading data 1/10/11
1.0.0b9Fixed a bug where lines starting with . and containing other content would have the . stripped 9/11/10
1.0.0b8Updated the class to use fEmail::getFQDN() 9/7/10
1.0.0b7Updated class to use new fCore::startErrorCapture() functionality 8/9/10
1.0.0b6Updated the class to use new fCore functionality 7/5/10
1.0.0b5Hacked around a bug in PHP 5.3 on Windows 6/22/10
1.0.0b4Updated the class to not connect and authenticate until a message is sent, moved message id generation in fEmail 5/5/10
1.0.0b3Fixed a bug with connecting to servers that send an initial response of 220- and instead of 220 4/26/10
1.0.0b2Fixed a bug where STARTTLS would not be triggered if it was last in the SMTP server's list of supported extensions 4/20/10
1.0.0bThe initial implementation 4/20/10

Methods

->__construct() public

Configures the SMTP connection

The SMTP connection is only made once authentication is attempted or an email is sent.

Please note that this class will upgrade the connection to TLS via the SMTP STARTTLS command if possible, even if a secure connection was not requested. This helps to keep authentication information secure.

Signature

fSMTP __construct( string $host, integer $port=NULL, boolean $secure=FALSE, integer $timeout=NULL )

Parameters

string $host The hostname or IP address to connect to
integer $port The port number to use
boolean $secure If the connection should be secure - if STARTTLS is available, the connection will be upgraded even if this is FALSE
integer $timeout The timeout for the connection - defaults to the default_socket_timeout ini setting

->__destruct() public

Closes the connection to the SMTP server

Signature

void __destruct( )

->__get() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

All requests that hit this method should be requests for callbacks

Signature

callback __get( string $method )

Parameters

string $method The method to create a callback for

Returns

The callback for the method requested

->authenticate() public

Authenticates with the SMTP server

This method supports the digest-md5, cram-md5, login and plain SMTP authentication methods. This method will try to use the more secure digest-md5 and cram-md5 methods first since they do not send information in the clear.

Signature

void authenticate( string $username, string $password )

Parameters

string $username The username
string $password The password

Throws

fValidationException
When the $username and $password are not accepted

->close() public

Closes the connection to the SMTP server

Signature

void close( )

->enableDebugging() public

Sets if debug messages should be shown

Signature

void enableDebugging( boolean $flag )

Parameters

boolean $flag If debugging messages should be shown

->send() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Sends a message via the SMTP server

Signature

void send( string $from [, ... ], string $headers, string $body )

Parameters

string $from The email address being sent from - this will be used as the Return-Path header
array $to All of the To, Cc and Bcc email addresses to send the message to - this does not affect the message headers in any way
string $headers The message headers - the Bcc header will be removed if present
string $body The mail body

Throws

fValidationException
When the message is too large for the server