Contact form auto-reply does not send

Created on 4 March 2022, almost 3 years ago
Updated 4 May 2023, over 1 year ago

Problem/Motivation

In a contact form when you fill the "auto-reply" field the auto-reply email has not sended

Steps to reproduce

Create a form then fill "auto-reply"

Proposed resolution

I have checked the code and in

/web/core/modules/contact/src/MailHandler.php
line 131
$this->mailManager->mail('contact', 'page_autoreply', $sender_cloned->getEmail(), $current_langcode, $params);

Should be
$this->mailManager->mail('contact', 'page_autoreply', $to, $current_langcode, $params);

?

Thanks

🐛 Bug report
Status

Needs work

Version

10.1

Component
Contact 

Last updated 5 days ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • I have the same problem, and I think it has to do with this piece of code:

    /**
     * Implements hook_mail_alter().
     *
     * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
     * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
     */
    function contact_emails_mail_alter(&$message) {
      // If an email from the contact module, disable sending.
      $contact_form_ids = [
        'contact_page_autoreply',
        'contact_page_mail',
      ];
      if (in_array($message['id'], $contact_form_ids)) {
        /** @var \Drupal\contact\MessageInterface $contact_message */
        if ($contact_message = $message['params']['contact_message']) {
          $contact_form = $contact_message->getContactForm();
          $contact_form_id = $contact_form->id();
          /** @var \Drupal\contact_emails\ContactEmailStorageInterface $storage */
          $storage = \Drupal::entityTypeManager()->getStorage('contact_email');
          if ($storage->hasContactEmails($contact_form_id)) {
            // Disable sending of default mails if we have at least one email
            // set by contact_emails (regardless of whether or not it is a disabled
            // email).
            $message['send'] = FALSE;
          }
        }
        else {
          // If we don't have a contact_message object, something must have gone
          // wrong, let's disable just in case.
          $log = t('Unable to load the contact message when attempting to alter the default mailing from contact form for contact form id: @contact_form_id', ['@contact_form_id' => $message['id']]);
          \Drupal::logger('contact_emails')->notice($log);
          $message['send'] = FALSE;
        }
      }

    Located in web/modules/contrib/contact_emails/contact_emails.module. It says "disable sending of default emails of we have at least one email set by contact emails".

    So when I have a contact email entry here: /admin/structure/contact/manage/contact/emails
    It does not matter if I fill the auto-reply in /admin/structure/contact/manage/contact.

    But when I delete all emails in /admin/structure/contact/manage/contact/emails, auto-reply does work.

  • Sorry, my bad, this code belongs to contact_emails module, not to this one, although it is affecting this one. I already created a ticket for contact_emails: https://www.drupal.org/project/contact_emails/issues/3358232 🐛 Contact form auto-reply disabled when contact email available Active

Production build 0.71.5 2024