0

How to debug following code.

$transport = $this->transportBuilder
                ->setTemplateIdentifier($emailTemplate)
                ->setTemplateOptions(
                    [
                        'area' => 'adminhtml',
                        'store' => $this->storeManager->getStore()->getId()
                    ]
                )
                ->setTemplateVars($variables)
                ->setFrom($emailSender)
                ->addTo($emailRecipient)
                ->setReplyTo($replyTo, $replyToName)
                ->getTransport();

It is getting failed without any error or exception message.

6

1 Answer 1

0

Issue was with class vendor/magento/module-email/Model/Template/SenderResolver.php

public function resolve($sender, $scopeId = null)
    {
        $result = [];

        if (!is_array($sender)) {
            $result['name'] = $this->_scopeConfig->getValue(
                'trans_email/ident_' . $sender . '/name',
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
                $scopeId
            );
            $result['email'] = $this->_scopeConfig->getValue(
                'trans_email/ident_' . $sender . '/email',
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
                $scopeId
            );
        } else {
            $result = $sender;
        }

        if (!isset($result['name']) || !isset($result['email'])) {
            throw new \Magento\Framework\Exception\MailException(__('Invalid sender data'));
        }

        return $result;
    }

I am passing the string in setFrom which is creating the problem.
Fixed it by passing the array.
Changed

setFrom($emailSender)

to

setFrom(['email'=> $emailSender, 'name'=> $senderName])

Your Answer

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

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