PHPMailer RFC821 SMTP email transport class. Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.
Methods | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
protected
|
edebug(string $str, integer $level = 0): void
Output debugging info via a user-selected method.
Output debugging info via a user-selected method. Parameters
|
# | ||||||||||||
public
|
connect(string $host, integer $port = null, integer $timeout = 30, array $options = []): boolean
Connect to an SMTP server.
Connect to an SMTP server. Parameters
|
# | ||||||||||||
public
|
startTLS(): boolean
Initiate a TLS (encrypted) session.
Initiate a TLS (encrypted) session. |
# | ||||||||||||
public
|
authenticate(
string $username,
string $password,
string $authtype = null,
string $realm = '',
string $workstation = '',
null|OAuth $OAuth = null,
): bool
Perform SMTP authentication.
Must be run after hello().
Perform SMTP authentication. Must be run after hello(). Parameters
ReturnsTrue if successfully authenticated.* @access public |
# | ||||||||||||
protected
|
hmac(string $data, string $key): string
Calculate an MD5 HMAC hash.
Works like hash_hmac('md5', $data, $key)
in case that function is not available
Calculate an MD5 HMAC hash. Works like hash_hmac('md5', $data, $key) in case that function is not available Parameters
|
# | ||||||||||||
public
|
connected(): boolean
Check connection state.
Check connection state. ReturnsTrue if connected. |
# | ||||||||||||
public
|
close(): void
Close the socket and clean up the state of the class.
Don't use this function without first trying to use QUIT.
Close the socket and clean up the state of the class. Don't use this function without first trying to use QUIT. |
# | ||||||||||||
public
|
data(string $msg_data): boolean
Send an SMTP DATA command.
Issues a data command and sends the msg_data to the server,
finializing the mail transaction…
Send an SMTP DATA command. Issues a data command and sends the msg_data to the server, finializing the mail transaction. $msg_data is the message that is to be send with the headers. Each header needs to be on a single line followed by a <CRLF> with the message headers and the message body being separated by and additional <CRLF>. Implements rfc 821: DATA <CRLF> Parameters
|
# | ||||||||||||
public
|
hello(string $host = ''): boolean
Send an SMTP HELO or EHLO command.
Used to identify the sending server to the receiving server.
This makes sure that…
Send an SMTP HELO or EHLO command.
Used to identify the sending server to the receiving server.
This makes sure that client and server are in a known state.
Implements RFC 821: HELO <SP> Parameters
|
# | ||||||||||||
protected
|
sendHello(string $hello, string $host): boolean
Send an SMTP HELO or EHLO command.
Low-level implementation used by hello()
Send an SMTP HELO or EHLO command. Low-level implementation used by hello() Parameters
|
# | ||||||||||||
protected
|
parseHelloFields(string $type)
Parse a reply to HELO/EHLO command to discover server extensions.
In case of HELO, the only parameter that can be…
Parse a reply to HELO/EHLO command to discover server extensions. In case of HELO, the only parameter that can be discovered is a server name. Parameters
|
# | ||||||||||||
public
|
mail(string $from): boolean
Send an SMTP MAIL command.
Starts a mail transaction from the email address specified in
$from. Returns true if…
Send an SMTP MAIL command.
Starts a mail transaction from the email address specified in
$from. Returns true if successful or false otherwise. If True
the mail transaction is started and then one or more recipient
commands may be called followed by a data command.
Implements rfc 821: MAIL <SP> FROM: Parameters
|
# | ||||||||||||
public
|
quit(boolean $close_on_error = true): boolean
Send an SMTP QUIT command.
Closes the socket if there is no error or the $close_on_error argument is true.
Implements…
Send an SMTP QUIT command. Closes the socket if there is no error or the $close_on_error argument is true. Implements from rfc 821: QUIT <CRLF> Parameters
|
# | ||||||||||||
public
|
recipient(string $address): boolean
Send an SMTP RCPT command.
Sets the TO argument to $toaddr.
Returns true if the recipient was accepted false if it was…
Send an SMTP RCPT command.
Sets the TO argument to $toaddr.
Returns true if the recipient was accepted false if it was rejected.
Implements from rfc 821: RCPT <SP> TO: Parameters
|
# | ||||||||||||
public
|
reset(): boolean
Send an SMTP RSET command.
Abort any transaction that is currently in progress.
Implements rfc 821: RSET <CRLF>
Send an SMTP RSET command. Abort any transaction that is currently in progress. Implements rfc 821: RSET <CRLF> ReturnsTrue on success. |
# | ||||||||||||
protected
|
sendCommand(string $command, string $commandstring, integer|array $expect): boolean
Send a command to an SMTP server and check its return code.
Send a command to an SMTP server and check its return code. Parameters
ReturnsTrue on success. |
# | ||||||||||||
public
|
sendAndMail(string $from): boolean
Send an SMTP SAML command.
Starts a mail transaction from the email address specified in $from.
Returns true if…
Send an SMTP SAML command.
Starts a mail transaction from the email address specified in $from.
Returns true if successful or false otherwise. If True
the mail transaction is started and then one or more recipient
commands may be called followed by a data command. This command
will send the message to the users terminal if they are logged
in and send them an email.
Implements rfc 821: SAML <SP> FROM: Parameters
|
# | ||||||||||||
public
|
verify(string $name): boolean
Send an SMTP VRFY command.
Send an SMTP VRFY command. Parameters
|
# | ||||||||||||
public
|
noop(): boolean
Send an SMTP NOOP command.
Used to keep keep-alives alive, doesn't actually do anything
Send an SMTP NOOP command. Used to keep keep-alives alive, doesn't actually do anything |
# | ||||||||||||
public
|
turn(): boolean
Send an SMTP TURN command.
This is an optional command for SMTP that this class does not support.
This method is here…
Send an SMTP TURN command. This is an optional command for SMTP that this class does not support. This method is here to make the RFC821 Definition complete for this class and may be implemented in future Implements from rfc 821: TURN <CRLF> |
# | ||||||||||||
public
|
client_send(string $data): integer|boolean
Send raw data to the server.
Send raw data to the server. Parameters
ReturnsThe number of bytes sent to the server or false on error |
# | ||||||||||||
public
|
getError(): array
Get the latest error.
Get the latest error. |
# | ||||||||||||
public
|
getServerExtList(): array|null
Get SMTP extensions available on the server
Get SMTP extensions available on the server |
# | ||||||||||||
public
|
getServerExt(string $name): mixed
A multipurpose method
The method works in three ways, dependent on argument value and current state
1. HELO/EHLO was…
A multipurpose method The method works in three ways, dependent on argument value and current state
Parameters
|
# | ||||||||||||
public
|
getLastReply(): string
Get the last reply from the server.
Get the last reply from the server. |
# | ||||||||||||
protected
|
get_lines(): string
Read the SMTP server's response.
Either before eof or socket timeout occurs on the operation.
With SMTP we can tell if…
Read the SMTP server's response. Either before eof or socket timeout occurs on the operation. With SMTP we can tell if we have more lines to read if the 4th character is '-' symbol. If it is a space then we don't need to read anything else. |
# | ||||||||||||
public
|
setVerp(boolean $enabled = false)
Enable or disable VERP address generation.
Enable or disable VERP address generation. |
# | ||||||||||||
public
|
getVerp(): boolean
Get VERP address generation mode.
Get VERP address generation mode. |
# | ||||||||||||
protected
|
setError(string $message, string $detail = '', string $smtp_code = '', string $smtp_code_ex = '')
Set error messages and codes.
Set error messages and codes. Parameters
|
# | ||||||||||||
public
|
setDebugOutput(string|callable $method = 'echo')
Set debug output method.
Set debug output method. Parameters
|
# | ||||||||||||
public
|
getDebugOutput(): string
Get debug output method.
Get debug output method. |
# | ||||||||||||
public
|
setDebugLevel(integer $level = 0)
Set debug output level.
Set debug output level. |
# | ||||||||||||
public
|
getDebugLevel(): integer
Get debug output level.
Get debug output level. |
# | ||||||||||||
public
|
setTimeout(integer $timeout = 0)
Set SMTP timeout.
Set SMTP timeout. |
# | ||||||||||||
public
|
getTimeout(): integer
Get SMTP timeout.
Get SMTP timeout. |
# | ||||||||||||
protected
|
errorHandler(integer $errno, string $errmsg, string $errfile = '', integer $errline = 0)
Reports an error number and string.
Reports an error number and string. Parameters
|
# | ||||||||||||
protected
|
recordLastTransactionID(): bool|null|string
Extract and return the ID of the last SMTP transaction based on
a list of patterns provided in SMTP::$smtp_transaction…
Extract and return the ID of the last SMTP transaction based on a list of patterns provided in SMTP::$smtp_transaction_id_patterns. Relies on the host providing the ID in response to a DATA command. If no reply has been received yet, it will return null. If no pattern was matched, it will return false. |
# | ||||||||||||
public
|
getLastTransactionID(): bool|null|string
Get the queue/transaction ID of the last SMTP transaction
If no reply has been received yet, it will return null.
If no…
Get the queue/transaction ID of the last SMTP transaction If no reply has been received yet, it will return null. If no pattern was matched, it will return false. |
# |
Constants | ||
---|---|---|
public
|
VERSION = '5.2.28'
The PHPMailer SMTP version number.
The PHPMailer SMTP version number. |
# |
public
|
CRLF = "\r\n"
SMTP line break constant.
SMTP line break constant. |
# |
public
|
DEFAULT_SMTP_PORT = 25
The SMTP port to use if one is not specified.
The SMTP port to use if one is not specified. |
# |
public
|
MAX_LINE_LENGTH = 998
The maximum line length allowed by RFC 2822 section 2.1.1
The maximum line length allowed by RFC 2822 section 2.1.1 |
# |
public
|
DEBUG_OFF = 0
Debug level for no output
Debug level for no output |
# |
public
|
DEBUG_CLIENT = 1
Debug level to show client -> server messages
Debug level to show client -> server messages |
# |
public
|
DEBUG_SERVER = 2
Debug level to show client -> server and server -> client messages
Debug level to show client -> server and server -> client messages |
# |
public
|
DEBUG_CONNECTION = 3
Debug level to show connection status, client -> server and server -> client messages
Debug level to show connection status, client -> server and server -> client messages |
# |
public
|
DEBUG_LOWLEVEL = 4
Debug level to show all messages
Debug level to show all messages |
# |
Properties | |||
---|---|---|---|
public
|
string
|
$Version = '5.2.28'
|
# |
public
|
integer
|
$SMTP_PORT = 25
|
# |
public
|
string
|
$CRLF = "\r\n"
|
# |
public
|
integer
|
$do_debug = self::DEBUG_OFF
|
# |
public
|
string|callable
|
$Debugoutput = 'echo'
|
# |
public
|
boolean
|
$do_verp = false
|
# |
public
|
integer
|
$Timeout = 300
|
# |
public
|
integer
|
$Timelimit = 300
|
# |
protected
|
array
|
$smtp_transaction_id_patterns = [
'exim' => '/[0-9]{3} OK id=(.*)/',
'sendmail' => '/[0-9]{3} 2.0.0 (.*) Message/',
'postfix' => '/[0-9]{3} 2.0.0 Ok: queued as (.*)/',
]
Patterns to extract an SMTP transaction id from reply to a DATA command.
The first capture group in each regex will be…
Patterns to extract an SMTP transaction id from reply to a DATA command. The first capture group in each regex will be used as the ID. |
# |
protected
|
string
|
$last_smtp_transaction_id
The last transaction ID issued in response to a DATA command,
if one was detected
The last transaction ID issued in response to a DATA command, if one was detected |
# |
protected
|
resource
|
$smtp_conn
|
# |
protected
|
array
|
$error = ['error' => '', 'detail' => '', 'smtp_code' => '', 'smtp_code_ex' => '']
|
# |
protected
|
string|null
|
$helo_rply = null
|
# |
protected
|
array|null
|
$server_caps = null
|
# |
protected
|
string
|
$last_reply = ''
|
# |