in2code-de / powermail

This is the official repository of the TYPO3 extension powermail! Powermail is a well-known, editor-friendly, powerful and easy mailform extension for TYPO3
https://in2code.de
88 stars 174 forks source link

PHP Error: Array to string conversion in SpamNotification-Mail with Checkboxes #851

Closed olivermeckel closed 3 months ago

olivermeckel commented 1 year ago

When a contact request is detected as spam by Powermail, I get a php error message in the log:

Core: Error handler (FE): PHP Warning: Array to string conversion in /html/typo3/typo3_src-11.5.21/vendor/typo3fluid/fluid/src/Core/Parser/SyntaxTree/AbstractNode.php line 73

In addition to simple input fields, textareas, dropdowns and so on, the form also contains input fields of the type checkboxes (with multiple values). The output of multiple values in the sender and receiver mails as well as in the back end is correct. In the spam notification mail and log, the output is as text "array".

TYPO3 11.5.21 Powermail 10.7.0 PHP 8.1.12

olivermeckel commented 1 year ago

Is it the missing check whether the answer is a string or an array in the templates for the SpamNotifaction?{vh:condition.isArray(val:answer.value)}

Is there a way to send/test the spamnotification log or mail by system?

einpraegsam commented 1 year ago

I just tried to reproduce this issue with PHP 8.0 and the lastest powermail but there is no issue in my eyes: Screenshot 2023-02-13 at 11-52-42 Powermail for TYPO3 11 active (Log)

Any hints how to reproduce it?

olivermeckel commented 1 year ago

Hi Alex,

just to clarify: it's a php-error reported in the typo3 backend when spameshield detects an spam and send a spamnotification by mail or log using the templates plugin.tx_powermail.settings.spamshield.emailTemplate = EXT:powermail/Resources/Private/Templates/Mail/SpamNotification.html and logTemplate = EXT:powermail/Resources/Private/Templates/Log/SpamNotification.html

These template don't have a condition for value string or array

einpraegsam commented 1 year ago

Ah, ok - I can read the error in the log:

  | Core: Error handler (FE): PHP  Warning: Array to string conversion in  /var/www/html/powermail11.localhost.de/vendor/typo3fluid/fluid/src/Core/Parser/SyntaxTree/AbstractNode.php  line 73
-- | --
olivermeckel commented 1 year ago

I changed the code for providing the form variables ind the spam notification template for logs to:

<f:for each="{mail.answers}" as="answer">
    <f:if condition="{vh:condition.isArray(val:answer.value)}">
        <f:else>
            - {answer.field.title}: {answer.value}
        </f:else>
        <f:then>
            <f:for each="{answer.value}" as="subValue" iteration="index">
                <f:if condition="{subValue}">
                    <vh:misc.manipulateValueWithTypoScript answer="{answer}" type="{type}">{subValue}</vh:misc.manipulateValueWithTypoScript><f:if condition="{index.isLast}"><f:else>, </f:else></f:if>
                </f:if>
            </f:for>
        </f:then>
    </f:if>
</f:for>

No more php-errors

olivermeckel commented 1 year ago

By the way, Spamshield works great and detects 100% of spam requests. Great feature!

pitscribble commented 1 year ago

Thanks for the code snippet @olivermeckel, solved the problem for me too.

TYPO3 11.5 Powermail 10.7.3 PHP 8.1

mschwemer commented 3 months ago

As the comment in the last PR states, it is fixed in powermail v12.

If you need a backport to powermail v10 / TYPO3 v11 please contact in2code https://www.in2code.de/