public function TestMailForm::submitForm in Sparkpost email 8.2
Same name and namespace in other branches
- 8 src/Form/TestMailForm.php \Drupal\sparkpost\Form\TestMailForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ TestMailForm.php, line 101
Class
- TestMailForm
- The form for sending test mails from Sparkpost.
Namespace
Drupal\sparkpost\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// Prepare.
$to = $form_state
->getValue('recipient');
$params = [];
$params['subject'] = $form_state
->getValue('subject');
$params['body'] = $form_state
->getValue('body');
$params['include_attachment'] = $form_state
->getValue('attachment');
// Send.
$message = $this->mailManager
->mail('sparkpost', 'test_mail_form', $to, LanguageInterface::LANGCODE_NOT_SPECIFIED, $params);
if ($message['result']) {
$this
->messenger()
->addStatus($this
->t('Sparkpost test email sent to %to.', [
'%to' => $to,
]));
}
else {
$form_state
->setRebuild();
}
}