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();
}
}