Download the PHP package utopia-php/smtp without Composer

On this page you can find all versions of the php package utopia-php/smtp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package smtp

Utopia SMTP

[!IMPORTANT] This repository is a read-only mirror of packages/smtp in appwrite/appwrite. Development happens there — please open issues and pull requests against appwrite/appwrite.

Lite and fast micro PHP SMTP library that is easy to learn.

Submits mail to a configured server: RFC 5321 on the wire, RFC 5322 and MIME for the message, with STARTTLS and authentication. It reports which recipients were accepted and whether a refusal is worth retrying.

Installation

Usage

The connection opens on the first send, so nothing in the constructor touches the network.

Envelope and content

MAIL FROM and RCPT TO carry the addresses that decide where the message goes. The headers decide what the reader sees. They are allowed to disagree, and for a blind recipient they must: Bcc addresses go in the envelope and appear in no header.

send() derives the envelope from the message. To send bytes built elsewhere, pass the envelope yourself:

Content may be a string or an iterable of chunks. The client never parses it.

Results and failures

A server may refuse some recipients and accept others, and the message still reaches the rest.

A TransactionException is thrown only when every recipient is refused. Its Reply says whether the same message could succeed later:

Every Reply carries an Outcome, which is the four reply classes of RFC 5321 section 4.2.1 rather than a set of booleans:

Case Codes Means
Success 2yz The command worked.
Intermediate 3yz Understood, and the server wants more — the 354 before message data.
Transient 4yz Failed, but the same command may work later.
Permanent 5yz Failed, and sending it again changes nothing.

Failures

Everything the library raises at runtime extends Utopia\SMTP\Exception\SmtpException, so one catch covers any way a send can go wrong:

Exception Raised when
ConnectionException The socket could not be opened, read, written or upgraded.
TimeoutException A deadline passed. Extends ConnectionException.
ProtocolException The server said something that is not a reply, or not one the command allows.
AuthenticationException No mechanism was shared, or the credentials were refused.
TransactionException The envelope or the data was refused. Carries the Reply.
CapabilityException The server cannot carry this message, such as a size above what it advertises.
MessageException The message could not be produced, such as an attachment that stopped being readable.

Mistakes in the calling code are deliberately outside that hierarchy. An address that is not an address, or a header the message owns, raises the SPL InvalidArgumentException; using a transport that was never connected raises LogicException. Catching SmtpException therefore never hides a bug in your own code.

Encryption

Case Behaviour
Opportunistic Upgrade when the server advertises STARTTLS. The default.
StartTls Upgrade, and fail when the server does not offer it.
Implicit TLS from the first byte, as RFC 8314 asks for on port 465.
None Plaintext, never upgraded.

After an upgrade the client reissues EHLO and discards everything the server said beforehand, per RFC 3207 section 4.2.

Certificate checking lives on the transport. Who signed it and who presented it are separate questions, so refusing to ask the first is not a reason to skip the second:

Case Issuer Hostname
Full Trusted chain required. The default. Checked.
SelfSigned Any. Checked.
None Any. Not checked.

Authentication

Authenticators are tried in the order given, against what the server advertises, so the order is the security policy. Auth\Plain, Auth\Login and Auth\XOAuth2 ship with the library, and the Authenticator interface takes anything else.

Messages

The MIME structure follows from what is set, rather than being chosen:

Content Structure
Text alone text/plain
Markup alone text/html
Both multipart/alternative
An inline attachment multipart/related around the above
An ordinary attachment multipart/mixed around the above

Attachments added by path are read while the message is written, so a large file is never held in memory twice. Encoding is decided for you: quoted-printable for text, base64 for attachments, RFC 2047 encoded words for headers outside ASCII.

Header fields are folded to the 78 octet line length of RFC 5322, and encoded words are split on character boundaries so none passes the 75 the specification allows it. A long recipient list or a subject full of accents therefore stays within the limits a server enforces.

Transports

Transport\Native uses streams and is the default choice. Under Swoole's runtime hook it yields the scheduler like any other hooked stream.

Transport\Swoole is coroutine-native and yields whether or not the hook is on, which matters where the hook for streams is switched off. It needs ext-swoole, and it must be built inside a coroutine.

One difference is worth knowing before choosing it. Swoole checks a certificate name with X509_check_host(), which reads the DNS entries and not the address ones, so dialling an IP literal cannot pass verification however the certificate is written. The stream transport checks both. Give Tls a peerName the certificate carries, or ask for Verification::None; the transport says as much rather than letting the handshake fail with nothing to go on.

A Client is one connection. Pooling belongs to utopia-php/pools, so there is no keep-alive setting here. What the client does offer a holder is the means to reuse a connection safely: a session the server has closed with 421 is dropped on the spot, and the next send() dials again on its own. A server that closes an idle session without a word is only found out by the next command, which would be MAIL FROM and the message with it, so a holder asks first once the session has sat long enough:

Do not ping on every message. A server may drop a session that sends too many commands that carry no mail.

A Client belongs to one caller at a time. SMTP is a strict request and reply protocol over one socket, so two coroutines sharing an instance would read each other's replies. Hold one per coroutine, or check one out of a pool for the length of a send.

Extensions

STARTTLS, AUTH, SIZE, 8BITMIME, SMTPUTF8 and ENHANCEDSTATUSCODES are used when the server advertises them. A message with a non-ASCII local part is refused before sending when the server cannot carry it. PIPELINING is parsed but not yet used.

Timeouts

Reaching a server and hearing back from it fail differently and deserve different patience:

The defaults are ten seconds to connect and thirty to read or write. Each applies per operation rather than per session, so a large message is bounded by its own size and not by a single deadline for the whole exchange. A handshake counts as connecting.

A host that is down should be given up on quickly, while the reply after the final dot can take as long as the server needs to scan the message — RFC 5321 section 4.5.3.2 asks for ten minutes there. The specification wants six separate minimums; three knobs is the useful part of that, and the deviation is deliberate.

Testing

License

MIT


All versions of smtp with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package utopia-php/smtp contains the following files

Loading the files please wait ...