smtp.class.php
Class: SMTP
Author: aldo of http://mschat.net/
This class can be used to send email with SMTP instead of mail().
NOTE: This WILL work with GMail! Use ssl://smtp.gmail.com for the SMTP host and 465 as the SMTP port, and false for TLS.
This script is released under the Lesser GPL.
Usage:
$smtp = new SMTP(SMTP_HOST, SMTP_PORT, IS_TLS); $smtp->auth(SMTP_USER, SMTP_PASS); $smtp->mail_from(WHO_IS_THE_EMAIL_FROM); $smtp->send(TO, SUBJECT, MESSAGE, ADDITIONAL_HEADERS); // Of course replacing everything with the necessary stuff. # # __construct([string $smtp_host = null[, int $smtp_port = 25[, bool $is_tls = false[, int $tryfor = 5]]]]); # string $smtp_host - The address to the SMTP host, like mail.example.com # int $smtp_port - The port the SMTP server is listening on, usually 25, # but not always! (So, of course, defaults to 25) # bool $is_tls - Whether or not to initiate a TLS connection with the server. # Not always supported, but after you connect, you can check if # the connection accepted it with the method is_tls(). # int $tryfor - How many seconds that should be given to connect to the SMTP # server and how long should be given for execution of an fread. # # # Connects to the SMTP Server. # # bool connect(string $smtp_host[, int $smtp_port[, bool $is_tls = false[, int $tryfor = 5]]]); # For more information, look at __construct() above. # # returns bool - If the connection was made, TRUE is issued, otherwise FALSE. # # # Retrieves the response from the SMTP server. # # mixed get_response(); # # returns mixed - A String containing the response will be returned if there # was one, but if none (Like your not connected) FALSE is issued. # # # Initiates a TLS connection with the SMTP Server. # # bool init_tls(); # # returns bool - If TLS was accepted by the server, TRUE is returned. Otherwise FALSE. # # # Sends EHLO or HELO if EHLO is not supported by the server. # # bool send_hello(); # # returns bool - If it was successfully recieved by the SMTP Server, TRUE is issued. Otherwise FALSE. # # # Authenticates with the SMTP server. # # bool auth(string $username, string $password); # string $username - Your SMTP username. # string $password - Your SMTP password. # # returns bool - TRUE is issued if you authenticated with the server successfully, otherwise FALSE. # # # Sends the MAIL FROM header which tells the SMTP Server who the email # is sent from. # # bool mail_from(string $from); # string $from - The email to set the from too. Ex: you@example.com # # returns bool - TRUE if it was accepted, FALSE if not. # # NOTE: Please note that you cannot do "Your name" <you@example.com> as # it will not be accepted. You can specify that, if you want as # FROM in the additional_headers array parameter in SMTP::send() # # # Sends the email and any headers to the SMTP Server. # # bool send(mixed $to, string $subject, string $message[, string $alt_message = null[, array $additional_headers = array()]]); # mixed $to - This can be an array of addresses, or a string of one addresses # or multiple addresses separated by commas. # string $subject - The Subject of the email message. # string $message - The email message to send. # string $alt_message - If HTML is set, this can be set so if the recievers email client # has HTML disabled or is not supported. # array $additional_headers - An associative array (Header => Value) containing # additional headers you want set. # # returns bool - If the message was sent without error, TRUE is issued. # Otherwise false is returned. # # NOTE: If the message was sent successfully, the connection to the SMTP server # is automatically closed. # # # Close the connection to the current SMTP server. # # bool close([bool $quit = false]); # bool $quit - TRUE if you want the QUIT command to be issued to close # the connection with the SMTP server. # # returns bool - If the connection was closed, TRUE is issued. Otherwise FALSE. # # # Sets whether or not the message will allow HTML. # # bool set_html([bool $html_allowed = true]); # bool $html_allowed - TRUE if you want to allow HTML to be sent in the message. # # returns bool - TRUE if the setting was successfully changed, FALSE otherwise. # # # Sets the priority of the message. # # bool set_priority([string $priority = 'normal']); # string $priority - The priority to set for the message. Acceptable values are: # highest, high, normal, belownormal and low. # # returns bool - TRUE if the setting was successfully changed, FALSE otherwise. # # # Sets your desired email charset. Such as UTF-8 # # bool set_charset($charset); # string $charset - The chacter set to apply to the email. # # returns bool - TRUE if the setting was successfully changed, FALSE otherwise. # # # Returns errors reported by this class. # # mixed error([$last_error = true]); # $last_error - TRUE if you want the last error returned. If FALSE is set, then the # whole array of errors is returned. # # returns mixed - If $last_error is true, a string is returned, if it is false, an array # will be returned. FALSE will be returned if there are no errors. #







