Ergebnis 1 bis 1 von 1

Thema: Mehrere Attachments / PDFs einem Mail anhängen

  1. #1
    Contao-Nutzer
    Registriert seit
    15.03.2010.
    Ort
    AT
    Beiträge
    204

    Standard Mehrere Attachments / PDFs einem Mail anhängen

    Isotope: Mailanhang

    Wie hängt man richtig mehrere Attachments (Dokumente, PDFs, ...) einem Mail an?

    Meine Vorgehensweise, nach langem Suchen...

    PHP-Code:
    // config.php
    $GLOBALS['TL_HOOKS']['initializeSystem'][] = array('Hooks''myInitializeSystem');
    $GLOBALS['TL_HOOKS']['sendNotificationMessage'][] = array('Hooks''addAttachmentsToMail');

    // Hooks.php
    public function myInitializeSystem( )
    {
        
    /**
         * Attachment-Token für alle Notifications hinzufügen
         */
        
    foreach( $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE'] as $x=>$y ) {
            foreach( 
    $y as $z=>$h ) {
                
    $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE'][$x][$z]['email_text'][] = 'file1_document';
                
    $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE'][$x][$z]['email_html'][] = 'file1_document';
                
    $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE'][$x][$z]['email_text'][] = 'file2_document';
                
    $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE'][$x][$z]['email_html'][] = 'file2_document';
                
    $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE'][$x][$z]['attachment_tokens'][] = 'file1_attachment';
                
    $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE'][$x][$z]['attachment_tokens'][] = 'file2_attachment';
            }
        }
    }


    public function 
    addAttachmentsToMail($objMessage, &$arrTokens$language$objGatewayModel)
    {
        
    $objGateway $objGatewayModel->getGateway();
        if (
    $objGateway instanceof Email) {
        
            
    /*
             * only if order is paid
             */
             
            
    $objOrder Order::findById($arrTokens['order_id']);
            if (! 
    $objOrder->isPaid()) {
                return 
    true#  muss true sein, damit der weitere Programmablauf nicht abgebrochen wird.
            
    }
            
            
    /*
            * Create File dynamicaly or load from somewhere,...
            */
            
            
    $filepath1 "/files/somewhere/file1.pdf";
            
    $filepath2 "/files/somewhere/file2.docx";
            
            
    $arrTokens['file1_document'] =  $filepath1;
            
    $arrTokens['file1_attachment'] = basename($filepath1);
            
            
    $arrTokens['file2_document'] =  $filepath2;
            
    $arrTokens['file2_attachment'] = basename($filepath2);
        
        }
        
        return 
    true;


    BACKEND
    Im Backend müssen diese Attachments beim jeweiligen Benachrichtigung unter "Dateianhänge via Tokens" eingefügt werden.
    Bsp: ##document##,##file1_attachment##,##file2_attachme nt##
    Geändert von heyho (19.05.2022 um 08:17 Uhr)

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

Lesezeichen

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •