1

Method setFrom is deprecated. Is Magento 2.4 any alternative?

2 Answers 2

0

With a new implementation, Magento 2.4 is a recommended setFromByScope alternative.

Change:

->setFrom($this->contactsConfig->emailSender()) To

->setFromByScope($this->contactsConfig->emailSender())


<?php
declare(strict_types=1);

namespace Module\Test\Model;
use Magento\Framework\Mail\Template\TransportBuilder;

/**
 * @var TransportBuilder
*/
private $transportBuilder;

class Main implements MailInterface
{
    /**
     * Initialize dependencies.
     * @param TransportBuilder $transportBuilder
     */
    public function __construct(
        TransportBuilder $transportBuilder
    ) {
        $this->transportBuilder = $transportBuilder;
    }

    public function send($replyTo, array $variables)
    {
       ...
        try {
            $transportBuilder = $this->transportBuilder
               ...
                ->setFromByScope($this->contactsConfig->emailSender())
               ...
            $transportBuilder->sendMessage();
        } finally {
            ...
        }
    }
 }
0

Alternative is setFromByScope. In fact setFrom

Original post:

Method setFrom is deprecated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.