Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
SMTP Class Reference
+ Collaboration diagram for SMTP:

Public Member Functions

 connect ($host, $port=null, $timeout=30, $options=array())
 
 startTLS ()
 
 authenticate ($username, $password, $authtype=null, $realm= '', $workstation= '', $OAuth=null)
 
 connected ()
 
 close ()
 
 data ($msg_data)
 
 hello ($host= '')
 
 mail ($from)
 
 quit ($close_on_error=true)
 
 recipient ($address)
 
 reset ()
 
 sendAndMail ($from)
 
 verify ($name)
 
 noop ()
 
 turn ()
 
 client_send ($data)
 
 getError ()
 
 getServerExtList ()
 
 getServerExt ($name)
 
 getLastReply ()
 
 setVerp ($enabled=false)
 
 getVerp ()
 
 setDebugOutput ($method= 'echo')
 
 getDebugOutput ()
 
 setDebugLevel ($level=0)
 
 getDebugLevel ()
 
 setTimeout ($timeout=0)
 
 getTimeout ()
 

Data Fields

const VERSION = '5.2.14'
 
const CRLF = "\r\n"
 
const DEFAULT_SMTP_PORT = 25
 
const MAX_LINE_LENGTH = 998
 
const DEBUG_OFF = 0
 
const DEBUG_CLIENT = 1
 
const DEBUG_SERVER = 2
 
const DEBUG_CONNECTION = 3
 
const DEBUG_LOWLEVEL = 4
 
 $Version = '5.2.14'
 
 $SMTP_PORT = 25
 
 $CRLF = "\r\n"
 
 $do_debug = self::DEBUG_OFF
 
 $Debugoutput = 'echo'
 
 $do_verp = false
 
 $Timeout = 300
 
 $Timelimit = 300
 

Protected Member Functions

 edebug ($str, $level=0)
 
 hmac ($data, $key)
 
 sendHello ($hello, $host)
 
 parseHelloFields ($type)
 
 sendCommand ($command, $commandstring, $expect)
 
 get_lines ()
 
 setError ($message, $detail= '', $smtp_code= '', $smtp_code_ex= '')
 

Protected Attributes

 $smtp_conn
 
 $error
 
 $helo_rply = null
 
 $server_caps = null
 
 $last_reply = ''
 

Detailed Description

Definition at line 27 of file class.smtp.php.

Member Function Documentation

authenticate (   $username,
  $password,
  $authtype = null,
  $realm = '',
  $workstation = '',
  $OAuth = null 
)

Perform SMTP authentication. Must be run after hello().

See Also
hello()
Parameters
string$usernameThe user name
string$passwordThe password
string$authtypeThe auth type (PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2)
string$realmThe auth realm for NTLM
string$workstationThe auth workstation for NTLM
null | OAuth$OAuthAn optional OAuth instance (
See Also
PHPMailerOAuth)
Returns
bool True if successfully authenticated.* public

Definition at line 362 of file class.smtp.php.

+ Here is the call graph for this function:

client_send (   $data)

Send raw data to the server.

Parameters
string$dataThe data to send public
Returns
integer|boolean The number of bytes sent to the server or false on error

Definition at line 964 of file class.smtp.php.

+ Here is the call graph for this function:

close ( )

Close the socket and clean up the state of the class. Don't use this function without first trying to use QUIT.

See Also
quit() public
Returns
void

Definition at line 589 of file class.smtp.php.

+ Here is the call graph for this function:

connect (   $host,
  $port = null,
  $timeout = 30,
  $options = array() 
)

Connect to an SMTP server.

Parameters
string$hostSMTP server IP or host name
integer$portThe port number to connect to
integer$timeoutHow long to wait for the connection to open
array$optionsAn array of options for stream_context_create() public
Returns
boolean

Definition at line 247 of file class.smtp.php.

+ Here is the call graph for this function:

connected ( )

Check connection state. public

Returns
boolean True if connected.

Definition at line 564 of file class.smtp.php.

+ Here is the call graph for this function:

data (   $msg_data)

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
string$msg_dataMessage data to send public
Returns
boolean

Definition at line 614 of file class.smtp.php.

+ Here is the call graph for this function:

edebug (   $str,
  $level = 0 
)
protected

Output debugging info via a user-selected method.

See Also
SMTP::$Debugoutput
SMTP::$do_debug
Parameters
string$strDebug string to output
integer$levelThe debug level of this message; see DEBUG_* constants
Returns
void

Definition at line 202 of file class.smtp.php.

get_lines ( )
protected

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. protected

Returns
string

Definition at line 1050 of file class.smtp.php.

+ Here is the call graph for this function:

getDebugLevel ( )

Get debug output level.

Returns
integer

Definition at line 1159 of file class.smtp.php.

getDebugOutput ( )

Get debug output method.

Returns
string

Definition at line 1141 of file class.smtp.php.

getError ( )

Get the latest error. public

Returns
array

Definition at line 975 of file class.smtp.php.

getLastReply ( )

Get the last reply from the server. public

Returns
string

Definition at line 1036 of file class.smtp.php.

getServerExt (   $name)

A multipurpose method The method works in three ways, dependent on argument value and current state

  1. HELO/EHLO was not sent - returns null and set up $this->error
  2. HELO was sent $name = 'HELO': returns server name $name = 'EHLO': returns boolean false $name = any string: returns null and set up $this->error
  3. EHLO was sent $name = 'HELO'|'EHLO': returns server name $name = any string: if extension $name exists, returns boolean True or its options. Otherwise returns boolean False In other words, one can use this method to detect 3 conditions:

null returned: handshake was not or we don't know about ext (refer to $this->error)

  • false returned: the requested feature exactly not exists
  • positive value returned: the requested feature exists
    Parameters
    string$nameName of SMTP extension or 'HELO'|'EHLO'
    Returns
    mixed

Definition at line 1009 of file class.smtp.php.

+ Here is the call graph for this function:

getServerExtList ( )

Get SMTP extensions available on the server public

Returns
array|null

Definition at line 985 of file class.smtp.php.

getTimeout ( )

Get SMTP timeout.

Returns
integer

Definition at line 1177 of file class.smtp.php.

getVerp ( )

Get VERP address generation mode.

Returns
boolean

Definition at line 1106 of file class.smtp.php.

hello (   $host = '')

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.

Parameters
string$hostThe host name or IP to connect to public
Returns
boolean

Definition at line 703 of file class.smtp.php.

+ Here is the call graph for this function:

hmac (   $data,
  $key 
)
protected

Calculate an MD5 HMAC hash. Works like hash_hmac('md5', $data, $key) in case that function is not available

Parameters
string$dataThe data to hash
string$keyThe key to hash with protected
Returns
string

Definition at line 532 of file class.smtp.php.

mail (   $from)

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>

Parameters
string$fromSource address of this message public
Returns
boolean

Definition at line 783 of file class.smtp.php.

+ Here is the call graph for this function:

noop ( )

Send an SMTP NOOP command. Used to keep keep-alives alive, doesn't actually do anything public

Returns
boolean

Definition at line 937 of file class.smtp.php.

+ Here is the call graph for this function:

parseHelloFields (   $type)
protected

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. protected

Parameters
string$type- 'HELO' or 'EHLO'

Definition at line 736 of file class.smtp.php.

quit (   $close_on_error = true)

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
boolean$close_on_errorShould the connection close if an error occurs? public
Returns
boolean

Definition at line 801 of file class.smtp.php.

+ Here is the call graph for this function:

recipient (   $address)

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>

Parameters
string$addressThe address the message is being sent to public
Returns
boolean

Definition at line 821 of file class.smtp.php.

+ Here is the call graph for this function:

reset ( )

Send an SMTP RSET command. Abort any transaction that is currently in progress. Implements rfc 821: RSET <CRLF> public

Returns
boolean True on success.

Definition at line 837 of file class.smtp.php.

+ Here is the call graph for this function:

sendAndMail (   $from)

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>

Parameters
string$fromThe address the message is from public
Returns
boolean

Definition at line 915 of file class.smtp.php.

+ Here is the call graph for this function:

sendCommand (   $command,
  $commandstring,
  $expect 
)
protected

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

Parameters
string$commandThe command name - not sent to the server
string$commandstringThe actual command to send
integer | array$expectOne or more expected integer success codes protected
Returns
boolean True on success.

Definition at line 850 of file class.smtp.php.

+ Here is the call graph for this function:

sendHello (   $hello,
  $host 
)
protected

Send an SMTP HELO or EHLO command. Low-level implementation used by hello()

See Also
hello()
Parameters
string$helloThe HELO string
string$hostThe hostname to say we are protected
Returns
boolean

Definition at line 718 of file class.smtp.php.

+ Here is the call graph for this function:

setDebugLevel (   $level = 0)

Set debug output level.

Parameters
integer$level

Definition at line 1150 of file class.smtp.php.

setDebugOutput (   $method = 'echo')

Set debug output method.

Parameters
string | callable$methodThe name of the mechanism to use for debugging output, or a callable to handle it.

Definition at line 1132 of file class.smtp.php.

setError (   $message,
  $detail = '',
  $smtp_code = '',
  $smtp_code_ex = '' 
)
protected

Set error messages and codes.

Parameters
string$messageThe error message
string$detailFurther detail on the error
string$smtp_codeAn associated SMTP error code
string$smtp_code_exExtended SMTP code

Definition at line 1118 of file class.smtp.php.

setTimeout (   $timeout = 0)

Set SMTP timeout.

Parameters
integer$timeout

Definition at line 1168 of file class.smtp.php.

setVerp (   $enabled = false)

Enable or disable VERP address generation.

Parameters
boolean$enabled

Definition at line 1097 of file class.smtp.php.

startTLS ( )

Initiate a TLS (encrypted) session. public

Returns
boolean

Definition at line 334 of file class.smtp.php.

+ Here is the call graph for this function:

turn ( )

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

Returns
boolean

Definition at line 951 of file class.smtp.php.

+ Here is the call graph for this function:

verify (   $name)

Send an SMTP VRFY command.

Parameters
string$nameThe name to verify public
Returns
boolean

Definition at line 926 of file class.smtp.php.

+ Here is the call graph for this function:

Field Documentation

$CRLF = "\r\n"

Definition at line 100 of file class.smtp.php.

$Debugoutput = 'echo'

Definition at line 127 of file class.smtp.php.

$do_debug = self::DEBUG_OFF

Definition at line 112 of file class.smtp.php.

$do_verp = false

Definition at line 135 of file class.smtp.php.

$error
protected
Initial value:
= array(
'error' => '',
'detail' => '',
'smtp_code' => '',
'smtp_code_ex' => ''
)

Definition at line 163 of file class.smtp.php.

$helo_rply = null
protected

Definition at line 175 of file class.smtp.php.

$last_reply = ''
protected

Definition at line 192 of file class.smtp.php.

$server_caps = null
protected

Definition at line 186 of file class.smtp.php.

$smtp_conn
protected

Definition at line 157 of file class.smtp.php.

$SMTP_PORT = 25

Definition at line 92 of file class.smtp.php.

$Timelimit = 300

Definition at line 151 of file class.smtp.php.

$Timeout = 300

Definition at line 144 of file class.smtp.php.

$Version = '5.2.14'

Definition at line 84 of file class.smtp.php.

const CRLF = "\r\n"

Definition at line 39 of file class.smtp.php.

const DEBUG_CLIENT = 1

Debug level to show client -> server messages

Definition at line 61 of file class.smtp.php.

const DEBUG_CONNECTION = 3

Debug level to show connection status, client -> server and server -> client messages

Definition at line 71 of file class.smtp.php.

const DEBUG_LOWLEVEL = 4

Debug level to show all messages

Definition at line 76 of file class.smtp.php.

const DEBUG_OFF = 0

Debug level for no output

Definition at line 56 of file class.smtp.php.

const DEBUG_SERVER = 2

Debug level to show client -> server and server -> client messages

Definition at line 66 of file class.smtp.php.

const DEFAULT_SMTP_PORT = 25

Definition at line 45 of file class.smtp.php.

const MAX_LINE_LENGTH = 998

Definition at line 51 of file class.smtp.php.

const VERSION = '5.2.14'

Definition at line 33 of file class.smtp.php.


The documentation for this class was generated from the following file:
← centre documentaire © anakeen