{"id":20170786,"url":"https://github.com/pear/net_smtp","last_synced_at":"2025-04-05T07:06:45.589Z","repository":{"id":1683953,"uuid":"2411513","full_name":"pear/Net_SMTP","owner":"pear","description":"PHP SMTP Implementation","archived":false,"fork":false,"pushed_at":"2024-04-15T19:42:50.000Z","size":223,"stargazers_count":26,"open_issues_count":4,"forks_count":38,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-05-17T04:43:53.707Z","etag":null,"topics":["php","smtp"],"latest_commit_sha":null,"homepage":"https://pear.php.net/package/net_smtp","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pear.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-09-18T21:29:13.000Z","updated_at":"2024-06-18T12:24:49.339Z","dependencies_parsed_at":"2024-02-10T00:24:27.438Z","dependency_job_id":"0f424289-eb5d-4bb6-a02a-e6081b89959c","html_url":"https://github.com/pear/Net_SMTP","commit_stats":{"total_commits":251,"total_committers":25,"mean_commits":10.04,"dds":"0.24302788844621515","last_synced_commit":"cfd963dc5cc73b4d64c7769e47dfa0f439dec536"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pear%2FNet_SMTP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pear%2FNet_SMTP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pear%2FNet_SMTP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pear%2FNet_SMTP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pear","download_url":"https://codeload.github.com/pear/Net_SMTP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299832,"owners_count":20916190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","smtp"],"created_at":"2024-11-14T01:21:04.528Z","updated_at":"2025-04-05T07:06:45.574Z","avatar_url":"https://github.com/pear.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"======================\n The Net_SMTP Package\n======================\n\n--------------------\n User Documentation\n--------------------\n\n+--------+-----------+----------------------+\n|Author: |Jon Parise |Armin Graefe          |\n+--------+-----------+----------------------+\n|Contact:|jon@php.net|schengawegga@gmail.com|\n+--------+-----------+----------------------+\n\n.. contents:: Table of Contents\n.. section-numbering::\n\nDependencies\n============\n\nThe ``PEAR_Error`` Class\n------------------------\n\nThe Net_SMTP package uses the `PEAR_Error`_ class for all of its `error\nhandling`_.\n\nThe ``Net_Socket`` Package\n--------------------------\n\nThe Net_Socket_ package is used as the basis for all network communications.\nConnection options can be specified via the `$socket_options` construction\nparameter::\n\n    $socket_options = array('ssl' =\u003e array('verify_peer_name' =\u003e false));\n    $smtp = new Net_SMTP($host, null, null, false, 0, $socket_options);\n\n**Note:** PHP 5.6 introduced `OpenSSL changes`_. Peer certificate verification\nis now enabled by default. Although not recommended, `$socket_options` can be\nused to disable peer verification (as shown above).\n\n.. _OpenSSL changes: https://php.net/manual/en/migration56.openssl.php\n\nThe ``Auth_SASL`` Package\n-------------------------\n\nThe `Auth_SASL`_ package is an optional dependency.  If it is available, the\nNet_SMTP package will be able to support the DIGEST-MD5_, CRAM-MD5_ and\nSCRAM-SHA_ SMTP authentication methods. Otherwise, only the LOGIN_ and\nPLAIN_ methods will be available.\n\nError Handling\n==============\n\nAll of the Net_SMTP class's public methods return a PEAR_Error_ object if an\nerror occurs.  The standard way to check for a PEAR_Error object is by using\n`PEAR::isError()`_::\n\n    if (PEAR::isError($error = $smtp-\u003econnect())) {\n        die($error-\u003egetMessage());\n    }\n\n.. _PEAR::isError(): https://pear.php.net/manual/en/core.pear.pear.iserror.php\n\nSMTP Authentication\n===================\n\nThe Net_SMTP package supports the SMTP authentication standard (as defined\nby RFC-2554_).  The Net_SMTP package supports the following authentication\nmethods, in order of preference:\n\n.. _RFC-2554: https://www.ietf.org/rfc/rfc2554.txt\n\nCRAM-MD5 (DEPRECATED)\n--------\n\n**DEPRECATED**\nThis authentication method is no longer secure and should be avoided.\n\nThe CRAM-MD5 authentication method has been superseded by the DIGEST-MD5_\nmethod in terms of security.  It is provided here for compatibility with\nolder SMTP servers that may not support the newer DIGEST-MD5 algorithm.\n\n**Note:** The CRAM-MD5 authentication method is only supported if the\nAUTH_SASL_ package is available.\n\nDIGEST-MD5 (DEPRECATED)\n----------\n\n**DEPRECATED**\nThis authentication method is no longer secure and should be avoided.\n\nThe DIGEST-MD5 authentication method uses `RSA Data Security Inc.`_'s MD5\nMessage Digest algorithm.  It is considered a more secure method of SMTP\nauthentication than PLAIN or LOGIN, while still vulnerable to MitM attacks\nwithout TLS/SSL.\n\n**Note:** The DIGEST-MD5 authentication method is only supported if the\nAUTH_SASL_ package is available.\n\n.. _RSA Data Security Inc.: https://www.rsasecurity.com/\n\nGSSAPI\n------\n\nThe GSSAPI authentication method uses Kerberos 5 protocol (RFC-4120_).\nDoes not use user/password.\nRequires Service Principal ``gssapi_principal`` parameter and\nhas an optional Credentials Cache ``gssapi_cname`` parameter.\nRequires DNS and Key Distribution Center (KDC) setup.\nIt is considered the most secure method of SMTP authentication.\n\n**Note:** The GSSAPI authentication method is only supported\nif the krb5_ php extension is available.\n\n.. _RFC-4120: https://tools.ietf.org/html/rfc4120\n.. _krb5: https://pecl.php.net/package/krb5\n\nLOGIN (DEPRECATED)\n-----\n\n**DEPRECATED**\nThis authentication method is no longer secure and should be avoided.\n\nThe LOGIN authentication method encrypts the user's password using the\nBase64_ encoding scheme.  Because decrypting a Base64-encoded string is\ntrivial.\n\n.. _Base64: https://www.php.net/manual/en/function.base64-encode.php\n\nPLAIN\n-----\n\nThis authentication method is no longer secure and should only be used\nlocal or via an TLS encrypted connection.\n\nThe PLAIN authentication method sends the user's password in plain text.\n\nSCRAM\n--------\n\nIn cryptography, the Salted Challenge Response Authentication Mechanism (SCRAM)\nis a family of modern, password-based challenge–response authentication mechanisms\nproviding authentication to a server.\n\nAvailable mechanisms are SCRAM-SHA-1, SCRAM-SHA-224, SCRAM-SHA-256, SCRAM-SHA-384\nand SCRAM-SHA-512.\n\n**Note:** The SCRAM-SHA authentication method is only supported if the\nAUTH_SASL_ package is available.\n\nXOAUTH2\n-------\n\nThe XOAUTH2 authentication method sends a username and an OAuth2 access token\nas per `Gmail's SASL XOAUTH2 documentation`__.\n\n.. __: https://developers.google.com/gmail/imap/xoauth2-protocol#smtp_protocol_exchange\n\nSecure Connections\n==================\n\nIf `secure socket transports`_ have been enabled in PHP, it is possible to\nestablish a secure connection to the remote SMTP server::\n\n    $smtp = new Net_SMTP('ssl://mail.example.com', 465);\n\nThis example connects to ``mail.example.com`` on port 465 (a common SMTPS\nport) using the ``ssl://`` transport.\n\nTLS/SSL is enabled for authenticated connections by default (via the ``auth()``\nmethod's ``$tls`` parameter), but the |STARTTLS|_ command can also be sent\nmanually using the ``starttls()`` method.\n\n.. _secure socket transports: https://www.php.net/transports\n.. |STARTTLS| replace:: ``STARTTLS``\n.. _STARTTLS: https://tools.ietf.org/html/rfc3207\n\nSending Data\n============\n\nMessage data is sent using the ``data()`` method.  The data can be supplied\nas a single string or as an open file resource.\n\nIf a string is provided, it is passed through the `data quoting`_ system and\nsent to the socket connection as a single block.  These operations are all\nmemory-based, so sending large messages may result in high memory usage.\n\nIf an open file resource is provided, the ``data()`` method will read the\nmessage data from the file line-by-line.  Each chunk will be quoted and sent\nto the socket connection individually, reducing the overall memory overhead of\nthis data sending operation.\n\nHeader data can be specified separately from message body data by passing it\nas the optional second parameter to ``data()``.  This is especially useful\nwhen an open file resource is being used to supply message data because it\nallows header fields (like *Subject:*) to be built dynamically at runtime.\n\n::\n\n    $smtp-\u003edata($fp, \"Subject: My Subject\");\n\nData Quoting\n============\n\nBy default, all outbound string data is quoted in accordance with SMTP\nstandards.  This means that all native Unix (``\\n``) and Mac (``\\r``) line\nendings are converted to Internet-standard CRLF (``\\r\\n``) line endings.\nAlso, because the SMTP protocol uses a single leading period (``.``) to signal\nan end to the message data, single leading periods in the original data\nstring are \"doubled\" (e.g. \"``..``\").\n\nThese string transformation can be expensive when large blocks of data are\ninvolved.  For example, the Net_SMTP package is not aware of MIME parts (it\njust sees the MIME message as one big string of characters), so it is not\nable to skip non-text attachments when searching for characters that may\nneed to be quoted.\n\nBecause of this, it is possible to extend the Net_SMTP class in order to\nimplement your own custom quoting routine.  Just create a new class based on\nthe Net_SMTP class and reimplement the ``quotedata()`` method::\n\n    require 'Net_SMTP.php';\n\n    class Net_SMTP_custom extends Net_SMTP\n    {\n        function quotedata($data)\n        {\n            /* Perform custom data quoting */\n        }\n    }\n\nNote that the ``$data`` parameter will be passed to the ``quotedata()``\nfunction `by reference`_.  This means that you can operate directly on\n``$data``.  It also the overhead of copying a large ``$data`` string to and\nfrom the ``quotedata()`` method.\n\n.. _by reference: https://www.php.net/manual/en/language.references.pass.php\n\nServer Responses\n================\n\nThe Net_SMTP package retains the server's last response for further\ninspection.  The ``getResponse()`` method returns a 2-tuple (two element\narray) containing the server's response code as an integer and the response's\narguments as a string.\n\nUpon a successful connection, the server's greeting string is available via\nthe ``getGreeting()`` method.\n\nDebugging\n=========\n\nThe Net_SMTP package contains built-in debugging output routines (disabled by\ndefault).  Debugging output must be explicitly enabled via the ``setDebug()``\nmethod::\n\n    $smtp-\u003esetDebug(true);\n\nThe debugging messages will be sent to the standard output stream by default.\nIf you need more control over the output, you can optionally install your own\ndebug handler.\n\n::\n\n    function debugHandler($smtp, $message)\n    {\n        echo \"[$smtp-\u003ehost] $message\\n\";\n    }\n\n    $smtp-\u003esetDebug(true, \"debugHandler\");\n\n\nExamples\n========\n\nBasic Use\n---------\n\nThe following script demonstrates how a simple email message can be sent\nusing the Net_SMTP package::\n\n    require 'Net/SMTP.php';\n\n    $host = 'mail.example.com';\n    $from = 'user@example.com';\n    $rcpt = array('recipient1@example.com', 'recipient2@example.com');\n    $subj = \"Subject: Test Message\\n\";\n    $body = \"Body Line 1\\nBody Line 2\";\n\n    /* Create a new Net_SMTP object. */\n    if (! ($smtp = new Net_SMTP($host))) {\n        die(\"Unable to instantiate Net_SMTP object\\n\");\n    }\n\n    /* Connect to the SMTP server. */\n    if (PEAR::isError($e = $smtp-\u003econnect())) {\n        die($e-\u003egetMessage() . \"\\n\");\n    }\n\n    /* Send the 'MAIL FROM:' SMTP command. */\n    if (PEAR::isError($smtp-\u003emailFrom($from))) {\n        die(\"Unable to set sender to \u003c$from\u003e\\n\");\n    }\n\n    /* Address the message to each of the recipients. */\n    foreach ($rcpt as $to) {\n        if (PEAR::isError($res = $smtp-\u003ercptTo($to))) {\n            die(\"Unable to add recipient \u003c$to\u003e: \" . $res-\u003egetMessage() . \"\\n\");\n        }\n    }\n\n    /* Set the body of the message. */\n    if (PEAR::isError($smtp-\u003edata($subj . \"\\r\\n\" . $body))) {\n        die(\"Unable to send data\\n\");\n    }\n\n    /* Disconnect from the SMTP server. */\n    $smtp-\u003edisconnect();\n\n.. _PEAR_Error: https://pear.php.net/manual/en/core.pear.pear-error.php\n.. _Net_Socket: https://pear.php.net/package/Net_Socket\n.. _Auth_SASL: https://pear.php.net/package/Auth_SASL\n\n.. vim: tabstop=4 shiftwidth=4 softtabstop=4 expandtab textwidth=78 ft=rst:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpear%2Fnet_smtp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpear%2Fnet_smtp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpear%2Fnet_smtp/lists"}