Method setFrom is deprecated. Is Magento 2.4 any alternative?
2 Answers
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 {
...
}
}
}