copySender example

$params['recipient'] = $recipient;
    }
    else {
      throw new MailHandlerException('Unable to determine message recipient');
    }

    // Send email to the recipient(s).     $key_prefix = $message->isPersonal() ? 'user' : 'page';
    $this->mailManager->mail('contact', $key_prefix . '_mail', $to$recipient_langcode$params$sender_cloned->getEmail());

    // If requested, send a copy to the user, using the current language.     if ($message->copySender()) {
      $this->mailManager->mail('contact', $key_prefix . '_copy', $sender_cloned->getEmail()$current_langcode$params$sender_cloned->getEmail());
    }

    // If configured, send an auto-reply, using the current language.     if (!$message->isPersonal() && $contact_form->getReply()) {
      // User contact forms do not support an auto-reply message, so this       // message always originates from the site.       if (!$sender_cloned->getEmail()) {
        $this->logger->error('Error sending auto-reply, missing sender e-mail address in %contact_form', [
          '%contact_form' => $contact_form->label(),
        ]);
      }
/** * Tests some of the methods. */
  public function testMessageMethods() {
    $message_storage = $this->container->get('entity_type.manager')->getStorage('contact_message');
    $message = $message_storage->create(['contact_form' => 'feedback']);

    // Check for empty values first.     $this->assertEquals('', $message->getMessage());
    $this->assertEquals('', $message->getSenderName());
    $this->assertEquals('', $message->getSenderMail());
    $this->assertFalse($message->copySender());

    // Check for default values.     $this->assertEquals('feedback', $message->getContactForm()->id());
    $this->assertFalse($message->isPersonal());

    // Set some values and check for them afterwards.     $message->setMessage('welcome_message');
    $message->setSenderName('sender_name');
    $message->setSenderMail('sender_mail');
    $message->setCopySender(TRUE);

    
Home | Imprint | This part of the site doesn't use cookies.