1

I do have powermail form in TYPO3 10. There are several email fields in the frontend which are checked with "This field contains the Email of the sender [sender_email]" checkbox. However after user fills the form in frontend - only first email is used to send confirmation email to user.

This might be related to getSenderMailFromArguments from MailRepository

    public function getSenderMailFromArguments(Mail $mail, string $default = ''): string
    {
        $email = '';
        foreach ($mail->getAnswers() as $answer) {
            if ($answer->getField() !== null &&
                $answer->getField()->isSenderEmail() &&
                GeneralUtility::validEmail(trim($answer->getValue()))
            ) {
                $email = trim($answer->getValue());
                break;
            }
        }
        if (empty($email)) {
            $email = $this->getSenderMailFromDefault($default);
        }
        return $email;
    }

Anyone has idea if it is possible to have several email beeing sent as a confirmation to user?

mcyg
  • 307
  • 2
  • 12

2 Answers2

0

I'm not sure if this will work for confirmation emails too, but via TypoScript you can add multiple (b)cc-recipients.

plugin.tx_powermail.settings.setup {
  sender {
    overwrite {
      # Add further BCC Receivers (split them via comma)
      bcc = TEXT
      bcc.data = GP:tx_powermail_pi1|field|bcc_receiver2
    }
  }
}

https://github.com/einpraegsam/powermail/blob/master/Configuration/TypoScript/Main/Configuration/04_MailSender.typoscript#L52

Julian Hofmann
  • 2,081
  • 1
  • 8
  • 16
0

In Powermail ^7.2 i'm XClassing the Powermail SendMailService to send a confirmation to several BCC e-mail-addresses.

For that you need to XClass the SendMailService in the ext_localconf.php.

EXT:ext_name/ext_localconf.php:

<?php

$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\In2code\Powermail\Domain\Service\Mail\SendMailService::class] = [
'className' => \VENDOR\ExtName\Service\SendMailService::class

];

Then implement your custom SendMailService.

EXT:ext_name/Classes/Service/SendMailService.php:

<?php
namespace VENDOR\ExtName\Service;

class SendMailService extends \In2code\Powermail\Domain\Service\Mail\SendMailService
{

    // Depending on what you want to achive you can now implement custom methods.
    // I overwrite the addBcc method, because the mail receivers are not allowed to
    // know the other mail-receiver mail-addresses.
    // But you could also overwrite the prepareAndSend method

    // Somehow like this
    protected function prepareAndSend(array $email)
    {

        /** @var MailMessage $message */
        $message = ObjectUtility::getObjectManager()->get(MailMessage::class);

        $form = $this->getMail()->getForm();
        $isCorrectForm = $this->checkForm($form);  // You need to implement the checkForm method

        if($this->type == 'sender' && $isCorrectForm)
        {
            
            $answers = $this->getMail()->getAnswersByFieldUid();

            // ... Fetch the e-mail-addresses from the form
            // And add them to the message
             
            $message
                ->setTo([
                    $email['receiverEmail'] => $email['receiverName'],
                    $anotherReceiverEmail => $anotherReceiverName
                ])
                ->setFrom([$email['senderEmail'] => $email['senderName']])
                ->setReplyTo([$email['replyToEmail'] => $email['replyToName']])
                ->setSubject($email['subject'])
               ->setCharset(FrontendUtility::getCharset());
        } else {
            $message
                ->setTo([$email['receiverEmail'] => $email['receiverName']])
                ->setFrom([$email['senderEmail'] => $email['senderName']])
                ->setReplyTo([$email['replyToEmail'] => $email['replyToName']])
                ->setSubject($email['subject'])
                ->setCharset(FrontendUtility::getCharset());
        }

        $message = $this->addCc($message);
        $message = $this->addBcc($message);
        // ...
        // ...
        $message->send();
        $this->updateMail($email);
        return $message->isSent();
    }
}
Mogens
  • 548
  • 1
  • 3
  • 10