关于从我在 drupal 中的自定义注册表格发送的邮件

regarding mail sent from my custom registration form in drupal

我已经在 Drupal 8 中创建了一个自定义注册表单,现在我想通过提交表单来发送一封邮件。所以我是这样做的

This is my .module file
/**
 * Implements hook_mail().
 */
function Registration_form_mail($key, &$message, $params) {
  $options = array(
    'langcode' => $message['langcode'],
  );
  switch ($key) {
    case 'contact_form':
      $message['from'] = \Drupal::config('system.site')->get('mail');
      $message['subject'] = $params['subject'];
      $message['body'][] = $params['body'];
      break;
  }
}


public function submitForm(array &$form, FormStateInterface $form_state){
$mailManager = \Drupal::service('plugin.manager.mail');
        $module = 'Registration_form';
        $key = 'contact_form'; // Replace with Your key
        $to = $form_state->getValue('Email');
        $params = array(
            'body' => 'test',
            'subject' => 'Website Information Request',
            );
        $langcode = \Drupal::currentUser()->getPreferredLangcode();
        $send = true;
        $message['subject'] = t('nouveau contact ');
        $message['body'][] = t('test');


        $result = $mailManager->mail($module, $key, $to, $langcode, $params, NULL, $send);
        if ($result['result'] != true) {
        $message = t('There was a problem sending your email notification to @email.', array('@email' => $to));
        drupal_set_message($message, 'error');
        \Drupal::logger('mail-log')->error($message);
        return;
        }
        else{
        $message = t('An email notification has been sent to @email ', array('@email' => $to));
        drupal_set_message($message);
        \Drupal::logger('mail-log')->notice($message);
        }
}

所以我的问题是我在 xampp 中使用本地主机并且我想在提交表单后发送一封邮件,但是我收到了这个错误

无法发送电子邮件。如果问题仍然存在,请联系站点管理员。 将您的电子邮件通知发送至 ABC@gmail.com
时出现问题 那么我该如何解决我的问题,我浏览了整个网站但找不到答案。

问题可能出在电子邮件配置上。看看这篇文章是否对您有帮助: https://stevepolito.design/blog/drupal-configure-smtp-module-work-gmail-updated/