Type
magento2-module
Magento2 Custom Mail
magento2-module
MIT
None
None
None
None
None
None
$data = [
'comment' => 'Hello this is a test message',
'email' => '[email protected]',
'name' => 'John Doe',
];
/**
* wrap parameters values in array as they are called by call_user_func_array
*/
$config = [
'template_identifier' => ['contact_us'],
'template_options' => [['area' => Area::AREA_FRONTEND ,'store' => $this->storeManager->getStore()->getId()]],
'template_vars' => [$data],
'from' => [['email' => '[email protected]', 'name' => 'John Doe']],
'to' => ['email' =>'[email protected]', 'name' => 'Tom Right'],
'cc' => ['email' =>'[email protected]', 'name' => 'Sarah Foxon'],
'bcc' => ['email' =>'[email protected]', 'name' => 'Ahmed Hassan'],
];
$this->sendMail->setConfig($config);
$this->sendMail->send();
app/code/Namespace/Modulename/etc/email_templates.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Email/etc/email_templates.xsd">
<template id="contact_us" label="Contact Us" file="contactus.html" type="html" module="Namespace_Modulename" area="frontend"/>
</config>
app/code/Namespace/Modulename/view/frontend/email/contactus.html
<!--@subject "Contact Us" @-->
<p>Name: {{var name}}</p>
<p>Email: {{var email}}</p>
<p>Comment: {{var comment}}</p>