Search code examples
formstypo3typo3-8.xplaintexttypo3-9.x

TYPO3 form framework: Sending email as both HTML and Plain Text


The finishers EmailToSender and EmailToReceiver both give the format option 'html' OR 'plaintext'. How can I send emails with both, 'plaintext' AND 'html'?

The background is: AFAIK emails should always contain a defined plaintext part for those of us who are not able or do not wish to receive HTML emails. AFAIK this is required by RFC (don't know which one).


Solution

  • As I never work much with the form-extension I don't know exactly if you're right about the mail-format, specifically that html-format never includes a text-only-part. I'd advise to check that the mail-format is really html and not multipart.

    If required you can add an own finisher, also as option in the Backend selection.

    In this documentation are many things described what is possible:

    • add own finisher class(es)
    • exchange data between different finishers
    • localize (translate) finishers
    • define default values
    • use the context of finishers
    • add the finisher to the UI of the backend

    As first step I'd try to program a simple finisher, it can do some simple thing like adding "Hello World" to the mail or replacing the mail-text completely.
    In this class I'd try to access data from other finishers and test if these data are programatically available even without activating the other finishers by choice in backend. If that's possible you could retrieve data from the two finishers for text- and html-mail and combine them according to your need.

    To add a bit code here, this is how a simple finisher is included:

    TYPO3:
      CMS:
        Form:
          prototypes:
            standard:
              finishersDefinition:
                CustomFinisher:
                  implementationClassName: 'VENDOR\MySitePackage\Domain\Finishers\CustomFinisher'
    

    and this is a simple finisher-class:

    declare(strict_types = 1);
    namespace VENDOR\MySitePackage\Domain\Finishers;
    
    class CustomFinisher extends \TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
    {
    
        protected $defaultOptions = [
            'yourCustomOption' => 'Olli',
        ];
    
        // ...
    }
    

    Further details you have to read in the documentation or ask more detailed.