Breaking: #108097 - MailMessage->send() removed 

See forge#108097

Description 

Class MailMessage is a data object that should not contain service methods like send(). The following methods have been removed:

  • TYPO3\CMS\Core\Mail\MailMessage->send()
  • TYPO3\CMS\Core\Mail\MailMessage->isSent()

Impact 

Using the above methods on instances of this class will raise fatal PHP errors.

Affected installations 

Instances that create MailMessage objects and call send() or isSent() are affected. The extension scanner is not configured to find affected code since the method names are too generic.

Migration 

The service (usually a controller class) that sends emails should be reconfigured to get an instance of \TYPO3\CMS\Core\Mail\MailerInterface injected and should use that service to send() the mail.

Example before:

use TYPO3\CMS\Core\Mail\MailMessage;

final readonly class MyController
{
    public function sendMail()
    {
        $email = new MailMessage();
        $email->subject('Some subject');
        $email->send();
    }
}
Copied!

Example after:

use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Mail\MailerInterface;

final readonly class MyController
{
    public function __construct(
        private MailerInterface $mailer
    ) {}

    public function sendMail()
    {
        $email = new MailMessage();
        $email->subject('Some subject');
        $this->mailer->send($email);
    }
}
Copied!