- 9.1.x core/lib/Drupal/Core/Mail/MailManager.php DrupalCoreMailMailManager::mail()
- 9.0.x core/lib/Drupal/Core/Mail/MailManager.php DrupalCoreMailMailManager::mail()
- 9.2.x core/lib/Drupal/Core/Mail/MailManager.php DrupalCoreMailMailManager::mail()
- 8.9.x core/lib/Drupal/Core/Mail/MailManager.php DrupalCoreMailMailManager::mail()
- 8.0.x core/lib/Drupal/Core/Mail/MailManager.php DrupalCoreMailMailManager::mail()
- 8.1.x core/lib/Drupal/Core/Mail/MailManager.php DrupalCoreMailMailManager::mail()
- 8.3.x core/lib/Drupal/Core/Mail/MailManager.php DrupalCoreMailMailManager::mail()
- 8.4.x core/lib/Drupal/Core/Mail/MailManager.php DrupalCoreMailMailManager::mail()
- 8.5.x core/lib/Drupal/Core/Mail/MailManager.php DrupalCoreMailMailManager::mail()
- 8.6.x core/lib/Drupal/Core/Mail/MailManager.php DrupalCoreMailMailManager::mail()
- 8.7.x core/lib/Drupal/Core/Mail/MailManager.php DrupalCoreMailMailManager::mail()
- 8.8.x core/lib/Drupal/Core/Mail/MailManager.php DrupalCoreMailMailManager::mail()
Composes and optionally sends an email message.
Core Plugin Email Overrides. These actions allow you to override the default emails sent by the core WP Job Manager plugin, or any addon plugin you’re using. If you create an email using action above (like new Job/Listing published, this will disable default emails from being sent). New Job/Listing Submitted; New Resume Submitted. Add this to your Gmail! For Firefox 38+, Chrome 5.0+, Safari 5.1+, Opera 15+, and Edge 39+. Works with Gmail and G Suite (Google Apps) email. The plugin lets you drop and drag your emails to any of your cloud management system and vice versa. MxHero also automatically converts your email messages to PDF format before saving them and placing them in easy-to-remember folders. Newsletter WordPress Plugin. Newsletter Plugin is foremost the No.1 WordPress Plugin available in. Save email to PDF, MSG, DOC, HTML, RTF, EML, TXT FileChimp makes it easy to automatically file emails from Outlook into relevant network folders, avoid duplication and share emails. Organise and keep a copy of filed emails in Outlook.
Sending an email works with defining an email template (subject, text andpossibly email headers) and the replacement values to use in theappropriate places in the template. Processed email templates are requestedfrom hook_mail() from the module sending the email. Any module can modifythe composed email message array using hook_mail_alter(). FinallyDrupal::service('plugin.manager.mail')->mail() sends the email, which canbe reused if the exact same composed email is to be sent to multiplerecipients.
Finding out what language to send the email with needs some consideration.If you send email to a user, her preferred language should be fine, so useDrupalCoreSessionAccountInterface::getPreferredAdminLangcode(). If yousend email based on form values filled on the page, there are twoadditional choices if you are not sending the email to a user on the site.You can either use the language used to generate the page or the sitedefault language. SeeDrupalCoreLanguageLanguageManagerInterface::getDefaultLanguage(). Theformer is good if sending email to the person filling the form, the lateris good if you send email to an address previously set up (like contactaddresses in a contact form).
Taking care of always using the proper language is even more important whensending emails in a row to multiple users. Hook_mail() abstracts whetherthe mail text comes from an administrator setting or is static in thesource code. It should also deal with common mail tokens, only receiving$params which are unique to the actual email at hand.
An example:
Mastercool installation manual. Another example, which uses MailManagerInterface->mail() to format amessage for sending later:
Parameters
string $module:A module name to invoke hook_mail() on. The {$module}_mail() hook will becalled to complete the $message structure which will already containcommon defaults.
string $key:A key to identify the email sent. The final message ID for email alteringwill be {$module}_{$key}.
string $to:The email address or addresses where the message will be sent to. Theformatting of this string will be validated with thePHP email validation filter.Some examples are:
- user@example.com, anotheruser@example.com
- User <user@example.com>
- User <user@example.com>, Another User <anotheruser@example.com>
string $langcode:Language code to use to compose the email.
array $params:(optional) Parameters to build the email.
string|null $reply:Optional email address to be used to answer.
bool $send:If TRUE, call an implementation ofDrupalCoreMailMailInterface->mail() to deliver the message, andstore the result in $message['result']. Modules implementinghook_mail_alter() may cancel sending by setting $message['send'] toFALSE.
Return value
arrayThe $message array structure containing all details of the message. Ifalready sent ($send = TRUE), then the 'result' element will contain thesuccess indicator of the email, failure being already written to thewatchdog. (Success means nothing more than the message being accepted atphp-level, which still doesn't guarantee it to be delivered.)
Overrides MailManagerInterface::mail
File
- core/lib/Drupal/Core/Mail/MailManager.php, line 166
Class
- MailManager
- Provides a Mail plugin manager.
Namespace
DrupalCoreMailCode
Comments
Simple example on hook_cron
This is just a simple example that fires on hook_cron()
Example after submitting a custom form
called from my custom module named eura_registerform
'registerMail' can be whatever key value you'd like to use
$params can be left empty too: $params = array();
and then in eura_registerform.module:
Drupal 8 Simple example of hook_mail with cron
Wp Mail Plugin
Simple message sending
You can send simple message without implementing hook_mail: