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##
Lesezeichen