VERSION
VERSION = '6.6.4' : string
The PHPMailer SMTP version number.
PHPMailer RFC821 SMTP email transport class.
Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.
$do_debug : int
Debug output level.
Options:
0
) No debug output, default1
) Client commands2
) Client commands and server responses3
) As DEBUG_SERVER plus connection status4
) Low-level data output, all messages.$Debugoutput : string|callable|\Psr\Log\LoggerInterface
How to handle debug output.
Options:
echo
Output plain-text as-is, appropriate for CLIhtml
Output escaped, line breaks converted to <br>
, appropriate for browser outputerror_log
Output to error log as configured in php.ini
Alternatively, you can provide a callable expecting two params: a message string and the debug level:$smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
Alternatively, you can pass in an instance of a PSR-3 compatible logger, though only debug
level output is used:
$mail->Debugoutput = new myPsr3Logger;
$do_verp : bool
Whether to use VERP.
$Timeout : int
The timeout value for connection, in seconds.
Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2. This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure.
$Timelimit : int
How long to wait for commands to complete, in seconds.
Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2.
$smtp_transaction_id_patterns : string[]
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. MS ESMTP returns the message ID, which may not be correct for internal tracking.
$last_smtp_transaction_id : string|bool|null
The last transaction ID issued in response to a DATA command, if one was detected.
$smtp_conn : ?resource
The socket for the server connection.
$error : array
Error information, if any, for the last SMTP command.
$helo_rply : string|null
The reply the server sent to us for HELO.
If null, no HELO string has yet been received.
$server_caps : array|null
The set of SMTP extensions sent in reply to EHLO command.
Indexes of the array are extension names. Value at index 'HELO' or 'EHLO' (according to command that was sent) represents the server name. In case of HELO it is the only element of the array. Other values can be boolean TRUE or an array containing extension options. If null, no HELO/EHLO string has yet been received.
$last_reply : string
The most recent reply received from the server.
connect(string $host, int $port = null, int $timeout = 30, array $options = []) : bool
Connect to an SMTP server.
string | $host | SMTP server IP or host name |
int | $port | The port number to connect to |
int | $timeout | How long to wait for the connection to open |
array | $options | An array of options for stream_context_create() |
authenticate(string $username, string $password, string $authtype = null, \PHPMailer\PHPMailer\OAuthTokenProvider $OAuth = null) : bool
Perform SMTP authentication.
Must be run after hello().
string | $username | The user name |
string | $password | The password |
string | $authtype | The auth type (CRAM-MD5, PLAIN, LOGIN, XOAUTH2) |
\PHPMailer\PHPMailer\OAuthTokenProvider | $OAuth | An optional OAuthTokenProvider instance for XOAUTH2 authentication |
True if successfully authenticated
data(string $msg_data) : bool
Send an SMTP DATA command.
Issues a data command and sends the msg_data to the server, finalizing 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 an additional <CRLF>. Implements RFC 821: DATA <CRLF>.
string | $msg_data | Message data to send |
hello(string $host = '') : bool
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>
string | $host | The host name or IP to connect to |
mail(string $from) : bool
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:
string | $from | Source address of this message |
recipient(string $address, string $dsn = '') : bool
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:
string | $address | The address the message is being sent to |
string | $dsn | Comma separated list of DSN notifications. NEVER, SUCCESS, FAILURE or DELAY. If you specify NEVER all other notifications are ignored. |
sendAndMail(string $from) : bool
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:
string | $from | The address the message is from |
client_send(string $data, string $command = '') : int|bool
Send raw data to the server.
string | $data | The data to send |
string | $command | Optionally, the command this is part of, used only for controlling debug output |
The number of bytes sent to the server or false on error
getServerExt(string $name) : string|bool|null
Get metadata about the SMTP server from its HELO/EHLO response.
The method works in three ways, dependent on argument value and current state:
string | $name | Name of SMTP extension or 'HELO'|'EHLO' |
getSMTPConnection(string $host, int $port = null, int $timeout = 30, array $options = []) : false|resource
Create connection to the SMTP server.
string | $host | SMTP server IP or host name |
int | $port | The port number to connect to |
int | $timeout | How long to wait for the connection to open |
array | $options | An array of options for stream_context_create() |
sendCommand(string $command, string $commandstring, int|array $expect) : bool
Send a command to an SMTP server and check its return code.
string | $command | The command name - not sent to the server |
string | $commandstring | The actual command to send |
int|array | $expect | One or more expected integer success codes |
True on success
setError(string $message, string $detail = '', string $smtp_code = '', string $smtp_code_ex = '') : mixed
Set error messages and codes.
string | $message | The error message |
string | $detail | Further detail on the error |
string | $smtp_code | An associated SMTP error code |
string | $smtp_code_ex | Extended SMTP code |
errorHandler(int $errno, string $errmsg, string $errfile = '', int $errline) : mixed
Reports an error number and string.
int | $errno | The error number returned by PHP |
string | $errmsg | The error message returned by PHP |
string | $errfile | The file the error occurred in |
int | $errline | The line number the error occurred on |
recordLastTransactionID() : bool|string|null
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.