1

I am implemented functionality to change store info in email templates, for that I have created plugin

public function aroundSendMessage(\Magento\Framework\Mail\TransportInterface $subject, \Closure $proceed){

        $message = $subject->getMessage();
        $body= str_replace("post@example.com","hello@hello.com", $message->getBody());
        $message->setBody($body);
        $message->setReplyTo("heelo@heelo.hff");
        try {
            $proceed();
        } catch (\Exception $e) {
            throw new \Magento\Framework\Exception\MailException(new \Magento\Framework\Phrase($e->getMessage()), $e);
        }
}

But am getting below error

Recoverable Error: Object of class Zend_Mime_Part could not be converted to string

  • $message->getBody() does not always return a string – Philipp Sander Feb 19 at 12:00
  • How can I replace my string in $message->getBody() – Daniel_12 Feb 19 at 12:04
  • try $message->getBody(true) – Philipp Sander Feb 19 at 12:11
0

$message->getBody() does not always return a string

try $message->getBodyText(true)

This will force htmlOutput

  • no still same error – Daniel_12 Feb 19 at 12:16
  • @Daniel_12 sorry. see updated answer – Philipp Sander Feb 19 at 12:19
  • Now I dnt get the error but my email body is empty :( – Daniel_12 Feb 19 at 12:24

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.