# \SMTP

PHPMailer RFC821 SMTP email transport class.

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

## Summary

Methods
Properties
Constants
__construct()
connect()
startTLS()
authenticate()
connected()
close()
data()
hello()
mail()
quit()
recipient()
reset()
sendAndMail()
verify()
noop()
turn()
client_send()
getError()
getLastReply()
setVerp()
getVerp()
setDebugOutput()
getDebugOutput()
setDebugLevel()
getDebugLevel()
setTimeout()
getTimeout()
$Version
$SMTP_PORT
$CRLF
$do_debug
$Debugoutput
$do_verp
$Timeout
$Timelimit
VERSION
CRLF
DEFAULT_SMTP_PORT
MAX_LINE_LENGTH
edebug()
hmac()
sendHello()
sendCommand()
get_lines()
$smtp_conn
$error
$helo_rply
$last_reply
N/A
No private methods found
No private properties found
N/A

File
  app/lib/SMTP.inc
Package
  PHPMailer
Class hierarchy
  \SMTP

## Tags

author | Chris Ryan unknown@example.com Marcus Bointon phpmailer@synchromedia.co.uk

## Constants

### VERSION

    VERSION

The PHPMailer SMTP version number.

#

## Tags

type | string

### CRLF

    CRLF

SMTP line break constant.

#

## Tags

type | string

### DEFAULT_SMTP_PORT

    DEFAULT_SMTP_PORT

The SMTP port to use if one is not specified.

#

## Tags

type | int

### MAX_LINE_LENGTH

    MAX_LINE_LENGTH

The maximum line length allowed by RFC 2822 section 2.1.1

#

## Tags

type | int

## Properties

### $Version

    $Version :

The PHPMailer SMTP Version number.

#### Type

#

#### Deprecated

Use the constant instead

See also

## Tags

type | string

### $SMTP_PORT

    $SMTP_PORT :

SMTP server port number.

#### Type

#

#### Deprecated

This is only ever used as a default value, so use the constant instead

See also

## Tags

type | int

### $CRLF

    $CRLF :

SMTP reply line ending.

#### Type

#

#### Deprecated

Use the constant instead

See also

## Tags

type | string

### $do_debug

    $do_debug :

Debug output level.

Options:

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

#### Type

#

## Tags

type | int

### $Debugoutput

    $Debugoutput :

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

#### Type

#

## Tags

type | string

### $do_verp

    $do_verp :

Whether to use VERP.

#### Type

#

See also
  http://en.wikipedia.org/wiki/Variable_envelope_return_path
  Info on VERP

## Tags

type | bool

### $Timeout

    $Timeout :

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.

#### Type

#

See also
  http://tools.ietf.org/html/rfc2821#section-4.5.3.2

## Tags

type | int

### $Timelimit

    $Timelimit :

The SMTP timelimit value for reads, in seconds.

#### Type

#

## Tags

type | int

### $smtp_conn

    $smtp_conn :

The socket for the server connection.

#### Type

#

## Tags

type | resource

### $error

    $error :

Error message, if any, for the last call.

#### Type

#

## Tags

type | string

### $helo_rply

    $helo_rply :

The reply the server sent to us for HELO.

#### Type

#

## Tags

type | string

### $last_reply

    $last_reply :

The most recent reply received from the server.

#### Type

#

## Tags

type | string

## Methods

### __construct()

    __construct()

Constructor.

#

## Tags

None found

### connect()

    connect(string  $host, integer  $port = null, integer  $timeout = 30, array  $options = array()) : boolean

Connect to an SMTP server.

#### Parameters

string | $host | SMTP server IP or host name
integer | $port | The port number to connect to
integer | $timeout | How long to wait for the connection to open
array | $options | An array of options for stream_context_create()

#### Returns

boolean

#

## Tags

None found

### startTLS()

    startTLS() : boolean

Initiate a TLS (encrypted) session.

#### Returns

boolean

#

## Tags

None found

### authenticate()

    authenticate(string  $username, string  $password, string  $authtype = 'LOGIN', string  $realm = '', string  $workstation = '') : boolean

Perform SMTP authentication.

Must be run after hello().

#### Parameters

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

#### Returns

boolean —

True if successfully authenticated.

#

See also

## Tags

None found

### connected()

    connected() : boolean

Check connection state.

#### Returns

boolean —

True if connected.

#

## Tags

None found

### close()

    close() : void

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

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

#

See also

## Tags

None found

### data()

    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. $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 with the message headers and the message body being separated by and additional . Implements rfc 821: DATA

#### Parameters

string | $msg_data | Message data to send

#### Returns

boolean

#

## Tags

None found

### hello()

    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 client and server are in a known state. Implements RFC 821: HELO and RFC 2821 EHLO.

#### Parameters

string | $host | The host name or IP to connect to

#### Returns

boolean

#

## Tags

None found

### mail()

    mail(string  $from) : boolean

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 FROM:

#### Parameters

string | $from | Source address of this message

#### Returns

boolean

#

## Tags

None found

### quit()

    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 from rfc 821: QUIT

#### Parameters

boolean | $close_on_error | Should the connection close if an error occurs?

#### Returns

boolean

#

## Tags

None found

### recipient()

    recipient(string  $toaddr) : boolean

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 TO:

#### Parameters

string | $toaddr | The address the message is being sent to

#### Returns

boolean

#

## Tags

None found

### reset()

    reset() : boolean

Send an SMTP RSET command.

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

#### Returns

boolean —

True on success.

#

## Tags

None found

### sendAndMail()

    sendAndMail(string  $from) : boolean

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 FROM:

#### Parameters

string | $from | The address the message is from

#### Returns

boolean

#

## Tags

None found

### verify()

    verify(string  $name) : boolean

Send an SMTP VRFY command.

#### Parameters

string | $name | The name to verify

#### Returns

boolean

#

## Tags

None found

### noop()

    noop() : boolean

Send an SMTP NOOP command.

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

#### Returns

boolean

#

## Tags

None found

### turn()

    turn() : boolean

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

#### Returns

boolean

#

## Tags

None found

### client_send()

    client_send(string  $data) : integer|boolean

Send raw data to the server.

#### Parameters

string | $data | The data to send

#### Returns

integer|boolean —

The number of bytes sent to the server or false on error

#

## Tags

None found

### getError()

    getError() : array

Get the latest error.

#### Returns

array

#

## Tags

None found

### getLastReply()

    getLastReply() : string

Get the last reply from the server.

#### Returns

string

#

## Tags

None found

### setVerp()

    setVerp(boolean  $enabled = false)

Enable or disable VERP address generation.

#### Parameters

boolean | $enabled |

#

## Tags

None found

### getVerp()

    getVerp() : boolean

Get VERP address generation mode.

#### Returns

boolean

#

## Tags

None found

### setDebugOutput()

    setDebugOutput(string  $method = 'echo')

Set debug output method.

#### Parameters

string | $method | The function/method to use for debugging output.

#

## Tags

None found

### getDebugOutput()

    getDebugOutput() : string

Get debug output method.

#### Returns

string

#

## Tags

None found

### setDebugLevel()

    setDebugLevel(integer  $level)

Set debug output level.

#### Parameters

integer | $level |

#

## Tags

None found

### getDebugLevel()

    getDebugLevel() : integer

Get debug output level.

#### Returns

integer

#

## Tags

None found

### setTimeout()

    setTimeout(integer  $timeout)

Set SMTP timeout.

#### Parameters

integer | $timeout |

#

## Tags

None found

### getTimeout()

    getTimeout() : integer

Get SMTP timeout.

#### Returns

integer

#

## Tags

None found

### edebug()

    edebug(string  $str) : void

Output debugging info via a user-selected method.

#### Parameters

string | $str | Debug string to output

#

## Tags

None found

### hmac()

    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

#### Parameters

string | $data | The data to hash
string | $key | The key to hash with

#### Returns

string

#

## Tags

None found

### sendHello()

    sendHello(string  $hello, string  $host) : boolean

Send an SMTP HELO or EHLO command.

Low-level implementation used by hello()

#### Parameters

string | $hello | The HELO string
string | $host | The hostname to say we are

#### Returns

boolean

#

See also

## Tags

None found

### sendCommand()

    sendCommand(string  $command, string  $commandstring, integer|array  $expect) : boolean

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

#### Parameters

string | $command | The command name - not sent to the server
string | $commandstring | The actual command to send
integer|array | $expect | One or more expected integer success codes

#### Returns

boolean —

True on success.

#

## Tags

None found

### get_lines()

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

#### Returns

string

#

## Tags

None found

### SMTP.inc