As done in Magento 1.x.x, how can custom transactional emails be sent.
Additional
Add email in bcc
Send attachment along email
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityAs done in Magento 1.x.x, how can custom transactional emails be sent.
Additional
Add email in bcc
Send attachment along email
okie bit of debugging helps,
Sending a transactional email in Magento2
class Dummy
{
/**
* @var \Magento\Framework\Mail\Template\TransportBuilder
*/
private $_transportBuilder;
public function __construct( \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder){
$this->_transportBuilder = $transportBuilder;
}
public function sendEmail($templateId =1, $storeId =1,$templateParams)
{
$transport = $this->_transportBuilder->setTemplateIdentifier($templateId)
->setTemplateOptions(['area' => Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])
->setTemplateVars($templateParams)
->setFrom('[email protected]')
->addTo('[email protected]')
->setReplyTo('[email protected]')
->addBcc('[email protected]')
->getTransport();
$transport->sendMessage();
}
}
<!--@subject Promopoup@-->
Magento 2 Uses \Magento\Framework\Mail\Template\TransportBuilder class for send custom email.
You need to create a simple module and set email_tempaltes.xml file for defining your transaction mail templates.
You can send mail from Adminhtml or Frontend Scope area.
I have shared a link for step by step guide to send a custom mail from Magento 2 using a module.
it's working for me
$emailTemplateVariables = array();
$emailTempVariables['myvar'] = $myvar;
$senderName = 'test';
$senderEmail = '[email protected]';
$postObject = new \Magento\Framework\DataObject();
$postObject->setData($emailTempVariables);
$sender = [
'name' => $senderName,
'email' => $senderEmail,
];
$transport = $this->_transportBuilder->setTemplateIdentifier('myemail_email_template')
->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])
->setTemplateVars(['data' => $postObject])
->setFrom($sender)
->addTo($email)
->setReplyTo($senderEmail)
->getTransport();
$transport->sendMessage();
more info