use Magento\Framework\Mail\TransportInterfaceFactory;
use Magento\Framework\Mail\Message;
[...]
protected $mailTransportFactory;
public function __construct(
TransportInterfaceFactory $mailTransportFactory
) {
$this->mailTransportFactory = $mailTransportFactory;
}
[...]
public function sendEmail()
{
$message = new Message();
$message->setFrom('[email protected]');
$message->addTo('[email protected]');
$message->setSubject('Subject');
$message->setBody('Body');
$transport = $this->mailTransportFactory->create(['message' => $message]);
try {
$transport->sendMessage();
} catch (\Exception $e) {
echo $e->getMessage();
}
}
}
Created
July 19, 2024 13:43
-
-
Save DominicWatts/727852c4039f3213ab14a76215eeb202 to your computer and use it in GitHub Desktop.
Magento 2 : send email without transport builder or template command line #magento2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment