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 ...
Language: PHP
Located at: lib/framework/plugins/lib_mail_send.php
Package: Plugins:Mailer
Namespace: \
Class Name: SmartMailerSmtpClient
Version: v.20221223
Depends: classes: Smart
Usage: dynamic object: (new Class())->method() - This class provides only DYNAMIC methods
@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
@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
@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
publicfunctionquit (
) {} -> 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>
publicfunctionnoop (
) {} -> 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>
publicfunctionhelp (
) {} -> 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>
publicfunctionreset (
) {} -> 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>
publicfunctionhello (
$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>
@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>
publicfunctionmail (
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>
@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
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 ...