Class SMTP

Description

PHP RFC821 SMTP client

Implements all the RFC 821 SMTP commands except TURN which will always return a not implemented error. SMTP also provides some utility methods for sending mail to an SMTP server.

Located in /libraries/phpmailer/smtp.php (line 47)


	
			
Variable Summary
 string $CRLF
 string $Debugoutput
 int $do_debug
 bool $do_verp
 string $error
 string $helo_rply
 resource $smtp_conn
 int $Timeout
 string $Version
Method Summary
 bool Authenticate (string $username, string $password, [string $authtype = 'LOGIN'], [string $realm = ''], [string $workstation = ''])
 Integer client_send (string $data)
 void Close ()
 bool Connect (string $host, [int $port = 0], [int $timeout = 30], [array $options = array()])
 bool Connected ()
 bool Data (string $msg_data)
 void edebug (string $str)
 array getError ()
 string get_lines ()
 bool Hello ([string $host = ''])
 string hmac (string $data, string $key)
 bool Mail (string $from)
 bool Quit ([bool $close_on_error = true])
 bool Recipient (string $to)
 bool Reset ()
 bool SendAndMail (string $from)
 bool SendHello (string $hello, string $host)
 bool StartTLS ()
 bool Turn ()
Variables
string $CRLF = "\r\n" (line 58)

SMTP reply line ending (don't change)

  • access: public
string $Debugoutput = 'echo' (line 71)

Sets the function/method to use for debugging output.

Right now we only honor 'echo', 'html' or 'error_log'

  • access: public
int $do_debug = 0 (line 64)

Debug output level; 0 for no output

  • access: public
bool $do_verp = false (line 77)

Sets VERP use on/off (default is off)

  • access: public
string $error (line 108)
  • var: Error message, if any, for the last call
  • access: protected
string $helo_rply (line 112)
  • var: The reply the server sent to us for HELO
  • access: protected
resource $smtp_conn (line 104)
  • var: The socket to the server
  • access: protected
int $SMTP_PORT = 25 (line 52)

SMTP server port

  • access: public
int $Timelimit = 30 (line 89)

Sets the SMTP timelimit value for reads, in seconds

  • access: public
int $Timeout = 15 (line 83)

Sets the SMTP timeout value for reads, in seconds

  • access: public
string $Version = '5.2.6' (line 95)

Sets the SMTP PHPMailer Version number

  • access: public
Methods
Constructor __construct (line 139)

Initialize the class so that the data is in a known state.

  • access: public
SMTP __construct ()
Authenticate (line 272)

Performs SMTP authentication. Must be run after running the Hello() method. Returns true if successfully authenticated.

  • access: public
bool Authenticate (string $username, string $password, [string $authtype = 'LOGIN'], [string $realm = ''], [string $workstation = ''])
  • string $username
  • string $password
  • string $authtype
  • string $realm
  • string $workstation
client_send (line 1021)

Sends data to the server

  • return: number of bytes sent to the server or FALSE on error
  • access: public
Integer client_send (string $data)
  • string $data
Close (line 528)

Closes the socket and cleans up the state of the class.

It is not considered good to use this function without first trying to use QUIT.

  • access: public
void Close ()
Connect (line 163)

Connect to an SMTP server

SMTP CODE SUCCESS: 220 SMTP CODE FAILURE: 421

  • access: public
bool Connect (string $host, [int $port = 0], [int $timeout = 30], [array $options = array()])
  • string $host: SMTP server IP or host name
  • int $port: The port number to connect to, or use the default port if not specified
  • int $timeout: How long to wait for the connection to open
  • array $options: An array of options compatible with stream_context_create()
Connected (line 505)

Returns true if connected to a server otherwise false

  • access: public
bool Connected ()
Data (line 562)

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>

SMTP CODE INTERMEDIATE: 354 [data] <CRLF>.<CRLF> SMTP CODE SUCCESS: 250 SMTP CODE FAILURE: 552, 554, 451, 452 SMTP CODE FAILURE: 451, 554 SMTP CODE ERROR : 500, 501, 503, 421

  • access: public
bool Data (string $msg_data)
  • string $msg_data
edebug (line 118)

Outputs debugging info via user-defined method

  • access: protected
void edebug (string $str)
  • string $str
getError (line 1033)

Get the current error

  • access: public
array getError ()
get_lines (line 1050)

Read in as many lines as possible 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 700)

Sends the HELO command to the smtp server.

This makes sure that we and the server are in the same known state.

Implements from rfc 821: HELO <SP> <domain> <CRLF>

SMTP CODE SUCCESS: 250 SMTP CODE ERROR : 500, 501, 504, 421

  • access: public
bool Hello ([string $host = ''])
  • string $host
hmac (line 475)

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

  • access: protected
string hmac (string $data, string $key)
  • string $data
  • string $key
Mail (line 773)

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>

SMTP CODE SUCCESS: 250 SMTP CODE SUCCESS: 552, 451, 452 SMTP CODE SUCCESS: 500, 501, 421

  • access: public
bool Mail (string $from)
  • string $from
Quit (line 817)

Sends the quit command to the server and then closes the socket if there is no error or the $close_on_error argument is true.

Implements from rfc 821: QUIT <CRLF>

SMTP CODE SUCCESS: 221 SMTP CODE ERROR : 500

  • access: public
bool Quit ([bool $close_on_error = true])
  • bool $close_on_error
Recipient (line 871)

Sends the command RCPT to the SMTP server with the TO: argument of $to.

Returns true if the recipient was accepted false if it was rejected.

Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>

SMTP CODE SUCCESS: 250, 251 SMTP CODE FAILURE: 550, 551, 552, 553, 450, 451, 452 SMTP CODE ERROR : 500, 501, 503, 421

  • access: public
bool Recipient (string $to)
  • string $to
Reset (line 914)

Sends the RSET command to abort and transaction that is currently in progress. Returns true if successful false otherwise.

Implements rfc 821: RSET <CRLF>

SMTP CODE SUCCESS: 250 SMTP CODE ERROR : 500, 501, 504, 421

  • access: public
bool Reset ()
SendAndMail (line 962)

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>

SMTP CODE SUCCESS: 250 SMTP CODE SUCCESS: 552, 451, 452 SMTP CODE SUCCESS: 500, 501, 502, 421

  • access: public
bool SendAndMail (string $from)
  • string $from
SendHello (line 732)

Sends a HELO/EHLO command.

  • access: protected
bool SendHello (string $hello, string $host)
  • string $hello
  • string $host
StartTLS (line 225)

Initiate a TLS communication with the server.

SMTP CODE 220 Ready to start TLS SMTP CODE 501 Syntax error (no parameters allowed) SMTP CODE 454 TLS not available due to temporary reason

  • return: success
  • access: public
bool StartTLS ()
Turn (line 1006)

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 implimented in the future

Implements from rfc 821: TURN <CRLF>

SMTP CODE SUCCESS: 250 SMTP CODE FAILURE: 502 SMTP CODE ERROR : 500, 503

  • access: public
bool Turn ()

Documentation generated on Tue, 19 Nov 2013 15:13:59 +0100 by phpDocumentor 1.4.3