public function EmailConfirmation::sendRequest in Email confirmer 8
Sends the email confirmation request.
Confirmation must be not expired, cancelled or confirmed. More than one request can be sent, but some delivery limitations are applied. See docs for details.
Return value
bool TRUE if request was successfully sent, FALSE on sending error.
Throws
\Drupal\email_confirmer\InvalidConfirmationStateException If confirmation is cancelled, expired or already confirmed.
Overrides EmailConfirmationInterface::sendRequest
File
- src/
Entity/ EmailConfirmation.php, line 246
Class
- EmailConfirmation
- Defines the email confirmation entity class.
Namespace
Drupal\email_confirmer\EntityCode
public function sendRequest() {
$status = $this
->getStatus();
if ($status != 'pending') {
throw new InvalidConfirmationStateException('Unable to send request email for ' . $status . ' confirmations.');
}
// Recently sent?
if ($this
->isRequestSent() && $this
->getLastRequestDate() + intval(\Drupal::config('email_confirmer.settings')
->get('resendrequest_delay')) > \Drupal::time()
->getRequestTime()) {
// Add to queue for further processing.
\Drupal::queue('email_confirmer_requests')
->createItem($this
->id());
return TRUE;
}
// Send the confirmation request.
$message = \Drupal::service('plugin.manager.mail')
->mail('email_confirmer', 'confirmation_request', mb_substr(PHP_OS, 0, 3) == 'WIN' ? $this
->getEmail() : '"' . addslashes(Unicode::mimeHeaderEncode(\Drupal::config('system.site')
->get('name'))) . '" <' . $this
->getEmail() . '>', $this
->language(), [
'context' => [
'email_confirmer_confirmation' => $this,
],
]);
if ($ok = !empty($message['result'])) {
$this
->setLastRequestDate(\Drupal::time()
->getRequestTime());
}
return $ok;
}