Version: @(#) $Id: smtp_class.html,v 1.1 2014/03/03 12:28:31 horst Exp $
Sending e-mail messages via SMTP protocol
Manuel Lemos (mlemos-at-acm.org)
Copyright (C) Manuel Lemos 1999-2011
@(#) $Id: smtp_class.html,v 1.1 2014/03/03 12:28:31 horst Exp $
Sending e-mail messages via SMTP protocol
If you are interested in translating the documentation of this class to your own idiom, please contact the author.
Technical support for using this class may be obtained in the smtpclass support forum. Just go to the support forum pages page to browse the forum archives and post support request messages:
http://www.phpclasses.org/discuss/package/14/
To use this class just create a new object, set any variables to configure its options and call the SendMessage function to send a message.
It is not recommended that you use this class alone unless you have deep understanding of Internet mail standards on how to compose compliant e-mail messages. Instead, use the MIME message composing and sending class and its sub-class SMTP message together with this SMTP class to properly compose e-mail messages, so your messages are not discarded for not being correctly composed.
string
''
Define the authorized user when sending messages to a SMTP server.
Set this variable to the user name when the SMTP server requires authentication.
string
''
Define the authentication realm when sending messages to a SMTP server.
Set this variable when the SMTP server requires authentication and if more than one authentication realm is supported.
string
''
Define the authorized user password when sending messages to a SMTP server.
Set this variable to the user password when the SMTP server requires authentication.
string
''
Define the client workstation name when sending messages to a SMTP server.
Set this variable to the client workstation when the SMTP server requires authentication identifiying the origin workstation name.
string
''
Force the use of a specific authentication mechanism.
Set it to an empty string to let the class determine the authentication mechanism to use automatically based on the supported mechanisms by the server and by the SASL client library classes.
Set this variable to a specific mechanism name if you want to override the automatic authentication mechanism selection.
string
''
Define the SMTP server host name.
Set to the host name of the SMTP server to which you want to relay the messages.
int
25
Define the SMTP server host port.
Set to the TCP port of the SMTP server host to connect.
string
''
Define the SOCKS server host name.
Set to the SOCKS server host name through which the SMTP connection should be routed. Leave it empty if you do not want the connections to be established through a SOCKS server.
int
1080
Define the SOCKS server host port.
Set to the port of the SOCKS server host through which the the SMTP connection should be routed.
string
'5'
Set the SOCKS protocol version.
Change this value if SOCKS server you want to use is listening to a different port.
string
''
Define the HTTP proxy server host name.
Set to the HTTP proxy server host name through which the SMTP connection should be routed. Leave it empty if you do not want the connections to be established through an HTTP proxy.
int
80
Define the HTTP proxy server host port.
Set to the port of the HTTP proxy server host through which the SMTP connection should be routed.
string
'SMTP Class (http://www.phpclasses.org/smtpclass $Revision: 1.1 $)'
Set the user agent used when connecting via an HTTP proxy.
Change this value only if for some reason you want emulate a certain e-mail client.
bool
0
Define whether the connection to the SMTP server should be established securely using SSL protocol.
Set to 1 if the SMTP server requires secure connections using SSL protocol.
bool
0
Define whether the connection to the SMTP server should use encryption after the connection is established using TLS protocol.
Set to 1 if the SMTP server requires that authentication be done securely starting the TLS protocol after the connection is established.
string
''
Name of the local host computer
Set to the name of the computer connecting to the SMTP server from the local network.
int
0
Specify the connection timeout period in seconds.
Leave it set to 0 if you want the connection attempts to wait forever. Change this value if for some reason the timeout period seems insufficient or otherwise it seems too long.
int
0
Specify the timeout period in seconds to wait for data from the server.
Leave it set to 0 if you want to use the same value defined in the timeout variable. Change this value if for some reason the default data timeout period seems insufficient or otherwise it seems too long.
bool
0
Boolean flag that indicates whether the message should be sent in direct delivery mode, i.e. the message is sent to the SMTP server associated to the domain of the recipient instead of relaying to the server specified by the host_name variable.
Set this to 1 if you want to send urgent messages directly to the recipient domain SMTP server.
string
''
Message that describes the error when a call to a class function fails.
Check this variable when an error occurs to understand what happened.
bool
0
Specify whether it is necessary to output SMTP connection debug information.
Set this variable to 1 if you need to see the progress of the SMTP connection and protocol dialog when you need to understand the reason for delivery problems.
bool
0
Specify whether the debug information should be outputted in HTML format.
Set this variable to 1 if you need to see the debug output in a Web page.
bool
1
Specify whether the class should attempt to use ESMTP extensions supported by the server.
Set this variable to 0 if for some reason you want to avoid benefitting from ESMTP extensions.
array
array()
Associative array with the list of ESMTP extensions supported by the SMTP server.
Check this variable after connecting to the SMTP server to determine which ESMTP extensions are supported.
string
''
Specify an address that should be considered invalid when resolving host name addresses.
In some networks any domain name that does not exist is resolved as a sub-domain of the default local domain. If the DNS is configured in such way that it always resolves any sub-domain of the default local domain to a given address, it is hard to determine whether a given domain does not exist.
If your network is configured this way, you may set this variable to the address that all sub-domains of the default local domain resolves, so the class can assume that such address is invalid.
string
'getmxrr'
Specify the name of the function that is called to determine the SMTP server address of a given domain.
Change this to a working replacement of the PHP getmxrr() function if this is not working in your system and you want to send messages in direct delivery mode.
string
''
Specify the server address for POP3 based authentication.
Set this variable to the address of the POP3 server if the SMTP server requires POP3 based authentication.
int
110
Specify the server port for POP3 based authentication.
Set this variable to the port of the POP3 server if the SMTP server requires POP3 based authentication.
bool Connect(
Connect to an SMTP server.
Call this function as first step to send e-mail messages.
domain - Specify the domain of the recipient when using the direct delivery mode.
The function returns 1 if the connection is successfully established.
bool MailFrom(
Set the address of the message sender.
Call this function right after establishing a connection with the Connect function.
sender - E-mail address of the sender.
The function returns 1 if the sender address is successfully set.
bool SetRecipient(
Set the address of a message recipient.
Call this function repeatedly for each recipient right after setting the message sender with the MailFrom function.
recipient - E-mail address of a recipient.
The function returns 1 if the recipient address is successfully set.
bool StartData()
Tell the SMTP server that the message data will start being sent.
Call this function right after you are done setting all the message recipients with the SetRecipient function.
The function returns 1 if the server is ready to start receiving the message data.
string PrepareData(
Prepare message data to normalize line breaks and escaping lines that contain single dots.
Call this function if the message data you want to send may contain line breaks that are not the "\r\n" sequence or it may contain lines that just have a single dot.
data - Message data to be prepared.
Resulting normalized messages data.
bool SendData(
Send message data.
Call this function repeatedly for all message data blocks to be sent right after start sending message data with the StartData function.
data - Message data to be sent.
The function returns 1 if the message data was sent to the SMTP server successfully.
bool EndSendingData()
Tell the server that all the message data was sent.
Call this function when you are done with sending the message data with the SendData function.
The function returns 1 if the server accepted the message.
bool ResetConnection()
Reset an already established SMTP connection to the initial state.
Call this function when there was an error sending a message and you need to skip to sending another message without disconnecting.
The function returns 1 if the connection was resetted successfully.
bool Disconnect(
Terminate a previously opened connection.
Call this function after you are done sending your messages.
quit - Boolean option that tells whether the class should perform the final connection quit handshake, or just close the connection without waiting.
The function returns 1 if the connection was successfully closed.
bool SendMessage(
Send a message in a single call.
Call this function if you want to send a single messages to a small number of recipients in a single call.
sender - E-mail address of the sender.
recipients - Array with a list of the e-mail addresses of the recipients of the message.
headers - Array with a list of the header lines of the message.
body - Body data of the message.
The function returns 1 if the message was sent successfully.