From 66c6b927402564b8d1d489809f052ad465805275 Mon Sep 17 00:00:00 2001 From: arhimede Date: Mon, 6 Jan 2025 10:33:45 +0000 Subject: [PATCH] Automated deployment: Mon Jan 6 10:33:45 UTC 2025 5.1.3 --- index.html | 8 +- search/search_index.json | 2 +- sitemap.xml | 26 +- sitemap.xml.gz | Bin 262 -> 276 bytes v5/configuration/index.html | 6 + v5/installation/index.html | 6 + v5/overview/index.html | 6 + v5/transports/index.html | 12 + v5/upgrade-v4-to-v5/index.html | 573 +++++++++++++++++++++++++++++++++ v5/usage/index.html | 6 + 10 files changed, 632 insertions(+), 13 deletions(-) create mode 100644 v5/upgrade-v4-to-v5/index.html diff --git a/index.html b/index.html index 16a6d04..9abb6a7 100644 --- a/index.html +++ b/index.html @@ -240,6 +240,12 @@ + + + + @@ -448,5 +454,5 @@ diff --git a/search/search_index.json b/search/search_index.json index 2211bf4..d005ddc 100644 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"dot-mail [!IMPORTANT] dot-mail is a wrapper on top of symfony mailer dot-mail badges Installation Install dotkernel/dot-mail by executing the following Composer command: composer require dotkernel/dot-mail 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 <?php return [ 'dot_mail' => [ 'default' => [ //... 'transport' => 'sendmail', //... ] ] ] 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 address port - the mail server's port connection_config - fill in the username and password keys with the login details of the email used in from above if you want to disable auto_tls set tls key to false Note: all other keys can be left as is. <?php return [ 'dot_mail' => [ 'default' => [ //... 'transport' => 'esmtp' 'message_options' => [ 'from' => '', //... ], 'smtp_options' => [ 'host' => '', 'port' => 25, 'connection_config' => [ 'username' => '', 'password' => '', 'tls' => null, ] ] //... ] ] ] In config/autoload/local.php add under contact => message_receivers => to key string values with the emails that should receive contact messages Note: Please add at least 1 email address in order for 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. public function sendBasicMail() { $this->mailService->setBody('Email body'); $this->mailService->setSubject('Email subject'); $this->mailService->getMessage()->addTo('email@example.com', 'User name'); $this->mailService->getMessage()->setEncoding('utf-8'); return $this->mailService->send()->isValid(); } 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 . try { $this->userService->sendBasicMail(); $this->messenger->addSuccess('The mail was sent successfully', 'user-login'); //more code... } catch (Exception $exception) { $this->messenger->addError($exception->getMessage(), 'user-login'); //more code... } 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. $result = $this->mailService->send(); if (! $result->isValid()) { //log the error error_log($result->getMessage()); } 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: [YYYY-MM-DD HH:MM:SS]: {\"subject\":\"Test subject\",\"to\":[\"Test Account <test@dotkernel.com>\"],\"cc\":[],\"bcc\":[]}. In order to enable it, make sure that your config/autoload/mail.local.php has the below log configuration under the dot_mail key: <?php return [ 'dot_mail' => [ ... 'log' => [ 'sent' => getcwd() . '/log/mail/sent.log' ] ] ]; To disable it, set the value of sent to null .","title":"Home"},{"location":"#dot-mail","text":"[!IMPORTANT] dot-mail is a wrapper on top of symfony mailer","title":"dot-mail"},{"location":"#dot-mail-badges","text":"","title":"dot-mail badges"},{"location":"#installation","text":"Install dotkernel/dot-mail by executing the following Composer command: composer require dotkernel/dot-mail","title":"Installation"},{"location":"#configuration","text":"","title":"Configuration"},{"location":"v4/configuration/","text":"Configuration Register dot-mail in you project by adding Dot\\Mail\\ConfigProvider::class to your configuration aggregator (to config/config.php for example). After registering the ConfigProvider copy the configuration file config/mail.global.php.dist into your project's config/autoload/ directory as mail.global.php . The resulting mail.global.php contains the necessary configurations for all available transport types, message options and logging options in one place. The config file provides a set of default values available to all mails under the dot-mail.default key. Many of these options can be programmatically set when sending the actual email. An example of this is the dot-mail.default.message_options key, which can be filled in with default message values to be available to all emails. When sending the actual email, these values can be overwritten by using an available \"setter\" function, supplemented by using \"add\" functions or simply left as the default. // setter will overwrite existing destination email $this->mailService->getMessage()->setTo(\"receiver@email.com\"); // existing destination email kept, new destination email added alongside it $this->mailService->getMessage()->addTo(\"receiver@email.com\"); Transport configuration dot-mail uses the transport key under the main dot_mail configuration key to select the email transport. It has four email transport classes available by default ( Sendmail , Smtp , File , InMemory ), one of which is to be added under the dot_mail.transport key for use. Both Sendmail and InMemory transports requires no specific configuration to use by default. Sending email with the Smtp transport requires valid data for the values under dot-mail.default.smtp_options , which is only used in this case. The dot_mail.default.save_sent_message_folder key may be uncommented when using this transport, saving a copy of all sent email to a certain IMAP folder. Using Laminas\\Mail\\Transport\\File as the transport will require uncommenting the dot-mail.default.file_options key. The configured path must be a writable directory 'file_options' => [ 'path' => 'data/mail/output', //'callback' => null, ], If no callback is provided to specify a new file name format, the messages will be saved in files using the default format set in Laminas\\Mail\\Transport\\FileOptions . // Example of a custom format 'callback' => static fn() => sprintf('DotMail%d_%s.log', time(), 'customFormat'), Logging configuration Uncommenting the dot-mail.log key will save a copy of all sent emails' subject, recipient addresses, cc and bcc addresses alongside a timestamp. In order to enable it, make sure that your mail.local.php has the below log configuration under the dot_mail key: <?php return [ 'dot_mail' => [ ... 'log' => [ 'sent' => getcwd() . '/log/mail/sent.log' ] ] ]; To disable it, set the value of sent to null .","title":"Configuration"},{"location":"v4/configuration/#configuration","text":"Register dot-mail in you project by adding Dot\\Mail\\ConfigProvider::class to your configuration aggregator (to config/config.php for example). After registering the ConfigProvider copy the configuration file config/mail.global.php.dist into your project's config/autoload/ directory as mail.global.php . The resulting mail.global.php contains the necessary configurations for all available transport types, message options and logging options in one place. The config file provides a set of default values available to all mails under the dot-mail.default key. Many of these options can be programmatically set when sending the actual email. An example of this is the dot-mail.default.message_options key, which can be filled in with default message values to be available to all emails. When sending the actual email, these values can be overwritten by using an available \"setter\" function, supplemented by using \"add\" functions or simply left as the default. // setter will overwrite existing destination email $this->mailService->getMessage()->setTo(\"receiver@email.com\"); // existing destination email kept, new destination email added alongside it $this->mailService->getMessage()->addTo(\"receiver@email.com\");","title":"Configuration"},{"location":"v4/configuration/#transport-configuration","text":"dot-mail uses the transport key under the main dot_mail configuration key to select the email transport. It has four email transport classes available by default ( Sendmail , Smtp , File , InMemory ), one of which is to be added under the dot_mail.transport key for use. Both Sendmail and InMemory transports requires no specific configuration to use by default. Sending email with the Smtp transport requires valid data for the values under dot-mail.default.smtp_options , which is only used in this case. The dot_mail.default.save_sent_message_folder key may be uncommented when using this transport, saving a copy of all sent email to a certain IMAP folder. Using Laminas\\Mail\\Transport\\File as the transport will require uncommenting the dot-mail.default.file_options key. The configured path must be a writable directory 'file_options' => [ 'path' => 'data/mail/output', //'callback' => null, ], If no callback is provided to specify a new file name format, the messages will be saved in files using the default format set in Laminas\\Mail\\Transport\\FileOptions . // Example of a custom format 'callback' => static fn() => sprintf('DotMail%d_%s.log', time(), 'customFormat'),","title":"Transport configuration"},{"location":"v4/configuration/#logging-configuration","text":"Uncommenting the dot-mail.log key will save a copy of all sent emails' subject, recipient addresses, cc and bcc addresses alongside a timestamp. In order to enable it, make sure that your mail.local.php has the below log configuration under the dot_mail key: <?php return [ 'dot_mail' => [ ... 'log' => [ 'sent' => getcwd() . '/log/mail/sent.log' ] ] ]; To disable it, set the value of sent to null .","title":"Logging configuration"},{"location":"v4/installation/","text":"Installation Install dotkernel/dot-mail by executing the following Composer command: composer require dotkernel/dot-mail","title":"Installation"},{"location":"v4/installation/#installation","text":"Install dotkernel/dot-mail by executing the following Composer command: composer require dotkernel/dot-mail","title":"Installation"},{"location":"v4/overview/","text":"Overview dot-mail is a wrapper on top of laminas-mail Extra features the option to log the results of the mailing process it provides the developer with more information and greater control.","title":"Overview"},{"location":"v4/overview/#overview","text":"dot-mail is a wrapper on top of laminas-mail","title":"Overview"},{"location":"v4/overview/#extra-features","text":"the option to log the results of the mailing process it provides the developer with more information and greater control.","title":"Extra features"},{"location":"v4/transports/","text":"Transports dot-mail can use any transport class that implements Laminas\\Mail\\Transport\\TransportInterface , with the four standard transports available being: Laminas\\Mail\\Transport\\Sendmail - the default transport set in the config file Laminas\\Mail\\Transport\\Smtp Laminas\\Mail\\Transport\\File Laminas\\Mail\\Transport\\InMemory Feel free to use any custom transport you desire, provided it implements the mentioned TransportInterface . Sendmail is a wrapper over PHP's mail() function, and as such has a different behaviour on Windows than on nix systems. Using sendmail on Windows will not work in combination with * addBcc() . Note: emails sent using the sendmail transport will be more often delivered to SPAM. Smtp connects to the configured SMTP host in order to handle sending emails. Saving a copy of an outgoing mail into a folder is possible for this transport only, and is done by uncommenting save_sent_message_folder in the config file mail.local.php under dot_mail.default . Common folder names are INBOX , INBOX.Archive , INBOX.Drafts , INBOX.Sent , INBOX.Spam , INBOX.Trash . If you have MailService available in your class, you can call $this->mailService->getFolderGlobalNames() to list the folder global names for the email you are using. Multiple folders can be added to the save_sent_message_folder key to save a copy of the outgoing email in each folder. File writes each message individually in a file named after the configured format, placed in the configured directory. From here the files may be used for sending via another transport mechanism, or simply as logs. InMemory saves the message in memory, allowing access to the last \"sent\" message via the getLastMessage() function. As the email is not sent, this transport can be helpful in development, with the access to the message being potentially useful in tests as well $this->mailService->setBody('First email body'); $this->mailService->setSubject('First email subject'); $this->mailService->getMessage()->setTo('email@example.com'); // The email is not sent to the email, instead it is stored in memory $this->mailService->send(); $this->mailService->setBody('Second email body'); $this->mailService->setSubject('Second email subject'); $this->mailService->getMessage()->setTo('email@example.com'); // The email is not sent to the email either, it overwrites the previously \"sent\" email in memory $this->mailService->send(); // Returns the second email's Laminas\\Mail\\Message object from memory $lastMessage = $this->mailService()->getTransport()->getLastMessage();","title":"Transports"},{"location":"v4/transports/#transports","text":"dot-mail can use any transport class that implements Laminas\\Mail\\Transport\\TransportInterface , with the four standard transports available being: Laminas\\Mail\\Transport\\Sendmail - the default transport set in the config file Laminas\\Mail\\Transport\\Smtp Laminas\\Mail\\Transport\\File Laminas\\Mail\\Transport\\InMemory Feel free to use any custom transport you desire, provided it implements the mentioned TransportInterface . Sendmail is a wrapper over PHP's mail() function, and as such has a different behaviour on Windows than on nix systems. Using sendmail on Windows will not work in combination with * addBcc() . Note: emails sent using the sendmail transport will be more often delivered to SPAM. Smtp connects to the configured SMTP host in order to handle sending emails. Saving a copy of an outgoing mail into a folder is possible for this transport only, and is done by uncommenting save_sent_message_folder in the config file mail.local.php under dot_mail.default . Common folder names are INBOX , INBOX.Archive , INBOX.Drafts , INBOX.Sent , INBOX.Spam , INBOX.Trash . If you have MailService available in your class, you can call $this->mailService->getFolderGlobalNames() to list the folder global names for the email you are using. Multiple folders can be added to the save_sent_message_folder key to save a copy of the outgoing email in each folder. File writes each message individually in a file named after the configured format, placed in the configured directory. From here the files may be used for sending via another transport mechanism, or simply as logs. InMemory saves the message in memory, allowing access to the last \"sent\" message via the getLastMessage() function. As the email is not sent, this transport can be helpful in development, with the access to the message being potentially useful in tests as well $this->mailService->setBody('First email body'); $this->mailService->setSubject('First email subject'); $this->mailService->getMessage()->setTo('email@example.com'); // The email is not sent to the email, instead it is stored in memory $this->mailService->send(); $this->mailService->setBody('Second email body'); $this->mailService->setSubject('Second email subject'); $this->mailService->getMessage()->setTo('email@example.com'); // The email is not sent to the email either, it overwrites the previously \"sent\" email in memory $this->mailService->send(); // Returns the second email's Laminas\\Mail\\Message object from memory $lastMessage = $this->mailService()->getTransport()->getLastMessage();","title":"Transports"},{"location":"v4/usage/","text":"Usage 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. public function sendBasicMail() { $this->mailService->setBody('Email body'); $this->mailService->setSubject('Email subject'); $this->mailService->getMessage()->addTo('email@example.com', 'User name'); $this->mailService->getMessage()->setEncoding('utf-8'); return $this->mailService->send()->isValid(); } 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 . try { $this->userService->sendBasicMail(); $this->messenger->addSuccess('The mail was sent successfully', 'user-login'); //more code... } catch (Exception $exception) { $this->messenger->addError($exception->getMessage(), 'user-login'); //more code... } 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. $result = $this->mailService->send(); if (! $result->isValid()) { //log the error error_log($result->getMessage()); } 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: [YYYY-MM-DD HH:MM:SS]: {\"subject\":\"Test subject\",\"to\":[\"Test Account <test@dotkernel.com>\"],\"cc\":[],\"bcc\":[]} . Each email is saved via the dotkernel/dot-log component in the shown JSON format, in the single file configured under the dot-mail.log.sent key. To disable it, set the value of dot-mail.log.sent to null . Transport usage Transports","title":"Usage"},{"location":"v4/usage/#usage","text":"","title":"Usage"},{"location":"v4/usage/#sending-an-e-mail","text":"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. public function sendBasicMail() { $this->mailService->setBody('Email body'); $this->mailService->setSubject('Email subject'); $this->mailService->getMessage()->addTo('email@example.com', 'User name'); $this->mailService->getMessage()->setEncoding('utf-8'); return $this->mailService->send()->isValid(); } 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 . try { $this->userService->sendBasicMail(); $this->messenger->addSuccess('The mail was sent successfully', 'user-login'); //more code... } catch (Exception $exception) { $this->messenger->addError($exception->getMessage(), 'user-login'); //more code... }","title":"Sending an e-mail"},{"location":"v4/usage/#testing-if-an-e-mail-message-is-valid","text":"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. $result = $this->mailService->send(); if (! $result->isValid()) { //log the error error_log($result->getMessage()); } Invalid e-mail messages will not be sent.","title":"Testing if an e-mail message is valid"},{"location":"v4/usage/#logging-outgoing-emails","text":"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: [YYYY-MM-DD HH:MM:SS]: {\"subject\":\"Test subject\",\"to\":[\"Test Account <test@dotkernel.com>\"],\"cc\":[],\"bcc\":[]} . Each email is saved via the dotkernel/dot-log component in the shown JSON format, in the single file configured under the dot-mail.log.sent key. To disable it, set the value of dot-mail.log.sent to null .","title":"Logging outgoing emails"},{"location":"v4/usage/#transport-usage","text":"Transports","title":"Transport usage"},{"location":"v5/configuration/","text":"Configuration Register dot-mail in you project by adding Dot\\Mail\\ConfigProvider::class to your configuration aggregator (to config/config.php for example). After registering the ConfigProvider copy the configuration file config/mail.global.php.dist into your project's config/autoload/ directory as mail.global.php . The resulting mail.global.php contains the necessary configurations for all available transport types, message options and logging options in one place. The config file provides a set of default values available to all mails under the dot-mail.default key. Many of these options can be programmatically set when sending the actual email. An example of this is the dot-mail.default.message_options key, which can be filled in with default message values to be available to all emails. When sending the actual email, these values can be overwritten by using an available \"setter\" function, supplemented by using \"add\" functions or simply left as the default. // setter will overwrite existing destination email $this->mailService->getMessage()->setTo(\"receiver@email.com\"); // existing destination email kept, new destination email added alongside it $this->mailService->getMessage()->addTo(\"receiver@email.com\"); Transport configuration dot-mail uses the transport key under the main dot_mail configuration key to select the email transport. It has two email transport classes available (by default sendmail ), one of which is to be added under the dot_mail.transport key for use. Sending email with the esmtp transport requires valid data for the values under dot-mail.default.smtp_options , which is only used in this case. The configured path must be a writable directory Logging configuration Uncommenting the dot-mail.log key will save a copy of all sent emails' subject, recipient addresses, cc and bcc addresses alongside a timestamp. In order to enable it, make sure that your mail.local.php has the below log configuration under the dot_mail key: <?php return [ 'dot_mail' => [ ... 'log' => [ 'sent' => getcwd() . '/log/mail/sent.log' ] ] ]; To disable it, set the value of sent to null .","title":"Configuration"},{"location":"v5/configuration/#configuration","text":"Register dot-mail in you project by adding Dot\\Mail\\ConfigProvider::class to your configuration aggregator (to config/config.php for example). After registering the ConfigProvider copy the configuration file config/mail.global.php.dist into your project's config/autoload/ directory as mail.global.php . The resulting mail.global.php contains the necessary configurations for all available transport types, message options and logging options in one place. The config file provides a set of default values available to all mails under the dot-mail.default key. Many of these options can be programmatically set when sending the actual email. An example of this is the dot-mail.default.message_options key, which can be filled in with default message values to be available to all emails. When sending the actual email, these values can be overwritten by using an available \"setter\" function, supplemented by using \"add\" functions or simply left as the default. // setter will overwrite existing destination email $this->mailService->getMessage()->setTo(\"receiver@email.com\"); // existing destination email kept, new destination email added alongside it $this->mailService->getMessage()->addTo(\"receiver@email.com\");","title":"Configuration"},{"location":"v5/configuration/#transport-configuration","text":"dot-mail uses the transport key under the main dot_mail configuration key to select the email transport. It has two email transport classes available (by default sendmail ), one of which is to be added under the dot_mail.transport key for use. Sending email with the esmtp transport requires valid data for the values under dot-mail.default.smtp_options , which is only used in this case. The configured path must be a writable directory","title":"Transport configuration"},{"location":"v5/configuration/#logging-configuration","text":"Uncommenting the dot-mail.log key will save a copy of all sent emails' subject, recipient addresses, cc and bcc addresses alongside a timestamp. In order to enable it, make sure that your mail.local.php has the below log configuration under the dot_mail key: <?php return [ 'dot_mail' => [ ... 'log' => [ 'sent' => getcwd() . '/log/mail/sent.log' ] ] ]; To disable it, set the value of sent to null .","title":"Logging configuration"},{"location":"v5/installation/","text":"Installation Install dotkernel/dot-mail by executing the following Composer command: composer require dotkernel/dot-mail","title":"Installation"},{"location":"v5/installation/#installation","text":"Install dotkernel/dot-mail by executing the following Composer command: composer require dotkernel/dot-mail","title":"Installation"},{"location":"v5/overview/","text":"Overview dot-mail is a wrapper on top of symfony mailer Extra features the option to log the results of the mailing process it provides the developer with more information and greater control.","title":"Overview"},{"location":"v5/overview/#overview","text":"dot-mail is a wrapper on top of symfony mailer","title":"Overview"},{"location":"v5/overview/#extra-features","text":"the option to log the results of the mailing process it provides the developer with more information and greater control.","title":"Extra features"},{"location":"v5/transports/","text":"Transports dot-mail can use any transport class that implements Symfony\\Component\\Mailer\\Transport\\TransportInterface , with the standard transport available being: esmtp sendmail Feel free to use any custom transport you desire, provided it implements the mentioned TransportInterface . PHP's mail() function is a wrapper over sendmail , and as such has a different behaviour on Windows than on nix systems. Using sendmail on Windows will not work in combination with * addBcc() . Note: emails sent using the sendmail transport will be more often delivered to SPAM. esmtp connects to the configured SMTP host in order to handle sending emails.","title":"Transports"},{"location":"v5/transports/#transports","text":"dot-mail can use any transport class that implements Symfony\\Component\\Mailer\\Transport\\TransportInterface , with the standard transport available being: esmtp sendmail Feel free to use any custom transport you desire, provided it implements the mentioned TransportInterface . PHP's mail() function is a wrapper over sendmail , and as such has a different behaviour on Windows than on nix systems. Using sendmail on Windows will not work in combination with * addBcc() . Note: emails sent using the sendmail transport will be more often delivered to SPAM. esmtp connects to the configured SMTP host in order to handle sending emails.","title":"Transports"},{"location":"v5/usage/","text":"Usage 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. public function sendBasicMail() { $this->mailService->setBody('Email body'); $this->mailService->setSubject('Email subject'); $this->mailService->getMessage()->addTo('email@example.com', 'User name'); $this->mailService->getMessage()->setEncoding('utf-8'); return $this->mailService->send()->isValid(); } 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 . try { $this->userService->sendBasicMail(); $this->messenger->addSuccess('The mail was sent successfully', 'user-login'); //more code... } catch (Exception $exception) { $this->messenger->addError($exception->getMessage(), 'user-login'); //more code... } 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. $result = $this->mailService->send(); if (! $result->isValid()) { //log the error error_log($result->getMessage()); } 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: [YYYY-MM-DD HH:MM:SS]: {\"subject\":\"Test subject\",\"to\":[\"Test Account <test@dotkernel.com>\"],\"cc\":[],\"bcc\":[]}. Each email is saved via the dotkernel/dot-log component in the shown JSON format, in the single file configured under the dot-mail.log.sent key. To disable it, set the value of dot-mail.log.sent to null . Transport usage Transports","title":"Usage"},{"location":"v5/usage/#usage","text":"","title":"Usage"},{"location":"v5/usage/#sending-an-e-mail","text":"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. public function sendBasicMail() { $this->mailService->setBody('Email body'); $this->mailService->setSubject('Email subject'); $this->mailService->getMessage()->addTo('email@example.com', 'User name'); $this->mailService->getMessage()->setEncoding('utf-8'); return $this->mailService->send()->isValid(); } 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 . try { $this->userService->sendBasicMail(); $this->messenger->addSuccess('The mail was sent successfully', 'user-login'); //more code... } catch (Exception $exception) { $this->messenger->addError($exception->getMessage(), 'user-login'); //more code... }","title":"Sending an e-mail"},{"location":"v5/usage/#testing-if-an-e-mail-message-is-valid","text":"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. $result = $this->mailService->send(); if (! $result->isValid()) { //log the error error_log($result->getMessage()); } Invalid e-mail messages will not be sent.","title":"Testing if an e-mail message is valid"},{"location":"v5/usage/#logging-outgoing-emails","text":"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: [YYYY-MM-DD HH:MM:SS]: {\"subject\":\"Test subject\",\"to\":[\"Test Account <test@dotkernel.com>\"],\"cc\":[],\"bcc\":[]}. Each email is saved via the dotkernel/dot-log component in the shown JSON format, in the single file configured under the dot-mail.log.sent key. To disable it, set the value of dot-mail.log.sent to null .","title":"Logging outgoing emails"},{"location":"v5/usage/#transport-usage","text":"Transports","title":"Transport usage"}]} \ No newline at end of file +{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"dot-mail [!IMPORTANT] dot-mail is a wrapper on top of symfony mailer dot-mail badges Installation Install dotkernel/dot-mail by executing the following Composer command: composer require dotkernel/dot-mail 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 <?php return [ 'dot_mail' => [ 'default' => [ //... 'transport' => 'sendmail', //... ] ] ] 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 address port - the mail server's port connection_config - fill in the username and password keys with the login details of the email used in from above if you want to disable auto_tls set tls key to false Note: all other keys can be left as is. <?php return [ 'dot_mail' => [ 'default' => [ //... 'transport' => 'esmtp' 'message_options' => [ 'from' => '', //... ], 'smtp_options' => [ 'host' => '', 'port' => 25, 'connection_config' => [ 'username' => '', 'password' => '', 'tls' => null, ] ] //... ] ] ] In config/autoload/local.php add under contact => message_receivers => to key string values with the emails that should receive contact messages Note: Please add at least 1 email address in order for 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. public function sendBasicMail() { $this->mailService->setBody('Email body'); $this->mailService->setSubject('Email subject'); $this->mailService->getMessage()->addTo('email@example.com', 'User name'); $this->mailService->getMessage()->setEncoding('utf-8'); return $this->mailService->send()->isValid(); } 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 . try { $this->userService->sendBasicMail(); $this->messenger->addSuccess('The mail was sent successfully', 'user-login'); //more code... } catch (Exception $exception) { $this->messenger->addError($exception->getMessage(), 'user-login'); //more code... } 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. $result = $this->mailService->send(); if (! $result->isValid()) { //log the error error_log($result->getMessage()); } 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: [YYYY-MM-DD HH:MM:SS]: {\"subject\":\"Test subject\",\"to\":[\"Test Account <test@dotkernel.com>\"],\"cc\":[],\"bcc\":[]}. In order to enable it, make sure that your config/autoload/mail.local.php has the below log configuration under the dot_mail key: <?php return [ 'dot_mail' => [ ... 'log' => [ 'sent' => getcwd() . '/log/mail/sent.log' ] ] ]; To disable it, set the value of sent to null .","title":"Home"},{"location":"#dot-mail","text":"[!IMPORTANT] dot-mail is a wrapper on top of symfony mailer","title":"dot-mail"},{"location":"#dot-mail-badges","text":"","title":"dot-mail badges"},{"location":"#installation","text":"Install dotkernel/dot-mail by executing the following Composer command: composer require dotkernel/dot-mail","title":"Installation"},{"location":"#configuration","text":"","title":"Configuration"},{"location":"v4/configuration/","text":"Configuration Register dot-mail in you project by adding Dot\\Mail\\ConfigProvider::class to your configuration aggregator (to config/config.php for example). After registering the ConfigProvider copy the configuration file config/mail.global.php.dist into your project's config/autoload/ directory as mail.global.php . The resulting mail.global.php contains the necessary configurations for all available transport types, message options and logging options in one place. The config file provides a set of default values available to all mails under the dot-mail.default key. Many of these options can be programmatically set when sending the actual email. An example of this is the dot-mail.default.message_options key, which can be filled in with default message values to be available to all emails. When sending the actual email, these values can be overwritten by using an available \"setter\" function, supplemented by using \"add\" functions or simply left as the default. // setter will overwrite existing destination email $this->mailService->getMessage()->setTo(\"receiver@email.com\"); // existing destination email kept, new destination email added alongside it $this->mailService->getMessage()->addTo(\"receiver@email.com\"); Transport configuration dot-mail uses the transport key under the main dot_mail configuration key to select the email transport. It has four email transport classes available by default ( Sendmail , Smtp , File , InMemory ), one of which is to be added under the dot_mail.transport key for use. Both Sendmail and InMemory transports requires no specific configuration to use by default. Sending email with the Smtp transport requires valid data for the values under dot-mail.default.smtp_options , which is only used in this case. The dot_mail.default.save_sent_message_folder key may be uncommented when using this transport, saving a copy of all sent email to a certain IMAP folder. Using Laminas\\Mail\\Transport\\File as the transport will require uncommenting the dot-mail.default.file_options key. The configured path must be a writable directory 'file_options' => [ 'path' => 'data/mail/output', //'callback' => null, ], If no callback is provided to specify a new file name format, the messages will be saved in files using the default format set in Laminas\\Mail\\Transport\\FileOptions . // Example of a custom format 'callback' => static fn() => sprintf('DotMail%d_%s.log', time(), 'customFormat'), Logging configuration Uncommenting the dot-mail.log key will save a copy of all sent emails' subject, recipient addresses, cc and bcc addresses alongside a timestamp. In order to enable it, make sure that your mail.local.php has the below log configuration under the dot_mail key: <?php return [ 'dot_mail' => [ ... 'log' => [ 'sent' => getcwd() . '/log/mail/sent.log' ] ] ]; To disable it, set the value of sent to null .","title":"Configuration"},{"location":"v4/configuration/#configuration","text":"Register dot-mail in you project by adding Dot\\Mail\\ConfigProvider::class to your configuration aggregator (to config/config.php for example). After registering the ConfigProvider copy the configuration file config/mail.global.php.dist into your project's config/autoload/ directory as mail.global.php . The resulting mail.global.php contains the necessary configurations for all available transport types, message options and logging options in one place. The config file provides a set of default values available to all mails under the dot-mail.default key. Many of these options can be programmatically set when sending the actual email. An example of this is the dot-mail.default.message_options key, which can be filled in with default message values to be available to all emails. When sending the actual email, these values can be overwritten by using an available \"setter\" function, supplemented by using \"add\" functions or simply left as the default. // setter will overwrite existing destination email $this->mailService->getMessage()->setTo(\"receiver@email.com\"); // existing destination email kept, new destination email added alongside it $this->mailService->getMessage()->addTo(\"receiver@email.com\");","title":"Configuration"},{"location":"v4/configuration/#transport-configuration","text":"dot-mail uses the transport key under the main dot_mail configuration key to select the email transport. It has four email transport classes available by default ( Sendmail , Smtp , File , InMemory ), one of which is to be added under the dot_mail.transport key for use. Both Sendmail and InMemory transports requires no specific configuration to use by default. Sending email with the Smtp transport requires valid data for the values under dot-mail.default.smtp_options , which is only used in this case. The dot_mail.default.save_sent_message_folder key may be uncommented when using this transport, saving a copy of all sent email to a certain IMAP folder. Using Laminas\\Mail\\Transport\\File as the transport will require uncommenting the dot-mail.default.file_options key. The configured path must be a writable directory 'file_options' => [ 'path' => 'data/mail/output', //'callback' => null, ], If no callback is provided to specify a new file name format, the messages will be saved in files using the default format set in Laminas\\Mail\\Transport\\FileOptions . // Example of a custom format 'callback' => static fn() => sprintf('DotMail%d_%s.log', time(), 'customFormat'),","title":"Transport configuration"},{"location":"v4/configuration/#logging-configuration","text":"Uncommenting the dot-mail.log key will save a copy of all sent emails' subject, recipient addresses, cc and bcc addresses alongside a timestamp. In order to enable it, make sure that your mail.local.php has the below log configuration under the dot_mail key: <?php return [ 'dot_mail' => [ ... 'log' => [ 'sent' => getcwd() . '/log/mail/sent.log' ] ] ]; To disable it, set the value of sent to null .","title":"Logging configuration"},{"location":"v4/installation/","text":"Installation Install dotkernel/dot-mail by executing the following Composer command: composer require dotkernel/dot-mail","title":"Installation"},{"location":"v4/installation/#installation","text":"Install dotkernel/dot-mail by executing the following Composer command: composer require dotkernel/dot-mail","title":"Installation"},{"location":"v4/overview/","text":"Overview dot-mail is a wrapper on top of laminas-mail Extra features the option to log the results of the mailing process it provides the developer with more information and greater control.","title":"Overview"},{"location":"v4/overview/#overview","text":"dot-mail is a wrapper on top of laminas-mail","title":"Overview"},{"location":"v4/overview/#extra-features","text":"the option to log the results of the mailing process it provides the developer with more information and greater control.","title":"Extra features"},{"location":"v4/transports/","text":"Transports dot-mail can use any transport class that implements Laminas\\Mail\\Transport\\TransportInterface , with the four standard transports available being: Laminas\\Mail\\Transport\\Sendmail - the default transport set in the config file Laminas\\Mail\\Transport\\Smtp Laminas\\Mail\\Transport\\File Laminas\\Mail\\Transport\\InMemory Feel free to use any custom transport you desire, provided it implements the mentioned TransportInterface . Sendmail is a wrapper over PHP's mail() function, and as such has a different behaviour on Windows than on nix systems. Using sendmail on Windows will not work in combination with * addBcc() . Note: emails sent using the sendmail transport will be more often delivered to SPAM. Smtp connects to the configured SMTP host in order to handle sending emails. Saving a copy of an outgoing mail into a folder is possible for this transport only, and is done by uncommenting save_sent_message_folder in the config file mail.local.php under dot_mail.default . Common folder names are INBOX , INBOX.Archive , INBOX.Drafts , INBOX.Sent , INBOX.Spam , INBOX.Trash . If you have MailService available in your class, you can call $this->mailService->getFolderGlobalNames() to list the folder global names for the email you are using. Multiple folders can be added to the save_sent_message_folder key to save a copy of the outgoing email in each folder. File writes each message individually in a file named after the configured format, placed in the configured directory. From here the files may be used for sending via another transport mechanism, or simply as logs. InMemory saves the message in memory, allowing access to the last \"sent\" message via the getLastMessage() function. As the email is not sent, this transport can be helpful in development, with the access to the message being potentially useful in tests as well $this->mailService->setBody('First email body'); $this->mailService->setSubject('First email subject'); $this->mailService->getMessage()->setTo('email@example.com'); // The email is not sent to the email, instead it is stored in memory $this->mailService->send(); $this->mailService->setBody('Second email body'); $this->mailService->setSubject('Second email subject'); $this->mailService->getMessage()->setTo('email@example.com'); // The email is not sent to the email either, it overwrites the previously \"sent\" email in memory $this->mailService->send(); // Returns the second email's Laminas\\Mail\\Message object from memory $lastMessage = $this->mailService()->getTransport()->getLastMessage();","title":"Transports"},{"location":"v4/transports/#transports","text":"dot-mail can use any transport class that implements Laminas\\Mail\\Transport\\TransportInterface , with the four standard transports available being: Laminas\\Mail\\Transport\\Sendmail - the default transport set in the config file Laminas\\Mail\\Transport\\Smtp Laminas\\Mail\\Transport\\File Laminas\\Mail\\Transport\\InMemory Feel free to use any custom transport you desire, provided it implements the mentioned TransportInterface . Sendmail is a wrapper over PHP's mail() function, and as such has a different behaviour on Windows than on nix systems. Using sendmail on Windows will not work in combination with * addBcc() . Note: emails sent using the sendmail transport will be more often delivered to SPAM. Smtp connects to the configured SMTP host in order to handle sending emails. Saving a copy of an outgoing mail into a folder is possible for this transport only, and is done by uncommenting save_sent_message_folder in the config file mail.local.php under dot_mail.default . Common folder names are INBOX , INBOX.Archive , INBOX.Drafts , INBOX.Sent , INBOX.Spam , INBOX.Trash . If you have MailService available in your class, you can call $this->mailService->getFolderGlobalNames() to list the folder global names for the email you are using. Multiple folders can be added to the save_sent_message_folder key to save a copy of the outgoing email in each folder. File writes each message individually in a file named after the configured format, placed in the configured directory. From here the files may be used for sending via another transport mechanism, or simply as logs. InMemory saves the message in memory, allowing access to the last \"sent\" message via the getLastMessage() function. As the email is not sent, this transport can be helpful in development, with the access to the message being potentially useful in tests as well $this->mailService->setBody('First email body'); $this->mailService->setSubject('First email subject'); $this->mailService->getMessage()->setTo('email@example.com'); // The email is not sent to the email, instead it is stored in memory $this->mailService->send(); $this->mailService->setBody('Second email body'); $this->mailService->setSubject('Second email subject'); $this->mailService->getMessage()->setTo('email@example.com'); // The email is not sent to the email either, it overwrites the previously \"sent\" email in memory $this->mailService->send(); // Returns the second email's Laminas\\Mail\\Message object from memory $lastMessage = $this->mailService()->getTransport()->getLastMessage();","title":"Transports"},{"location":"v4/usage/","text":"Usage 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. public function sendBasicMail() { $this->mailService->setBody('Email body'); $this->mailService->setSubject('Email subject'); $this->mailService->getMessage()->addTo('email@example.com', 'User name'); $this->mailService->getMessage()->setEncoding('utf-8'); return $this->mailService->send()->isValid(); } 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 . try { $this->userService->sendBasicMail(); $this->messenger->addSuccess('The mail was sent successfully', 'user-login'); //more code... } catch (Exception $exception) { $this->messenger->addError($exception->getMessage(), 'user-login'); //more code... } 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. $result = $this->mailService->send(); if (! $result->isValid()) { //log the error error_log($result->getMessage()); } 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: [YYYY-MM-DD HH:MM:SS]: {\"subject\":\"Test subject\",\"to\":[\"Test Account <test@dotkernel.com>\"],\"cc\":[],\"bcc\":[]} . Each email is saved via the dotkernel/dot-log component in the shown JSON format, in the single file configured under the dot-mail.log.sent key. To disable it, set the value of dot-mail.log.sent to null . Transport usage Transports","title":"Usage"},{"location":"v4/usage/#usage","text":"","title":"Usage"},{"location":"v4/usage/#sending-an-e-mail","text":"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. public function sendBasicMail() { $this->mailService->setBody('Email body'); $this->mailService->setSubject('Email subject'); $this->mailService->getMessage()->addTo('email@example.com', 'User name'); $this->mailService->getMessage()->setEncoding('utf-8'); return $this->mailService->send()->isValid(); } 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 . try { $this->userService->sendBasicMail(); $this->messenger->addSuccess('The mail was sent successfully', 'user-login'); //more code... } catch (Exception $exception) { $this->messenger->addError($exception->getMessage(), 'user-login'); //more code... }","title":"Sending an e-mail"},{"location":"v4/usage/#testing-if-an-e-mail-message-is-valid","text":"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. $result = $this->mailService->send(); if (! $result->isValid()) { //log the error error_log($result->getMessage()); } Invalid e-mail messages will not be sent.","title":"Testing if an e-mail message is valid"},{"location":"v4/usage/#logging-outgoing-emails","text":"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: [YYYY-MM-DD HH:MM:SS]: {\"subject\":\"Test subject\",\"to\":[\"Test Account <test@dotkernel.com>\"],\"cc\":[],\"bcc\":[]} . Each email is saved via the dotkernel/dot-log component in the shown JSON format, in the single file configured under the dot-mail.log.sent key. To disable it, set the value of dot-mail.log.sent to null .","title":"Logging outgoing emails"},{"location":"v4/usage/#transport-usage","text":"Transports","title":"Transport usage"},{"location":"v5/configuration/","text":"Configuration Register dot-mail in you project by adding Dot\\Mail\\ConfigProvider::class to your configuration aggregator (to config/config.php for example). After registering the ConfigProvider copy the configuration file config/mail.global.php.dist into your project's config/autoload/ directory as mail.global.php . The resulting mail.global.php contains the necessary configurations for all available transport types, message options and logging options in one place. The config file provides a set of default values available to all mails under the dot-mail.default key. Many of these options can be programmatically set when sending the actual email. An example of this is the dot-mail.default.message_options key, which can be filled in with default message values to be available to all emails. When sending the actual email, these values can be overwritten by using an available \"setter\" function, supplemented by using \"add\" functions or simply left as the default. // setter will overwrite existing destination email $this->mailService->getMessage()->setTo(\"receiver@email.com\"); // existing destination email kept, new destination email added alongside it $this->mailService->getMessage()->addTo(\"receiver@email.com\"); Transport configuration dot-mail uses the transport key under the main dot_mail configuration key to select the email transport. It has two email transport classes available (by default sendmail ), one of which is to be added under the dot_mail.transport key for use. Sending email with the esmtp transport requires valid data for the values under dot-mail.default.smtp_options , which is only used in this case. The configured path must be a writable directory Logging configuration Uncommenting the dot-mail.log key will save a copy of all sent emails' subject, recipient addresses, cc and bcc addresses alongside a timestamp. In order to enable it, make sure that your mail.local.php has the below log configuration under the dot_mail key: <?php return [ 'dot_mail' => [ ... 'log' => [ 'sent' => getcwd() . '/log/mail/sent.log' ] ] ]; To disable it, set the value of sent to null .","title":"Configuration"},{"location":"v5/configuration/#configuration","text":"Register dot-mail in you project by adding Dot\\Mail\\ConfigProvider::class to your configuration aggregator (to config/config.php for example). After registering the ConfigProvider copy the configuration file config/mail.global.php.dist into your project's config/autoload/ directory as mail.global.php . The resulting mail.global.php contains the necessary configurations for all available transport types, message options and logging options in one place. The config file provides a set of default values available to all mails under the dot-mail.default key. Many of these options can be programmatically set when sending the actual email. An example of this is the dot-mail.default.message_options key, which can be filled in with default message values to be available to all emails. When sending the actual email, these values can be overwritten by using an available \"setter\" function, supplemented by using \"add\" functions or simply left as the default. // setter will overwrite existing destination email $this->mailService->getMessage()->setTo(\"receiver@email.com\"); // existing destination email kept, new destination email added alongside it $this->mailService->getMessage()->addTo(\"receiver@email.com\");","title":"Configuration"},{"location":"v5/configuration/#transport-configuration","text":"dot-mail uses the transport key under the main dot_mail configuration key to select the email transport. It has two email transport classes available (by default sendmail ), one of which is to be added under the dot_mail.transport key for use. Sending email with the esmtp transport requires valid data for the values under dot-mail.default.smtp_options , which is only used in this case. The configured path must be a writable directory","title":"Transport configuration"},{"location":"v5/configuration/#logging-configuration","text":"Uncommenting the dot-mail.log key will save a copy of all sent emails' subject, recipient addresses, cc and bcc addresses alongside a timestamp. In order to enable it, make sure that your mail.local.php has the below log configuration under the dot_mail key: <?php return [ 'dot_mail' => [ ... 'log' => [ 'sent' => getcwd() . '/log/mail/sent.log' ] ] ]; To disable it, set the value of sent to null .","title":"Logging configuration"},{"location":"v5/installation/","text":"Installation Install dotkernel/dot-mail by executing the following Composer command: composer require dotkernel/dot-mail","title":"Installation"},{"location":"v5/installation/#installation","text":"Install dotkernel/dot-mail by executing the following Composer command: composer require dotkernel/dot-mail","title":"Installation"},{"location":"v5/overview/","text":"Overview dot-mail is a wrapper on top of symfony mailer Extra features the option to log the results of the mailing process it provides the developer with more information and greater control.","title":"Overview"},{"location":"v5/overview/#overview","text":"dot-mail is a wrapper on top of symfony mailer","title":"Overview"},{"location":"v5/overview/#extra-features","text":"the option to log the results of the mailing process it provides the developer with more information and greater control.","title":"Extra features"},{"location":"v5/transports/","text":"Transports dot-mail can use any transport class that implements Symfony\\Component\\Mailer\\Transport\\TransportInterface , with the standard transport available being: esmtp sendmail Feel free to use any custom transport you desire, provided it implements the mentioned TransportInterface . PHP's mail() function is a wrapper over sendmail , and as such has a different behaviour on Windows than on nix systems. Using sendmail on Windows will not work in combination with * addBcc() . Note: emails sent using the sendmail transport will be more often delivered to SPAM. esmtp connects to the configured SMTP host in order to handle sending emails.","title":"Transports"},{"location":"v5/transports/#transports","text":"dot-mail can use any transport class that implements Symfony\\Component\\Mailer\\Transport\\TransportInterface , with the standard transport available being: esmtp sendmail Feel free to use any custom transport you desire, provided it implements the mentioned TransportInterface . PHP's mail() function is a wrapper over sendmail , and as such has a different behaviour on Windows than on nix systems. Using sendmail on Windows will not work in combination with * addBcc() . Note: emails sent using the sendmail transport will be more often delivered to SPAM. esmtp connects to the configured SMTP host in order to handle sending emails.","title":"Transports"},{"location":"v5/upgrade-v4-to-v5/","text":"How to update dotkernel/dot-mail from v3/v4 to v5 in your projects The first thing to do is download the new mail configuration file . Add the values you configured for your project, focusing on transport , message_options and smtp_options , then replace your old configuration file. In your composer.json update \"dotkernel/dot-mail\": \"^5.0.0\", and run composer update in the command line. At this moment, mime and imap related functionality is removed. Technical approach You can follow all the changes in this list of PRs: dot-mail PR 65 dot-mail PR 66 dot-mail PR 67 dot-mail PR 69 Function definition changes will not be covered in this article. When upgrading dotkernel/dot-mail from v4 to v5, the main focus is on the configuration file mail.global.php . It was revised to implement symfony/mailer, to remove features that are no longer available and to make dotkernel/dot-mail easier to configure. ?php declare(strict_types=1); return [ /** * Dotkernel mail module configuration * Note that many of these options can be set programmatically too, when sending mail messages actually that is * what you'll usually do, these configs provide just defaults and options that remain the same for all mails */ 'dot_mail' => [ //the key is the mail service name, this is the default one, which does not extend any configuration 'default' => [ //message configuration 'message_options' => [ //from email address of the email 'from' => '', //from name to be displayed instead of from address 'from_name' => '', //reply-to email address of the email 'reply_to' => '', //replyTo name to be displayed instead of the address 'reply_to_name' => '', //destination email address as string or a list of email addresses 'to' => [], //copy destination addresses 'cc' => [], //hidden copy destination addresses 'bcc' => [], //email subject 'subject' => '', //body options - content can be plain text, HTML 'body' => [ 'content' => '', 'charset' => 'utf-8', ], //attachments config 'attachments' => [ 'files' => [], 'dir' => [ 'iterate' => false, 'path' => 'data/mail/attachments', 'recursive' => false, ], ], ], /** * the mail transport to use can be any class implementing * Symfony\\Component\\Mailer\\Transport\\TransportInterface * * for standard mail transports, you can use these aliases: * - sendmail => Symfony\\Component\\Mailer\\Transport\\SendmailTransport * - esmtp => Symfony\\Component\\Mailer\\Transport\\Smtp\\EsmtpTransport * * defaults to sendmail **/ 'transport' => 'sendmail', //options that will be used only if esmtp adapter is used 'smtp_options' => [ //hostname or IP address of the mail server 'host' => '', //port of the mail server - 587 or 465 for secure connections 'port' => 587, 'connection_config' => [ //the smtp authentication identity 'username' => '', //the smtp authentication credential 'password' => '', //to disable auto_tls set tls key to false //it's not recommended to disable TLS while connecting to an SMTP server 'tls' => null, ], ], ], // option to log the SENT emails 'log' => [ 'sent' => getcwd() . '/log/mail/sent.log', ], ], ]; Make sure to use ONE of the below transporters, based on your server configuration. 'transport' => 'sendmail', OR 'transport' => 'esmtp', We set Sendmail to be the default.","title":"Upgrade from V4 to v5"},{"location":"v5/upgrade-v4-to-v5/#how-to-update-dotkerneldot-mail-from-v3v4-to-v5-in-your-projects","text":"The first thing to do is download the new mail configuration file . Add the values you configured for your project, focusing on transport , message_options and smtp_options , then replace your old configuration file. In your composer.json update \"dotkernel/dot-mail\": \"^5.0.0\", and run composer update in the command line. At this moment, mime and imap related functionality is removed.","title":"How to update dotkernel/dot-mail from v3/v4 to v5 in your projects"},{"location":"v5/upgrade-v4-to-v5/#technical-approach","text":"You can follow all the changes in this list of PRs: dot-mail PR 65 dot-mail PR 66 dot-mail PR 67 dot-mail PR 69 Function definition changes will not be covered in this article. When upgrading dotkernel/dot-mail from v4 to v5, the main focus is on the configuration file mail.global.php . It was revised to implement symfony/mailer, to remove features that are no longer available and to make dotkernel/dot-mail easier to configure. ?php declare(strict_types=1); return [ /** * Dotkernel mail module configuration * Note that many of these options can be set programmatically too, when sending mail messages actually that is * what you'll usually do, these configs provide just defaults and options that remain the same for all mails */ 'dot_mail' => [ //the key is the mail service name, this is the default one, which does not extend any configuration 'default' => [ //message configuration 'message_options' => [ //from email address of the email 'from' => '', //from name to be displayed instead of from address 'from_name' => '', //reply-to email address of the email 'reply_to' => '', //replyTo name to be displayed instead of the address 'reply_to_name' => '', //destination email address as string or a list of email addresses 'to' => [], //copy destination addresses 'cc' => [], //hidden copy destination addresses 'bcc' => [], //email subject 'subject' => '', //body options - content can be plain text, HTML 'body' => [ 'content' => '', 'charset' => 'utf-8', ], //attachments config 'attachments' => [ 'files' => [], 'dir' => [ 'iterate' => false, 'path' => 'data/mail/attachments', 'recursive' => false, ], ], ], /** * the mail transport to use can be any class implementing * Symfony\\Component\\Mailer\\Transport\\TransportInterface * * for standard mail transports, you can use these aliases: * - sendmail => Symfony\\Component\\Mailer\\Transport\\SendmailTransport * - esmtp => Symfony\\Component\\Mailer\\Transport\\Smtp\\EsmtpTransport * * defaults to sendmail **/ 'transport' => 'sendmail', //options that will be used only if esmtp adapter is used 'smtp_options' => [ //hostname or IP address of the mail server 'host' => '', //port of the mail server - 587 or 465 for secure connections 'port' => 587, 'connection_config' => [ //the smtp authentication identity 'username' => '', //the smtp authentication credential 'password' => '', //to disable auto_tls set tls key to false //it's not recommended to disable TLS while connecting to an SMTP server 'tls' => null, ], ], ], // option to log the SENT emails 'log' => [ 'sent' => getcwd() . '/log/mail/sent.log', ], ], ]; Make sure to use ONE of the below transporters, based on your server configuration. 'transport' => 'sendmail', OR 'transport' => 'esmtp', We set Sendmail to be the default.","title":"Technical approach"},{"location":"v5/usage/","text":"Usage 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. public function sendBasicMail() { $this->mailService->setBody('Email body'); $this->mailService->setSubject('Email subject'); $this->mailService->getMessage()->addTo('email@example.com', 'User name'); $this->mailService->getMessage()->setEncoding('utf-8'); return $this->mailService->send()->isValid(); } 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 . try { $this->userService->sendBasicMail(); $this->messenger->addSuccess('The mail was sent successfully', 'user-login'); //more code... } catch (Exception $exception) { $this->messenger->addError($exception->getMessage(), 'user-login'); //more code... } 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. $result = $this->mailService->send(); if (! $result->isValid()) { //log the error error_log($result->getMessage()); } 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: [YYYY-MM-DD HH:MM:SS]: {\"subject\":\"Test subject\",\"to\":[\"Test Account <test@dotkernel.com>\"],\"cc\":[],\"bcc\":[]}. Each email is saved via the dotkernel/dot-log component in the shown JSON format, in the single file configured under the dot-mail.log.sent key. To disable it, set the value of dot-mail.log.sent to null . Transport usage Transports","title":"Usage"},{"location":"v5/usage/#usage","text":"","title":"Usage"},{"location":"v5/usage/#sending-an-e-mail","text":"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. public function sendBasicMail() { $this->mailService->setBody('Email body'); $this->mailService->setSubject('Email subject'); $this->mailService->getMessage()->addTo('email@example.com', 'User name'); $this->mailService->getMessage()->setEncoding('utf-8'); return $this->mailService->send()->isValid(); } 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 . try { $this->userService->sendBasicMail(); $this->messenger->addSuccess('The mail was sent successfully', 'user-login'); //more code... } catch (Exception $exception) { $this->messenger->addError($exception->getMessage(), 'user-login'); //more code... }","title":"Sending an e-mail"},{"location":"v5/usage/#testing-if-an-e-mail-message-is-valid","text":"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. $result = $this->mailService->send(); if (! $result->isValid()) { //log the error error_log($result->getMessage()); } Invalid e-mail messages will not be sent.","title":"Testing if an e-mail message is valid"},{"location":"v5/usage/#logging-outgoing-emails","text":"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: [YYYY-MM-DD HH:MM:SS]: {\"subject\":\"Test subject\",\"to\":[\"Test Account <test@dotkernel.com>\"],\"cc\":[],\"bcc\":[]}. Each email is saved via the dotkernel/dot-log component in the shown JSON format, in the single file configured under the dot-mail.log.sent key. To disable it, set the value of dot-mail.log.sent to null .","title":"Logging outgoing emails"},{"location":"v5/usage/#transport-usage","text":"Transports","title":"Transport usage"}]} \ No newline at end of file diff --git a/sitemap.xml b/sitemap.xml index 43fdbc1..52104cf 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -2,46 +2,50 @@ https://docs.dotkernel.org/dot-mail/ - 2024-12-19 + 2025-01-06 https://docs.dotkernel.org/dot-mail/v4/configuration/ - 2024-12-19 + 2025-01-06 https://docs.dotkernel.org/dot-mail/v4/installation/ - 2024-12-19 + 2025-01-06 https://docs.dotkernel.org/dot-mail/v4/overview/ - 2024-12-19 + 2025-01-06 https://docs.dotkernel.org/dot-mail/v4/transports/ - 2024-12-19 + 2025-01-06 https://docs.dotkernel.org/dot-mail/v4/usage/ - 2024-12-19 + 2025-01-06 https://docs.dotkernel.org/dot-mail/v5/configuration/ - 2024-12-19 + 2025-01-06 https://docs.dotkernel.org/dot-mail/v5/installation/ - 2024-12-19 + 2025-01-06 https://docs.dotkernel.org/dot-mail/v5/overview/ - 2024-12-19 + 2025-01-06 https://docs.dotkernel.org/dot-mail/v5/transports/ - 2024-12-19 + 2025-01-06 + + + https://docs.dotkernel.org/dot-mail/v5/upgrade-v4-to-v5/ + 2025-01-06 https://docs.dotkernel.org/dot-mail/v5/usage/ - 2024-12-19 + 2025-01-06 \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 6c952cbaa909075343ef0f8798871a58e5e733ae..462d62faf4fe63817e2350087263430f2a072c63 100644 GIT binary patch literal 276 zcmV+v0qg!BiwFn+9eZa2|8r?{Wo=<_E_iKh0L@iFZo?oDyyq1bcfg54)mApSDCyDHa8aNTXy1h9H#!A#SE zMbQC$yA)m6h;qjVO+Ze^?A=n#03{P~ghW`(!i1)Gh1Atkgi$?17***os`6n}avJ+&I>+ZD aC*T<VCD9X7#kiEdJhMCc7M0@@jeX-bx4noIjUa`Uk1HB7F$38zUwQSlQ~ha%NRaJ%i*dN68Z!9>%8 zLEZy>+Ze3hiBeaN+Ii864f*^~BaP6jrfQC5-IVnyLGH7gl6Xk{RdhKD1L4aJbJUdf zlFfw+NZR|nCLpC_adypSfT9jKK_tv(VMaaJOzQF_!YE%Mj52o^W&SYA|Auit(r2!I M0n*D0!2AUO0FPvQJpcdz diff --git a/v5/configuration/index.html b/v5/configuration/index.html index 248b5cc..e06bd74 100644 --- a/v5/configuration/index.html +++ b/v5/configuration/index.html @@ -249,6 +249,12 @@ + + + + diff --git a/v5/installation/index.html b/v5/installation/index.html index 69aeba5..c59ff99 100644 --- a/v5/installation/index.html +++ b/v5/installation/index.html @@ -249,6 +249,12 @@ + + + + diff --git a/v5/overview/index.html b/v5/overview/index.html index 579c0b9..7080660 100644 --- a/v5/overview/index.html +++ b/v5/overview/index.html @@ -249,6 +249,12 @@ + + + + diff --git a/v5/transports/index.html b/v5/transports/index.html index d939350..435393b 100644 --- a/v5/transports/index.html +++ b/v5/transports/index.html @@ -249,6 +249,12 @@ + + + + @@ -310,6 +316,12 @@

Transports

diff --git a/v5/upgrade-v4-to-v5/index.html b/v5/upgrade-v4-to-v5/index.html new file mode 100644 index 0000000..ef32b0d --- /dev/null +++ b/v5/upgrade-v4-to-v5/index.html @@ -0,0 +1,573 @@ + + + + + + + + + + + + + + + + + + + + + + + + + Upgrade from V4 to v5 - dot-mail - DotKernel Documentation + + + + + + + + + + + + + + +
+ +
+ + +
+
+ +
+ + + + + + + + + +

How to update dotkernel/dot-mail from v3/v4 to v5 in your projects

+
    +
  • The first thing to do is download the new mail configuration file.
  • +
  • Add the values you configured for your project, focusing on transport, message_options and smtp_options, then replace your old configuration file.
  • +
  • In your composer.json update "dotkernel/dot-mail": "^5.0.0", and run composer update in the command line.
  • +
+

At this moment, mime and imap related functionality is removed.

+

Technical approach

+

You can follow all the changes in this list of PRs:

+ +
+

Function definition changes will not be covered in this article.

+
+

When upgrading dotkernel/dot-mail from v4 to v5, the main focus is on the configuration file mail.global.php. +It was revised to implement symfony/mailer, to remove features that are no longer available and to make dotkernel/dot-mail easier to configure.

+
?php
+
+declare(strict_types=1);
+
+return [
+    /**
+     * Dotkernel mail module configuration
+     * Note that many of these options can be set programmatically too, when sending mail messages actually that is
+     * what you'll usually do, these configs provide just defaults and options that remain the same for all mails
+     */
+    'dot_mail' => [
+        //the key is the mail service name, this is the default one, which does not extend any configuration
+        'default' => [
+            //message configuration
+            'message_options' => [
+                //from email address of the email
+                'from' => '',
+                //from name to be displayed instead of from address
+                'from_name' => '',
+                //reply-to email address of the email
+                'reply_to' => '',
+                //replyTo name to be displayed instead of the address
+                'reply_to_name' => '',
+                //destination email address as string or a list of email addresses
+                'to' => [],
+                //copy destination addresses
+                'cc' => [],
+                //hidden copy destination addresses
+                'bcc' => [],
+                //email subject
+                'subject' => '',
+                //body options - content can be plain text, HTML
+                'body' => [
+                    'content' => '',
+                    'charset' => 'utf-8',
+                ],
+                //attachments config
+                'attachments' => [
+                    'files' => [],
+                    'dir'   => [
+                        'iterate'   => false,
+                        'path'      => 'data/mail/attachments',
+                        'recursive' => false,
+                    ],
+                ],
+            ],
+            /**
+             * the mail transport to use can be any class implementing
+             * Symfony\Component\Mailer\Transport\TransportInterface
+             *
+             * for standard mail transports, you can use these aliases:
+             * - sendmail  => Symfony\Component\Mailer\Transport\SendmailTransport
+             * - esmtp     => Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport
+             *
+             * defaults to sendmail
+             **/
+            'transport' => 'sendmail',
+            //options that will be used only if esmtp adapter is used
+            'smtp_options' => [
+                //hostname or IP address of the mail server
+                'host' => '',
+                //port of the mail server - 587 or 465 for secure connections
+                'port'              => 587,
+                'connection_config' => [
+                    //the smtp authentication identity
+                    'username' => '',
+                    //the smtp authentication credential
+                    'password' => '',
+                    //to disable auto_tls set tls key to false
+                    //it's not recommended to disable TLS while connecting to an SMTP server
+                    'tls' => null,
+                ],
+            ],
+        ],
+        // option to log the SENT emails
+        'log' => [
+            'sent' => getcwd() . '/log/mail/sent.log',
+        ],
+    ],
+];
+

Make sure to use ONE of the below transporters, based on your server configuration.

+
'transport' => 'sendmail',
+

OR

+
'transport' => 'esmtp',
+

We set Sendmail to be the default.

+ + + + + + + + + +
+
+
+ + + + + + + + + diff --git a/v5/usage/index.html b/v5/usage/index.html index 828ef18..3fc8a9b 100644 --- a/v5/usage/index.html +++ b/v5/usage/index.html @@ -249,6 +249,12 @@ + + + +