Smart.Framework Logo

final class \SmartMailerSmtpClient
{ } ->

Class: SmartMailerSmtpClient - provides the raw communication protocol between PHP and a SMTP server with support for SSL/TLS.
This class is for advanced usage.
It just implements the communication protocol between PHP and a SMTP or ESMTP server.
It does and NOT implement the Mail Send Client or Message Composing.
For a bit more easy use on send emails use the SmartMailerSend class ...


class Methods

public function __construct ( ) {} @ 
SMTP Client Class constructor
public function set_ssl_tls_ca_file ( STRING $cafile ) {} -> VOID
@return: {VOID}
@param: {STRING} $cafile: Relative Path to a SSL Certificate Authority File (Ex: store within smart-framework/etc/certificates ; specify as 'etc/certificates/ca.pem') ; IMPORTANT: in this case the 'etc/certificates/' directory must be protected with a .htaccess to avoid being public readable - the directory and any files within this directory ...)
Set a SSL/TLS Certificate Authority File
If not set but SMART_FRAMEWORK_SSL_CA_FILE is defined will use the SMART_FRAMEWORK_SSL_CA_FILE
public function connect ( STRING $helo, STRING $server, INTEGER+ $port = 25, ENUM $sslversion = "" ) {} -> INTEGER+
@hints: SMTP SUCCESS CODE: 220 ; SMTP FAILURE CODE: 421
@return: {INTEGER+} 1 on success, 0 on fail
@param: {STRING} $helo: The SMTP HELO (server name that is allowed to send mails for this domain) ; Must be set to a real domain host that is valid to send emails for that address ; Ex: 'mail.mydomain.ext'
@param: {STRING} $server: The SMTP server Hostname or IP address
@param: {INTEGER+} $port: *Optional* The SMTP Server Port ; Default is: 25
@param: {ENUM} $sslversion: To connect using SSL mode this must be set to any of these accepted values: '', 'starttls', 'starttls:1.0', 'starttls:1.1', 'starttls:1.2', 'tls', 'tls:1.0', 'tls:1.1', 'tls:1.2', 'ssl', 'sslv3' ; If empty string is set here it will be operate in unsecure mode (NOT using any SSL/TLS Mode)
Will try to open a socket to the specified SMTP Server using the host/ip and port ; If a SSL option is selected will try to establish a SSL socket or fail
public function login ( STRING $username, STRING $pass, ENUM $mode = "" ) {} -> INTEGER+
@hints: SMTP SUCCESS CODES are: 334 OR 235 (final)
@return: {INTEGER+} 1 on Success or 0 on Error
@param: {STRING} $username: The SMTP authentication username
@param: {STRING} $pass: The SMTP authentication password
@param: {ENUM} $mode: *Optional* The authentication mode ; can be set to any of: 'login', 'auth:plain', 'auth:cram-md5', 'auth:xoauth2' ; Default is 'login'
Try a SMTP Authentication with a username and password
Generally this must be run after running the SMTP hello() method
Sends both user and pass to the SMTP server
public function quit ( ) {} -> INTEGER+
@hints: SMTP SUCCESS CODE: 221 ; SMTP ERROR CODE: 500
@return: {INTEGER+} 1 on Success or 0 on Error
Sends the QUIT command to the SMTP server
Closes the communication socket after sending QUIT command
Implemented as RFC 821: QUIT <CRLF>
public function noop ( ) {} -> INTEGER+
@hints: SMTP SUCCESS CODE: 250 ; SMTP ERROR CODE: 500, 421
@return: {INTEGER+} 1 on Success or 0 on Error
Ping the SMTP Server
Sends the command NOOP to the SMTP server
Implemented as RFC 821: NOOP <CRLF>
public function help ( ) {} -> INTEGER+
@hints: SMTP SUCCESS CODE: 211, 214 ; SMTP ERROR CODE: 500, 501, 502, 504, 421
@return: {INTEGER+} 1 on Success or 0 on Error
Help for supported commands on the SMTP Server
Sends the command HELP to the SMTP server.
Implemented as RFC 821: HELP [ <SP> <string> ] <CRLF>
public function reset ( ) {} -> INTEGER+
@hints: SMTP SUCCESS CODE: 250 ; SMTP ERROR CODE: 500, 501, 504, 421
@return: {INTEGER+} 1 on Success or 0 on Error
Sends the RSET command to the SMTP Server to abort any transaction that is currently in progress
Implemented as RFC 821: RSET <CRLF>
public function hello ( $hostname ) {} -> INTEGER+
@hints: SMTP SUCCESS CODE: 250 ; SMTP ERROR CODE: 500, 501, 504, 421
@return: {INTEGER+} 1 on Success (if any of EHLO/HELO is successful) ; 0 on Error (if both EHLO and HELO fail)
Sends the EHLO and/or HELO command to the SMTP Server
First will try the extended SMTP feature by sending EHLO. If EHLO is not successful will try HELO
This makes sure that the client and the server are in the same known state.
Implemented as RFC 821: EHLO <SP> <domain> <CRLF> / HELO <SP> <domain> <CRLF>
public function verify ( STRING $name ) {} -> INTEGER+
@hints: SMTP SUCCESS CODE: 250, 251 ; SMTP FAIL CODE: 550, 551, 553 ; SMTP ERROR CODE: 500, 501, 502, 421
@return: {INTEGER+} 1 on Success or 0 on Error
@param: {STRING} $name: The recipient name to be verified ; Ex: name@domain.ext
Verifies if the given recipient name is recognized by the SMTP server
Implemented as RFC 821: VRFY <SP> <string> <CRLF>
public function expand ( STRING $name ) {} -> INTEGER+
@hints: SMTP SUCCESS CODE: 250 ; SMTP FAIL CODE: 550 ; SMTP ERROR CODE: 500, 501, 502, 504, 421
@return: {INTEGER+} 1 on Success or 0 on Error
@param: {STRING} $name: The recipient name to be expanded ; Ex: mail-list@domain.ext
Expand takes the recipient name and asks the server to list all the recipients who are members of the _list_
SMTP Expand will return back an empty string for error and the reply with reply lines ended by [CRLF]
Each value in the array returned has the format of: [ <full-name> <sp> ] <path>
The definition of <path> is defined in RFC 821
Implemented as RFC 821: EXPN <SP> <string> <CRLF>
public function mail ( STRING $from ) {} -> INTEGER+
@hints: SMTP SUCCESS CODE: 250 ; SMTP FAIL CODE: 552, 451, 452 ; SMTP ERROR CODE: 500, 501, 421
@return: {INTEGER+} 1 on Success or 0 on Error
@param: {STRING} $from: The originating email recipient ; Ex: me@my-email.ext
Starts a send mail (message) transaction originating from the email address specified in $from recipient name on the SMTP Server
If this command is successful then the mail transaction is started and then one or more Recipient commands may be called followed by a Data command
Implemented as RFC 821: MAIL <SP> FROM:<reverse-path> <CRLF>
public function recipient ( STRING $to ) {} -> INTEGER+
@hints: SMTP SUCCESS CODE: 250, 251 ; SMTP FAIL CODE: 550, 551, 552, 553, 450, 451, 452 ; SMTP ERROR CODE: 500, 501, 503, 421
@return: {INTEGER+} 1 on Success or 0 on Error
@param: {STRING} $to: The destination email recipient (or email list) ; Ex: destination@your-email.ext
Sends the command RCPT to the SMTP server with the TO: argument of $to.
Implemented as RFC 821: RCPT <SP> TO:<forward-path> <CRLF>
public function data_send ( STRING $msg_data ) {} -> INTEGER+
@hints: [ Intermediate codes for {data} <CRLF>.<CRLF> are: SMTP INTERMEDIATE CODE: 354 ; SMTP CODE SUCCESS: 250 ; SMTP CODE FAILURE: 552,554,451,452 ] ; [ Final Transaction codes are: SMTP SUCCESS CODE: 250 ; SMTP FAIL CODE: 451, 554 ; SMTP ERROR CODE: 500, 501, 503, 421 ]
@return: {INTEGER+} 1 on Success or 0 on Error
@param: {STRING} $msg_data: The message data (headers + body) to be sent to the SMTP Server
Initiates a data command on the SMTP Server and sends the $msg_data to the server finalizing the mail transaction started with mail($from) and followed by recipient($to)
The $msg_data as data is the message that is to be send together with the message headers
Each header line (if any) needs to be on a single line followed by a <CRLF>
After headers the mail message body have to be appended and being separated by and additional <CRLF>
Implemented as RFC 821: DATA <CRLF>

class Properties

public $timeout = 30 ;  -> INTEGER+
socket timeout in seconds
public $debug = FALSE ;  -> BOOLEAN
to debug or not
public $dbglevel = 1 ;  -> ENUM
debug level (1 or 2)
public $error = '' ;  -> STRING
collects the error message(s)
public $log = '' ;  -> STRING
if debug is enabled will collect the send log(s)

class Constants



documentation generated on: 2023-10-19 23:15:46 +0000


Smart.Framework © 2009-2023 unix-world.org