DGS SMTP v0.9.2 (12/02/12) - http://www.digitalgenesis.com

Quick Install/Usage:

  0. Untar the distribution. It will create a dgssmtp directory. Several examples follow:

     For .tar.gz files:
       tar xvzf dgssmtp-0.9.2.tar.gz
     For .tar.bz2 files:
       tar xvIf dgssmtp-0.9.2.tar.bz2
        -or-
       tar xvf dgssmtp-0.9.2.tar.bz2 --with-compress-program=bzip2
     For .zip files:
       pkunzip -x dgssmtp-0.9.2.zip
        -or-
       Use WinZip or other GUI zip program.

  1. Copy dgssmtp.php to your source directory and edit your php script.
     Sample code showing how to use DGS SMTP in your script is listed below:

       <?

       include("dgssmtp.php");

       $smtpObj = new dgssmtp("relay.yourdomain.com", "from-user@yourdomain.com", "to-user@yourdomain.com");
       $smtpObj->setSubject("Example Subject");
       $smtpObj->setBody("This is line one of the body.\r\nThis is line two.");

       $smtpObj->sendmail();

       ?>

Public Member Functions:

  Below is a full list of public functions the DGS SMTP class supports:

    dgssmtp(String $server, String $from, String $to)

      This is the constructor. Sets the "Outgoing SMTP Server", "From Address"
      and "To Address". All three values must be passed as a String.

      This is the only function that must be called before sendmail(). All other
      functions just set additional options.

      Returns nothing. Failure will cause an internal error to be set. This error
      will be returned when the sendmail() member function is called.
 

    Boolean setServer(String $server)

      Sets the "Outgoing SMTP Server". This allows you to change the server
      that was set by the constructor. This must be passed as a String.

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean setHostname(String $hostname)

      Sets the hostname of the server that originated the email. If not set,
      DGS SMTP will use the SERVER_NAME enviroment variable. This must be passed
      as a String.

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean setPort(Integer $port)

      Sets the port to use on the "Outgoing SMTP Server". If not set, DGS SMTP
      will default to the standard of port 25. This must be passed as an Integer.

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean setTimeout(Integer $timeout)

      Sets the timeout in seconds for the connect system call. This must be
      passed as a Integer.

      NOTE: This setting is ignored on versions of PHP older than 3.0.9.

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean setFrom(String $from)

      Sets objects "From Address". This must be passed as a String.

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean setTo(String $to)

      Sets objects "To Address". This must be passed as a String.

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean setCc(String/Array $cc)

      Sets objects "Cc Address". This can be passed as a String or an Array
      of Strings.

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean setBcc(String/Array $bcc)

      Sets objects "Bcc Address". This can be passed as a String or an Array
      of Strings.

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean setReplyTo(String/Array $replyTo)

      Sets objects "ReplyTo Address". This can be passed as a String or an Array
      of Strings.

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean setSubject(String $subject)

      Sets objects "Subject". This must be passed as a String.

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean setPriority(Integer/String $priority)

      Sets objects "Priority". This value can be passed as a Integer or a
      String. Valid values are 1 through 5, or the keywords "Lowest", "Low",
      "Normal", "High" and "Highest".

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean setBody(String $body)

      Sets object "Body". This must be passed as a String. Lines within the
      body are seperated by LFCR ("\r\n").

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean setDebug(Integer $flag)

      Sets object debug mode. This value must be passed as an Integer. If set
      to 0, debug is off. If set to 1, debug is on.

      Returns true on success, and false on failure. Failure will cause the
      previous setting to be lost.


    Boolean clearErrors()

      Clears all internal errors.

      Returns true on success. There are no failure conditions.


    Array getErrors()

      Returns an Array of Strings. If there are no errors null is returned.


    Boolean sendmail()

      Causes the object to deliver the email, via SMTP.

      Returns true on success, and false on failure.


Private Memeber Functions:

  Below is a full list of private functions the DGS SMTP class supports:

    Boolean initSendmail()

      Sets and reformats several internal values needed by sendmail(). This
      function should only be called by the sendmail() member function.

      Returns true on success. There are no failure conditions.


    Boolean sanityCheck()

      Verifies that all needed values have been set for the sendmail() member
      function to continue.

      Returns true on success, and false on insanity.


    Boolean isEmailAddress(String/Array $address)

      Verifies that an email address is in a valid format. The function will
      accept an email address in a String, or an Array of Strings.

      Returns true on success, and false on failure. Failure will cause
      an internal error to be set. This error will be returned when the
      sendmail() member function is called.


    processSMTP(Integer $lBound, Integer $uBound, Socket $handle, Boolean $replyFlag)

      Communicates with SMTP server to deliver mail. This function will send
      the commands stored within the classes internal data[] array.
      Set lBound and uBound to Integer values. The variable handle must be
      passed an open Socket connection to an SMTP server. Set replyFlag to
      a Boolean value.

      lBound is the lower bound of which commands to use from data[] to
		send to the SMTP server.

      uBound is the upper bound of which commands to use from data[] to
		send to the SMTP server.

      handle is the open Socket connection to the SMTP server.

      replyFlag when set to true this function will check the code returned
      from each command from the SMTP server for correctness. When set to
      false the function will ignore return codes.

      Returns true on success, and false on failure.
 

    String getReplyCode(Socket $handle)

      Returns a SMTP reply code from an open socket.

      handle is the open Socket connection to the SMTP server.

      If debug is enabled, the reply code will be printed to stdout.

      Returns the numerical reply code from handle. Returns "" on failure.


    Integer putCommand(String $buffer, Socket $handle)

      Writes the passed command to the specified stream.

      buffer is a string containing the command to send to the open
      socket.

      handle is the open Socket connection to the SMTP server.

      If debug is enabled, the command will be printed to stdout.

      Returns the number of bytes written to the socket on success.
      Returns -1 on failure.


    String joinAddresses(Array $addresses)

      Combines an Array of Strings into a comma deliminated String.

      Returns a comma deliminated String on success. Returns "" on failure.

    Array getPHPVersion()

      Returns an Array of Strings containing PHP Version information.

      Index of 0 is major version, index of 1 is minor version and index
      of 2 is sub version. If the PHP version was 4.0.2, then index 0 is
      "4", index 1 is "0" and index 2 is "2".
