1

I want to send the Product Image in email I'm getting the ID of the product from my custom table now from that ID how can I get the image of the product and send it in the email

public function sendAdminEmail($data)
{
    $mail = $data['email']; 

    $product_id = $data['product_id'];      //Product Id for Image

    // $product = $this->_productRepositoryFactory->create()->getById($product_id);
    // $imgg = $product->getData('image');

    $store = $this->_storeManager->getStore()->getId();
    $transport = $this->_transportBuilder->setTemplateIdentifier('makeanoffer_adminhtml_template')
        ->setTemplateOptions(['area' => 'frontend', 'store' => $store])
        ->setTemplateVars(
            [
                'store' => $this->_storeManager->getStore(),
                'name'  => $data['name'],
                // 'email' => $data['email'],
                // 'img'   => $imgg,
                'pnumber' => $data['pnumber'],
                'offeramount' => $data['offeramount'],
                'message' => $data['message'],
                'product_name' => $data['product_name'],
                'product_price' => $data['product_price'],
            ]
        )
        ->setFrom('general')
        // you can config general email address in Store -> Configuration -> General -> Store Email Addresses
        // ->addTo($this->_helper->adminEmail(), 'Veronica')
        ->addTo($mail, 'Veronica')
        ->getTransport();
    $transport->sendMessage();
    return $this;
}

as you guys can see that I'm passing $data which returns data of my custom table in the form of array and my custom email template is

    {{template config_path="design/email/header_template"}} 
 <p align="center"><b style="color: #009900">Name:</b> {{trans "%name" name=$name}}</p>
 <p align="center"><b style="color: #009900">Email:</b> {{trans "%email" email=$email}}</p>
 <p align="center"><b style="color: #009900">Phone Number:</b> {{trans "%pnumber" pnumber=$pnumber}}</p>
 <p align="center"><b style="color: #009900">Offer Amount:</b> {{trans "%offeramount" offeramount=$offeramount}}</p>
 <p align="center"><b style="color: #009900">Message:</b> {{trans "%message" message=$message}}</p>
 <p align="center"><b style="color: #009900">Product Name:</b> {{trans "%product_name" product_name=$product_name}}</p>
 <p align="center"><b style="color: #009900">Product Price:</b> {{trans "%product_price" product_price=$product_price}}</p>
{{template config_path="design/email/footer_template"}} 

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.