SMTP - PHP SMTP class
Version: 1.02
License: LGPL, see LICENSE
PHP version: 5
Required modules: standard, streams
Required packages: none
Author: Chris Ryan
Define an SMTP class that can be used to connect and communicate with any SMTP server. It implements all the SMTP functions defined in RFC 821 except TURN.
From: phpmailer.sourceforge.net.
2006-12-22 Umberto Salsi:
Converted from PHP4 to PHP5.
Added PHPLint meta-code.
Exceptions support added.
Source available at
www.icosaedro.it/phpmailer.
class SMTP
SMTP is RFC 821 compliant and 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.
Some methods can return exceptions of the class ErrorException indicating something goes wrong talking to the server, or the server did not understand the command. Some others methods
{
boolean $debug = FALSEEnable debugging messages
boolean $debug_stderr = FALSESend debugging messages to stderr rather than to stdout.
void __construct()Initialize the class so that the data is in a known state.
void Close()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.
boolean Connected()Returns TRUE if connected to a server otherwise FALSE
void Connect(string $host, int $port = 25, int $tval = 30)
throws ErrorExceptionConnect to the server specified on the port specified.
$tval is the max time to wait (seconds) for the connection be established with the server, then an exception is raised.
SMTP CODE SUCCESS: 220
SMTP CODE FAILURE: 421void Authenticate(string $username, string $password)
throws ErrorExceptionPerforms SMTP authentication. Must be run after running the ::Hello() method.
void Data(string $msg_data)
throws ErrorExceptionIssues 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 seperated by and additional <CRLF>.
Implements RFC 821: DATA
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,421array[int]string Expand(string $name)
throws ErrorExceptionExpand takes the name and asks the server to list all the people who are members of the _list_. Expand will return back and array of the result or FALSE if an error occurs. Each value in the array returned has the format of: [ <full-name> <sp> ] <path> The definition of <path> is defined in RFC 821
Implements RFC 821: EXPN <SP> <string> <CRLF>
SMTP CODE SUCCESS: 250
SMTP CODE FAILURE: 550
SMTP CODE ERROR : 500,501,502,504,421void SendHello(string $hello, string $host)
throws ErrorExceptionSends a HELO/EHLO command.
void Hello(string $host = "")
throws ErrorExceptionSends 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, 421string Help(string $keyword = "")
throws ErrorExceptionGets help information on the keyword specified.
If the keyword is not specified then returns generic help, ussually containing a list of keywords that help is available on. This function returns the results back to the user. It is up to the user to handle the returned data.
Implements RFC 821: HELP [ <SP> <string> ] <CRLF>
SMTP CODE SUCCESS: 211,214
SMTP CODE ERROR : 500,501,502,504,421void Mail(string $from)
throws ErrorExceptionStarts a mail transaction from the email address specified in $from 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
void Noop()
throws ErrorExceptionSends the command NOOP to the SMTP server.
Implements from RFC 821: NOOP <CRLF>
SMTP CODE SUCCESS: 250
SMTP CODE ERROR : 500, 421void Quit()
throws ErrorExceptionSends the quit command to the server and then closes the socket.
Implements from RFC 821: QUIT <CRLF>
SMTP CODE SUCCESS: 221
SMTP CODE ERROR : 500void Recipient(string $to)
throws ErrorExceptionSends 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,421void Reset()
throws ErrorExceptionSends the RSET command to abort and transaction that is currently in progress.
Implements RFC 821: RSET <CRLF>
SMTP CODE SUCCESS: 250
SMTP CODE ERROR : 500,501,504,421void Send(string $from)
throws ErrorExceptionStarts 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.
Implements RFC 821: SEND <SP> FROM:<reverse-path> <CRLF>
SMTP CODE SUCCESS: 250
SMTP CODE SUCCESS: 552,451,452
SMTP CODE SUCCESS: 500,501,502,421void SendAndMail(string $from)
throws ErrorExceptionStarts 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,421void SendOrMail(string $from)
throws ErrorExceptionStarts 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 or mail it to them if they are not.
Implements RFC 821: SOML <SP> FROM:<reverse-path> <CRLF>
SMTP CODE SUCCESS: 250
SMTP CODE SUCCESS: 552,451,452
SMTP CODE SUCCESS: 500,501,502,421void Turn()
throws ErrorExceptionThis is an optional command for SMTP that this class does not support. This method is here to make the RFC 821 Definition complete for this class and __may__ be implemented in the future
Implements from RFC 821: TURN <CRLF>
SMTP CODE SUCCESS: 250
SMTP CODE FAILURE: 502
SMTP CODE ERROR : 500, 503int Verify(string $name)
throws ErrorExceptionVerifies that the name is recognized by the server. Returns the result code from the server (see below).
Implements RFC 821: VRFY <SP> <string> <CRLF>
SMTP CODE SUCCESS: 250,251
SMTP CODE FAILURE: 550,551,553
SMTP CODE ERROR : 500,501,502,421NOTE. See RFC 2821 for even more result codes.
}
Generated by PHPLint Documentator