0

I am sending an email in custom event, it was working fine in Magento 2.3.1 but after upgrade to Magento version 2.4.0, It's showing me an error when I sending an email from custom code. Below is the code sample.

 $templateOptions = array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $options[$customer->getWebsiteId()]);


        $templateVars = array(
            'store' => $store->getWebsite($customer->getWebsiteId())->getName(),
            'email' => $customer->getEmail(),
            'name' => $customer->getFirstname() . ' ' . $customer->getLastname(),
            'newGroup' => $newGroupName,
            'oldGroup' => $oldGroupName,
            'logo_alt' => $logo['logo_alt'],
            'logo_width' => $logo['logo_width'],
            'logo_height' => $logo['logo_height'],
            'support_email' => $sender['email'],
            'support_phone' => $phone,
            'logo_url' => $store->getStore()->getBaseUrl(
                    \Magento\Framework\UrlInterface::URL_TYPE_MEDIA
                ) . 'email/logo/' . $logo['logo'],
        );

        $from = array('email' => $storeEmail, 'name' => $storeName);
        $to = array($customer->getEmail());

        $transport = $transportBuilder->setTemplateIdentifier('customer_change_group_email_template')
            ->setTemplateOptions($templateOptions)
            ->setTemplateVars($templateVars)
            ->setFrom($from)
            ->addTo($to)
            ->getTransport();
        $transport->sendMessage();

Below is the Magento 2 Warning:

Illegal string offset 'frontend_name' in /var/www/html/vendor/magento/module-email/Model/AbstractTemplate.php on line 465

I checked the above file for error and found below the line on 465, if I commented then it's working

if (!isset($variables['store']['frontend_name'])) {
            $variables['store']['frontend_name'] = $store->getFrontendName();
        } 

I don't know what is use of this code in email sending.

0

I have fixed this issue by change store as storename in param

$templateVars = array(
    'storeName' => $store->getWebsite($customer->getWebsiteId())->getName(),
    'email' => $customer->getEmail(),
    'name' => $customer->getFirstname() . ' ' . $customer->getLastname(),
    'logo_alt' => $logo['logo_alt'],
    'logo_width' => $logo['logo_width'],
    'logo_height' => $logo['logo_height'],
    'support_email' => $sender['email'],
    'support_phone' => $phone,
    'logo_url' => $store->getStore()->getBaseUrl(
            \Magento\Framework\UrlInterface::URL_TYPE_MEDIA
        ) . 'email/logo/' . $logo['logo'],
);
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.