You are here

public function AmazonSesTestForm::submitForm in Amazon SES 2.0.x

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/AmazonSesTestForm.php, line 134

Class

AmazonSesTestForm
Amazon SES test form.

Namespace

Drupal\amazon_ses\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $to = $form_state
    ->getValue('to');
  $from = $this->config
    ->get('from_address');
  $body = $this
    ->t('This is a test of the Amazon SES module. The module has
      been configured successfully!');
  $message = [
    'to' => $to,
    'from' => $from,
    'subject' => $this
      ->t('Amazon SES test'),
    'body' => $body,
  ];
  $message_id = $this->handler
    ->send($message);
  if ($message_id) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('A test message was sent to %to.', [
      '%to' => $to,
    ]));
  }
  else {
    $this
      ->messenger()
      ->addError($this
      ->t('Error sending message to %to.', [
      '%to' => $to,
    ]));
  }
}