Download the PHP package dotkernel/dot-mail without Composer
On this page you can find all versions of the php package dotkernel/dot-mail. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dotkernel/dot-mail
More information about dotkernel/dot-mail
Files in dotkernel/dot-mail
Package dot-mail
Short Description Dotkernel mail component based on symfony mailer
License MIT
Homepage https://github.com/dotkernel/dot-mail
Informations about the package dot-mail
dot-mail
Dotkernel's mail service.
dot-mail is a wrapper on top of symfony mailer
Documentation
Documentation is available at: https://docs.dotkernel.org/dot-mail/.
Version History
| Branch | Release | PSR-11 | Mailer | OSS Lifecycle | PHP Version |
|---|---|---|---|---|---|
| 5.2 | >=5.2.0 |
1 || 2 | symfony/mailer |
||
| 5.1 | <5.2.0 |
1 | symfony/mailer |
||
| 5.0 | <5.1.0 |
1 || 2 | symfony/mailer |
||
| 4.0 | <=4.3.0 |
1 | laminas-mail |
Badges
Installation
Install dotkernel/dot-mail by executing the following Composer command:
Configuration
Mail - Sendmail
If your server has Sendmail installed, update the config/autoload/mail.local.php.dist file by setting the transport key like below
Mail - ESMTP
If you want your application to send mails on e.g., registration, contact, then edit the file config/autoload/mail.local.php.
Set the transport, message_options and smtp_options keys like below.
Under message_options key:
from- email address from whom users will receive emails
Under smtp_options key:
host- the mail server's hostname or IP addressport- the mail server's portconnection_config- fill in theusernameandpasswordkeys with the login details of the email used infromabove- if you want to disable auto_tls set
tlskey to false
Note: all other keys can be left as is.
In config/autoload/local.php add under contact => message_receivers => to key string values with the emails that should receive contact messages
Please add at least one email address in order for a contact message to reach someone
Also feel free to add as many cc as you want under contact => message_receivers => cc key
Sending an e-mail
Below is an example of how to use the email in the most basic way. You can add your own code to it, e.g., to get the user data from a User object or from a config file, to use a template for the body.
Note that addTo is only one of the methods available for the Message class returned by getMessage().
Other useful methods that were not included in the example are addCc(), addBcc(), addReplyTo().
The returned type is boolean, but if the isValid() method is removed, the returned type becomes MailResult which allows the use of getMessage() for a more detailed error message.
See the Testing if an e-mail message is valid section below.
It's optional but recommended to call the above function in a try-catch block to display helpful error messages.
The next example calls the sendBasicMail function from within UserController, but you can implement it in other controllers, just make sure that the controller's construct also includes the FlashMessenger parameter $messenger.
Testing if an e-mail message is valid
After sending an e-mail, you can check if the message was valid or not.
The $this->mailService->send()->isValid() method call will return a boolean value.
If the returned result is true, the e-mail was valid, otherwise the e-mail was invalid.
In case your e-mail was invalid, you can check for any errors using $this->mailService->send()->getMessage().
Using the below logic will let you determine if a message was valid or not and log it. You can implement your own custom error logging logic.
Invalid e-mail messages will not be sent.
Logging outgoing emails
Optionally, you can keep a log of each successfully sent email. This might be useful when you need to know if/when a specific email has been sent out to a recipient.
Logs are stored in the following format:
To enable it, make sure that your config/autoload/mail.local.php has the below log configuration under the dot_mail key:
To disable it, set the value of sent to null.
All versions of dot-mail with dependencies
ext-fileinfo Version *
ext-json Version *
dotkernel/dot-event Version ^4.0
laminas/laminas-servicemanager Version ^3.22 || ^4.0
symfony/mailer Version ^v7.1.6