powermail icon indicating copy to clipboard operation
powermail copied to clipboard

Empty receiver mail subject triggers unwanted error flash message

Open franzkugelmann opened this issue 3 years ago • 4 comments

If an editor leaves the field receiver.subject empty (and no override via TS is set), then the expected behaviour is that this disables the mail sending. The mail is indeed not sent, but in case the editor did leave the field receiver.email empty ("why should we add an email address if we do not want to send the mail"), then after sending the form the enduser gets the error flash message: "Error, Mail could not sent correctly!"

This causes lots of people to try resend the form multiple times in one of our projects.

franzkugelmann avatar Oct 20 '20 09:10 franzkugelmann

I just tested, but I can't reproduce this issue with this settings (with the latest powermail in TYPO3 10):

backend frontend

Any hints how to reproduce?

einpraegsam avatar Nov 08 '20 15:11 einpraegsam

Hi Alex, thanks for taking care! I just

  • installed the lastest powermail 8.2.3 into an empty TYPO3 10.4.9
  • added static TS "Main Template (powermail)"
  • created a form with one one field "name"
  • used this form in a new powermail plugin (screenshot same as yours - nothing edited beside choosing the form)
  • sent the form
  • got the output "Error, Mail could not sent correctly!" above the single field.

For this to happen, you must have no receiver email configured, since there are several places where powermail tries to fech one:

  • flexform
  • TypoScript
  • ['EXT']['powermailDevelopContextEmail']

Then the loop in Classes/Domain/Service/Mail/SendReceiverMailPreflight.php:66 is never entered, resulting in $isSent = false; resulting in the error message.

We could do some screensharing to figure out what we do differently if you want.

franzkugelmann avatar Nov 09 '20 15:11 franzkugelmann

Hi Alex, I can confirm and reproduce this behaviour using powermail 7.4.1 / TYPO3 9.5.x.

If "Subject for Email to Receiver" is empty, the form values are correctly stored in the database and no email is sent, but a form validation error is shown:

In Classes/Controller/FormController.php, the result of sendReceiverMail() gets assigned to $isSent. As no subject is set, no mail is sent and $isSent correctly evalualtes to false, causing a flash message to be added:

grafik
if ($this->isReceiverMailEnabled()) {
                /** @noinspection PhpMethodParametersCountMismatchInspection */
                $mailPreflight = $this->objectManager->get(SendReceiverMailPreflight::class, $this->settings);
                $isSent = $mailPreflight->sendReceiverMail($mail, $hash);
                if ($isSent === false) {
                    $this->addFlashMessage(
                        LocalizationUtility::translate('error_mail_not_created'),
                        '',
                        AbstractMessage::ERROR
                    );
                    $this->messageClass = 'error';
                }
            }

I was able to suppress the flash message by simply adding if ($isSent === false && $this->settings['receiver']['subject'] != '' ) {

Cheers, Marcus

atnetws avatar Dec 10 '20 11:12 atnetws

Thank you @atnetws! That fixed the issue :)

KreativeKrise avatar Mar 16 '21 16:03 KreativeKrise

We are using 10.7.2 at the moment and the issue is still not solved. Although leaving the plugin-setting settings.flexform.receiver.subject empty, the mail is being sent anyways for the code only tests for the typoscript setting plugin.tx_powermail.settings.setup.receiver.enable and not flexform anymore. The only way to prevent the mail from being sent is to set the constant plugin.tx_powermail.settings.receiver.enable to 0. But this is not an appropriate behaviour. Especially for editors which aren't supposed to edit constants.

Please fix the issue asap. Thank you very much in advance.

chrissonntag avatar Apr 17 '23 12:04 chrissonntag

We are using 10.7.2 at the moment and the issue is still not solved.

Can confirm this for 8.4.2 also. I recently added my abovementioned code to a project, we inject it using composer-patches as a workaround.

atnetws avatar Apr 17 '23 13:04 atnetws

Hi,

This occurs when the email-field is empty. If you fill in the email-field and leave the subject empty there is no error message.

ext/powermail/Classes/Domain/Service/Mail/SendReceiverMailPreflight.php returns false because it doesn't get any email from ext/powermail/Classes/Domain/Service/Mail/ReceiverMailReceiverPropertiesService.php

Kind regards

Tomas

tomashavner avatar Sep 07 '23 09:09 tomashavner