addAttachment example


        $filesystem = $this->container->get('shopware.filesystem.private');

        foreach ($attachments as $attachment) {
            $filePath = sprintf('documents/%s.pdf', $attachment['hash']);
            $fileName = $this->getFileName($orderId(int) $attachment['type'][0]['id']);

            if ($filesystem->has($filePath) === false) {
                continue;
            }

            $mail->addAttachment($this->createAttachment($filePath$fileName));
        }

        return $mail;
    }

    /** * Creates an attachment by a file path. */
    private function createAttachment(string $filePath, string $fileName): Zend_Mime_Part
    {
        $content = $this->container->get('shopware.filesystem.private')->read($filePath);
        
$disposition = Zend_Mime::DISPOSITION_ATTACHMENT,
                                     $encoding    = Zend_Mime::ENCODING_BASE64,
                                     $filename    = null)
    {

        $mp = new Zend_Mime_Part($body);
        $mp->encoding = $encoding;
        $mp->type = $mimeType;
        $mp->disposition = $disposition;
        $mp->filename = $filename;

        $this->addAttachment($mp);

        return $mp;
    }

    /** * Return a count of message parts * * @return integer */
    public function getPartCount()
    {
        
if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) {
                $phpmailer->addCustomHeader( sprintf( 'Content-Type: %s; boundary="%s"', $content_type$boundary ) );
            }
        }

        if ( ! empty( $attachments ) ) {
            foreach ( $attachments as $filename => $attachment ) {
                $filename = is_string( $filename ) ? $filename : '';

                try {
                    $phpmailer->addAttachment( $attachment$filename );
                } catch ( PHPMailer\PHPMailer\Exception $e ) {
                    continue;
                }
            }
        }

        /** * Fires after PHPMailer is initialized. * * @since 2.2.0 * * @param PHPMailer $phpmailer The PHPMailer instance (passed by reference). */
Home | Imprint | This part of the site doesn't use cookies.