Download the PHP package technicalguru/email without Composer

On this page you can find all versions of the php package technicalguru/email. 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 email

php-email

Provides an object-oriented way to send and queue emails.

There is a need to send e-mails in almost all projects, e.g. for user registration or password reset functions. Most e-mails sent are very easy. Sophisticated features like PGP encryption etc is not required. This library offers a way to create such e-mails without setting up the PHPMailer (the underlying library), to send multiple e-mails and even to defer sending e-mail sending by using a queue backed by a database - and all in an object-oriented way.

Features are:

License

This project is licensed under GNU LGPL 3.0.

Installation

By Composer

By Package Download

You can download the source code packages from GitHub Release Page

How to use it

Create Main Configuration Object

The central class for configuration is the EmailConfig. It holds all necessary information. Let's start with the basic skeleton:

The lines above create the configuration and tells it to use the timezone Europe/Berlin when it needs to create timestamps. This is required mainly when e-mails are queued and the timestamp needs to be recorded. This value is optional and defaults to UTC.

Next, a default sender address is configured. The default sender will be used when a specific e-mail to be sent does not define a sender address. Creating e-mail addresses is explained further below.

The subject prefix is used on every e-mail to be sent later. Subjects will be prefixed with this string. The default is NULL and will not modify the subject.

A debug address is required only when you need to send a test mail.

Create SMTP Configuration

We still need to tell where our SMTP server is located. So this is how you set these values:

Most options are self-explaining. $auth tells underlying PHPMailer whether to authenticate with given user credentials. $secureOption is defined by PHPMailer and shall have value smtps or starttls. See the PHPMailer documentation for further information.

All properties can be set by using a setter:

Authentication credentials can also be set by using the \TgUtils\Auth\CredentialsProvider interface from technicalguru/utils package:

Create the Main MailQueue object

Now it's time to create our central MailQueue object:

You are ready send your first e-mail.

Send a Test E-Mail

There is a fast and easy way to check whether your setup works correctly:

Send an E-Mail

We have setup the minimum requirements to send an e-mail:

That's it. The code snippet above is all you would need in your application code in order to send e-mails. Configuration and setup shall be buried somewhere in your infrastructure setup.

Hot to add Attachments or embed Images

Attaching files or embedding images is simple. You will need to have the file available and readable on the filesystem:

Note the third parameter of embedded images. It defines a unique ID within your HTML email which you can reference by

The MailQueue will leave all your attachments untouched on your filesystem. However, sometimes you may wish to get rid of the file after you sent the e-mail. The constructor takes two additional arguments:

The first boolean will trigger the file to be deleted after the e-mail was sent successfully. The second boolean tells whether the file can be deleted when sending failed. Using these parameters you don't need to take care about temporary files anymore. Especially when it comes to queueing and deferred sending.

Mail Modes

MailQueue supports so-called Mail Modes. They tell the mailer object how to generally treat e-mails. This comes comfortable when you're either testing a setup, when you are in an environment that has real e-mail addresses (such as User Acceptance Test environments) or when actually sending out e-mails doesn't make much sense.

These modes are available:

Blocking all E-Mails

Blocking all e-mails to be sent or queued is quite easy:

The same method can be used on the central EmailConfig object.

Rerouting all E-Mails

You need a RerouteConfig configuration to be set in the main configuration. You can set this up-front when creating the config object, or alltogether when setting the mail mode:

Set a Developer as BCC on all sent E-mails

You need a BccConfig configuration to be set in the main configuration. You can set this up-front when creating the config object, or alltogether when setting the mail mode:

Queue E-Mails to be sent later

One drawback of sending out e-mails directly from application code is the that it is time-consuming. Your user needs to wait for the sending to complete before she/he can see any response from your application. Queueing e-mails is the solution as sending is deferred (preferrable to a cron job) and the user receives her/his application response fast.

You will need a TgDatabase\Database object to queue e-mails. Otherwise, EmailQueue will throw exceptions when you try to queue e-mails. Please refer to the TgDatabase\Database documentation about how to create the Database object. Setup the according EmailsDAO and EmailQueue as follows:

The mailer will automatically create the queue table if it does not exist.

Once, the EmailsDAO is available, you can easily queue e-mails:

Processing the E-Mail Queue

You can process the queue in another call or during a cronjob:

The argument $maxSeconds will ensure that the processing stops when the time limit has been reached. The argument is optional and defaults to 60 seconds.

How to Create an E-mail Address

There are multiple ways to create e-mail addresses. All mailing components use an EmailAddress object. You can use this object as an argument whereever e-mail addresses are expected. Several ways exist to create such an object.

This means that you can use these flavours when creating e-mails:

Creating Configuration Objects from Objects, Arrays or JSON strings

The configuration objects introduced above can also be created using JSON strings, objects or associative arrays. The following snippets describe the JSON objects in short notation.

Each of the configuration classes provide a static from() method that take these types as an argument and return the configuration object itself:

Sending and queueing multiple e-mails

It is possible to pass an array of Email objects to send() and queue() functions. However, especially for sending e-mails immediately you should be aware that this can take some time. A better strategy is to queue mass mailings.

Development Notes

Most PHPUnit tests will not be executed when there is no SMTP server or database available. The unit tests will check for environment variable EMAIL_TEST_SMTP and EMAIL_DATABASE. There is a bash script available, set-test-env.sh that creates those variables for you. Copy it to e.g. set-local-test-env.sh and follow instructions in the file.

Contribution

Report a bug, request an enhancement or pull request at the GitHub Issue Tracker.


All versions of email with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0.0
technicalguru/utils Version ~1
phpmailer/phpmailer Version ^6.1
symfony/polyfill-mbstring Version ^1.20
technicalguru/database Version ^1.3
phpunit/phpunit Version ^9.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 technicalguru/email contains the following files

Loading the files please wait ....