0

Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Magento\Framework\Mail\EmailMessage

$store = $this->_storeManager->getStore()->getId();
$transport = $this->_transportBuilder->setTemplateIdentifier('send_email_email_template')
    ->setTemplateOptions(['area' => 'frontend', 'store' => $store])
    ->setTemplateVars(
        [
            'store' => $this->_storeManager->getStore(),
        ]
    )
    ->setFrom('general')
    ->addTo(['name@gmail.com','name2@gmail.com'])
    ->getTransport();
$transport->sendMessage();

but on sending email to a single recipient

->addTo('test@gmail.com')

it sends without any load.

Magento Bug:

https://github.com/magento/magento2/issues/24984

0

I am using Magento ver. 2.3.3 and I found in https://github.com/magento/magento2/issues/24984 that it was bug, I tried to resolve it by my own.

private function addAddressByType(string $addressType, $email, ?string $name = null): void
{
    if (is_string($email)) {
        $this->messageData[$addressType][] = $this->addressConverter->convert($email, $name);
        return;
    }
    $convertedAddressArray = $this->addressConverter->convertMany($email);
    **$this->messageData[$addressType] = [];**
    if (isset($this->messageData[$addressType])) {
        $this->messageData[$addressType] = array_merge(
            $this->messageData[$addressType],
            $convertedAddressArray
        );
    }
}

I added $this->messageData[$addressType] = []; in my function as it was not compiling code in if condition, not sure if it is right approach to do but I can send email to multiple recipients now.

| 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.