2

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.

app\code\Custom\Module\view\frontend\email\sucess.html

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

Message

{{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');
$state->setAreaCode('frontend');

$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();
$postObject->setData($emailTempVariables);

$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($templateParams)
            ->setTemplateVars(['data' => $postObject])
            ->setFrom($sender)
            ->addTo($senderEmail)
            ->setReplyTo($senderEmail)
            ->getTransport();
        $transport->sendMessage();
        echo "Success";
        exit;
  } catch (Exception $e) {
    echo "<pre>";
    print_r($e->getMessage());
    exit;
}
  • try with {{var data.custom_email_footer}} or show your php code where you have set custom_email_footer – Rakesh Jesadiya Oct 28 '16 at 10:02
  • @Rakesh Updated Question. Still not getting value in email. Don't want to replace like First Name – Ankit Shah Oct 28 '16 at 10:12
  • 1
    You can try with {{customVar code="custom_email_footer"}}, add double qutoes in codename – Rakesh Jesadiya Oct 28 '16 at 10:22
  • Getting Plain Value of Custom Attribute Not HTML. How to get that? – Ankit Shah Oct 28 '16 at 10:26
  • Have you fill up Variable HTML Value from variable code? May be you have fill up Variable plain value – Rakesh Jesadiya Oct 28 '16 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.