I'm following below post & able to send email.

how to send custom email no template in magento2?

I have created 1 custom variable named Custome Footer.


<!--@subject Test Subject @-->
Hi {{trans "%lastName" lastName=$data.lastName}} {{trans "%firstName" firstName=$data.firstName}},


{{customVar code=custom_email_footer}}

When i receive email Custom Variable custom_email_footer is not replaced & i'm getting that portion Blank

Below is code i'm testing Email Outside Magento by extending

require __DIR__ . '/app/bootstrap.php';

use Magento\Framework\App\Bootstrap;

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();

$state = $objectManager->get('Magento\Framework\App\State');

$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface');

// Customer Factory to Create Customer
$transportBuilder = $objectManager->get('\Magento\Framework\Mail\Template\TransportBuilder');
$websiteId = $storeManager->getWebsite()->getWebsiteId();

/// Get Store ID
$store = $storeManager->getStore();
$storeId = $store->getStoreId();

$senderName = 'Sender';
$senderEmail = 'abc@gmail.com';

$emailTemplateVariables = array();
$emailTempVariables['firstName'] = 'First';
$emailTempVariables['lastName'] = 'Last';

$postObject = new \Magento\Framework\DataObject();

$sender = [
    'name' => $senderName,
    'email' => $senderEmail,

$templateId = 'my_email_template';
$storeId =1;
$templateParams = array();

try {  
     $transport = $transportBuilder->setTemplateIdentifier($templateId)
            ->setTemplateOptions(['area' => Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])
            ->setTemplateVars(['data' => $postObject])
        echo "Success";
  } catch (Exception $e) {
    echo "<pre>";
  • try with {{var data.custom_email_footer}} or show your php code where you have set custom_email_footer Oct 28, 2016 at 10:02
  • @Rakesh Updated Question. Still not getting value in email. Don't want to replace like First Name
    – Jackson
    Oct 28, 2016 at 10:12
  • 1
    You can try with {{customVar code="custom_email_footer"}}, add double qutoes in codename Oct 28, 2016 at 10:22
  • Getting Plain Value of Custom Attribute Not HTML. How to get that?
    – Jackson
    Oct 28, 2016 at 10:26
  • Have you fill up Variable HTML Value from variable code? May be you have fill up Variable plain value Oct 28, 2016 at 10:30


Your Answer

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