Class SMTP

Description

PHPMailer RFC821 SMTP email transport class.

Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.

Located in /class.smtp.php (line 27)


	
			
Class Constant Summary
CRLF = "\r\n"
VERSION = '5.2.8'
Variable Summary
mixed $CRLF
mixed $Debugoutput
mixed $do_debug
mixed $do_verp
mixed $error
mixed $helo_rply
mixed $last_reply
mixed $smtp_conn
mixed $SMTP_PORT
mixed $Timelimit
mixed $Timeout
mixed $Version
Method Summary
SMTP __construct ()
bool authenticate (string $username, string $password, [string $authtype = 'LOGIN'], [string $realm = ''], [string $workstation = ''])
int|bool client_send (string $data)
void close ()
bool connect (string $host, [int $port = null], [int $timeout = 30], [array $options = array()])
bool connected ()
bool data (string $msg_data)
void edebug (string $str)
int getDebugLevel ()
string getDebugOutput ()
array getError ()
string getLastReply ()
int getTimeout ()
bool getVerp ()
string get_lines ()
bool hello ([string $host = ''])
string hmac (string $data, string $key)
bool mail (string $from)
bool noop ()
bool quit ([bool $close_on_error = true])
bool recipient (string $toaddr)
bool reset ()
bool sendAndMail (string $from)
bool sendCommand (string $command, string $commandstring, int|array $expect)
bool sendHello (string $hello, string $host)
void setDebugLevel ([int $level = 0])
void setDebugOutput ([string $method = 'echo'])
void setTimeout ([int $timeout = 0])
void setVerp ([bool $enabled = false])
bool startTLS ()
bool turn ()
bool verify (string $name)
Variables
mixed $CRLF = "\r\n" (line 75)

SMTP reply line ending.

  • see: SMTP::CRLF
  • deprecated: Use the constant instead
  • access: public
mixed $Debugoutput = 'echo' (line 97)

How to handle debug output.

Options: * `echo` Output plain-text as-is, appropriate for CLI * `html` Output escaped, line breaks converted to
, appropriate for browser output * `error_log` Output to error log as configured in php.ini

  • access: public
mixed $do_debug = 0 (line 87)

Debug output level.

Options: * `0` No output * `1` Commands * `2` Data and commands * `3` As 2 plus connection status * `4` Low-level data output

  • access: public
mixed $do_verp = false (line 105)

Whether to use VERP.

mixed $error = '' (line 132)

Error message, if any, for the last call.

  • access: protected
mixed $helo_rply = '' (line 138)

The reply the server sent to us for HELO.

  • access: protected
mixed $last_reply = '' (line 144)

The most recent reply received from the server.

  • access: protected
mixed $smtp_conn (line 126)

The socket for the server connection.

  • access: protected
mixed $SMTP_PORT = 25 (line 67)

SMTP server port number.

  • see: SMTP::DEFAULT_SMTP_PORT
  • deprecated: This is only ever used as a default value, so use the constant instead
  • access: public
mixed $Timelimit = 30 (line 120)

The SMTP timelimit value for reads, in seconds.

  • access: public
mixed $Timeout = 300 (line 114)

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.

mixed $Version = '5.2.8' (line 59)

The PHPMailer SMTP Version number.

  • see: SMTP::VERSION
  • deprecated: Use the constant instead
  • access: public
Methods
Constructor __construct (line 150)

Constructor.

  • access: public
SMTP __construct ()
authenticate (line 291)

Perform SMTP authentication.

Must be run after hello().

  • return: True if successfully authenticated.
  • see: SMTP::hello()
  • access: public
bool authenticate (string $username, string $password, [string $authtype = 'LOGIN'], [string $realm = ''], [string $workstation = ''])
  • string $username: The user name
  • string $password: The password
  • string $authtype: The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5)
  • string $realm: The auth realm for NTLM
  • string $workstation: The auth workstation for NTLM
client_send (line 777)

Send raw data to the server.

  • return: The number of bytes sent to the server or false on error
  • access: public
int|bool client_send (string $data)
  • string $data: The data to send
close (line 466)

Close the socket and clean up the state of the class.

Don't use this function without first trying to use QUIT.

void close ()
connect (line 194)

Connect to an SMTP server.

  • access: public
bool connect (string $host, [int $port = null], [int $timeout = 30], [array $options = array()])
  • 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()
connected (line 440)

Check connection state.

  • return: True if connected.
  • access: public
bool connected ()
data (line 492)

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>

  • access: public
bool data (string $msg_data)
  • string $msg_data: Message data to send
edebug (line 163)

Output debugging info via a user-selected method.

  • access: protected
void edebug (string $str)
  • string $str: Debug string to output
getDebugLevel (line 913)

Get debug output level.

  • access: public
int getDebugLevel ()
getDebugOutput (line 895)

Get debug output method.

  • access: public
string getDebugOutput ()
getError (line 790)

Get the latest error.

  • access: public
array getError ()
getLastReply (line 800)

Get the last reply from the server.

  • access: public
string getLastReply ()
getTimeout (line 931)

Get SMTP timeout.

  • access: public
int getTimeout ()
getVerp (line 877)

Get VERP address generation mode.

  • access: public
bool getVerp ()
get_lines (line 814)

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.

  • access: protected
string get_lines ()
hello (line 574)

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> <domain> <CRLF> and RFC 2821 EHLO.

  • access: public
bool hello ([string $host = ''])
  • string $host: The host name or IP to connect to
hmac (line 408)

Calculate an MD5 HMAC hash.

Works like hash_hmac('md5', $data, $key) in case that function is not available

  • access: protected
string hmac (string $data, string $key)
  • string $data: The data to hash
  • string $key: The key to hash with
mail (line 607)

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:<reverse-path> <CRLF>

  • access: public
bool mail (string $from)
  • string $from: Source address of this message
noop (line 746)

Send an SMTP NOOP command.

Used to keep keep-alives alive, doesn't actually do anything

  • access: public
bool noop ()
quit (line 625)

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>

  • access: public
bool quit ([bool $close_on_error = true])
  • bool $close_on_error: Should the connection close if an error occurs?
recipient (line 645)

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:<forward-path> <CRLF>

  • access: public
bool recipient (string $toaddr)
  • string $toaddr: The address the message is being sent to
reset (line 661)

Send an SMTP RSET command.

Abort any transaction that is currently in progress. Implements rfc 821: RSET <CRLF>

  • return: True on success.
  • access: public
bool reset ()
sendAndMail (line 724)

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:<reverse-path> <CRLF>

  • access: public
bool sendAndMail (string $from)
  • string $from: The address the message is from
sendCommand (line 674)

Send a command to an SMTP server and check its return code.

  • return: True on success.
  • access: protected
bool sendCommand (string $command, string $commandstring, int|array $expect)
  • 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
sendHello (line 589)

Send an SMTP HELO or EHLO command.

Low-level implementation used by hello()

bool sendHello (string $hello, string $host)
  • string $hello: The HELO string
  • string $host: The hostname to say we are
setDebugLevel (line 904)

Set debug output level.

  • access: public
void setDebugLevel ([int $level = 0])
  • int $level
setDebugOutput (line 886)

Set debug output method.

  • access: public
void setDebugOutput ([string $method = 'echo'])
  • string $method: The function/method to use for debugging output.
setTimeout (line 922)

Set SMTP timeout.

  • access: public
void setTimeout ([int $timeout = 0])
  • int $timeout
setVerp (line 868)

Enable or disable VERP address generation.

  • access: public
void setVerp ([bool $enabled = false])
  • bool $enabled
startTLS (line 263)

Initiate a TLS (encrypted) session.

  • access: public
bool startTLS ()
turn (line 760)

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>

  • access: public
bool turn ()
verify (line 735)

Send an SMTP VRFY command.

  • access: public
bool verify (string $name)
  • string $name: The name to verify
Class Constants
CRLF = "\r\n" (line 39)

SMTP line break constant.

DEFAULT_SMTP_PORT = 25 (line 45)

The SMTP port to use if one is not specified.

MAX_LINE_LENGTH = 998 (line 51)

The maximum line length allowed by RFC 2822 section 2.1.1

VERSION = '5.2.8' (line 33)

The PHPMailer SMTP version number.

Documentation generated on Sat, 25 Oct 2014 20:22:57 +0200 by phpDocumentor 1.4.4