You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
34
+
35
+
Under `message_options` key:
36
+
-`from` - email address from whom users will receive emails
37
+
38
+
Under `smtp_options` key:
39
+
-`host` - the mail server's hostname or IP address
40
+
-`port` - the mail server's port
41
+
-`connection_config` - fill in the `username`, `password` and `ssl` keys with the login details of the email used in `from` above
In `config/autoload/local.php` add under `contact` => `message_receivers` => `to` key *string* values with the emails that should receive contact messages
72
+
73
+
Note: **Please add at least 1 email address in order for contact message to reach someone**
74
+
75
+
Also feel free to add as many cc as you want under `contact` => `message_receivers` => `cc` key
76
+
77
+
### Sending an e-mail
78
+
79
+
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.
80
+
81
+
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()`.
82
+
83
+
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`.
97
+
98
+
```php
99
+
try {
100
+
$this->userService->sendBasicMail();
101
+
$this->messenger->addSuccess('The mail was sent successfully', 'user-login');
0 commit comments