4

I put that function on the transpotbuilder file in core file , but it has still error:

Fatal error: Class 'Magento\Framework\Mail\Template\Zend_Mime' not found in /var/www/html/vendor/magento/framework/Mail/Template

 public function addAttachment(
    $body,
    $mimeType    = Zend_Mime::TYPE_OCTETSTREAM,
    $disposition = Zend_Mime::DISPOSITION_ATTACHMENT,
    $encoding    = Zend_Mime::ENCODING_BASE64,
    $filename    = null
) {
    $this->message->createAttachment($body, $mimeType, $disposition, $encoding, $filename);
    return $this;
}

I added this function in core file and try to send attachment email and I got the Above error.

3 Answers 3

3

You need to add prefix slash() before zend_mime.

Clear var/generation folder and check,

 public function addAttachment(
    $body,
    $mimeType    = \Zend_Mime::TYPE_OCTETSTREAM,
    $disposition = \Zend_Mime::DISPOSITION_ATTACHMENT,
    $encoding    = \Zend_Mime::ENCODING_BASE64,
    $filename    = null
) {
    $this->message->createAttachment($body, $mimeType, $disposition, $encoding, $filename);
    return $this;
}

There are not any class related to

'Magento\Framework\Mail\Template\Zend_Mime.php

When you use prefix \ before the class they will route to Mime.php file from path vendor/magento/zendframework1/library/Zend/Mime.php

0
1
    class TransportBuilder extends \Magento\Framework\Mail\Template\TransportBuilder
{

    const TYPE_OCTETSTREAM         = 'application/octet-stream';
    const DISPOSITION_ATTACHMENT   = 'attachment';
    const ENCODING_BASE64          = 'base64';

    public function addAttachment(
        $body,
        $mimeType    = self::TYPE_OCTETSTREAM,
        $disposition = self::DISPOSITION_ATTACHMENT,
        $encoding    = self::ENCODING_BASE64,
        $filename    = null
    ) {
        $this->message->createAttachment($body, $mimeType, $disposition, $encoding, $filename);
        return $this;
    }
}

Use like this then you can resolve this issue.

Reference: vendor/magento/zendframework1/library/Zend/Mime.php

1

Try

composer require zendframework/zend-mime
0

Your Answer

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

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