TemplateMail example



        $job = $args->getJob();

        $context = [
            'sData' => $data,
            'sJob' => [
                'articles' => $articles,
            ],
        ];

        $mail = Shopware()->TemplateMail()->createMail(
            $job->get('inform_template'),
            $context
        );

        $informMail = $job->get('inform_mail');
        if ($job->get('inform_mail') === trim('{$sConfig.sMAIL}')) {
            $informMail = Shopware()->Config()->get('mail');
        }

        $mail->addTo($informMail);
        $mail->send();

        
$position['image_large'] = isset($thumbnails[1]) ? $thumbnails[1]['source'] : $position['image_original'];
            }

            unset($position);

            $context = [
                'sOrder' => $order,
                'sUser' => $customers[$orderId],
                'sArticles' => $orderPositions[$orderId],
            ];

            $mail = Shopware()->TemplateMail()->createMail('sARTICLECOMMENT', $context);
            $mail->addTo($customers[$orderId]['email']);
            $mail->send();
            ++$count;
        }

        if ($count <= 0) {
            return 'No rating mails sent.';
        }

        return $count . ' rating mail(s) sent.';
    }

    
if (!$this->Request()->getParam('value')) {
            $this->View()->assign(['success' => false, 'message' => 'Value not found']);
        }

        $recipient = Shopware()->Config()->get('mail');

        $shop = $this->get('models')->getRepository(Shop::class)->getActiveDefault();
        $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

        try {
            $templateMail = Shopware()->TemplateMail()->createMail($mailarray_merge($this->getDefaultMailContext($shop)$mail->getContext())$shop);
            $templateMail->addTo($recipient);
            $templateMail->setAssociation(AdministrativeMailFilter::ADMINISTRATIVE_MAIL, true);
            $templateMail->send();
        } catch (Exception $e) {
            $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);

            return;
        }

        $this->View()->assign(['success' => true]);
    }

    


        /* @var Connection $connection */
        $connection = $this->get(Connection::class);
        $customer = $connection->fetchAssociative($sql[$customerId]);
        $email = $customer['email'];
        $customer['attributes'] = $connection->fetchAssociative('SELECT * FROM s_user_attributes WHERE userID = ?', [$customerId]);

        $context['user'] = $customer;

        // Send mail         $mail = Shopware()->TemplateMail()->createMail('sCONFIRMPASSWORDCHANGE', $context);
        $mail->addTo($email);
        $mail->send();

        $this->invalidateExistingPasswordLinkHashes($customerId);

        // Add the hash to the optin table         $sql = "INSERT INTO `s_core_optin` (`type`, `datum`, `hash`, `data`) VALUES ('swPassword', NOW(), ?, ?)";
        $connection->executeStatement($sql[$hash$customerId]);

        return [];
    }

    
'sName' => $this->sSYSTEM->_POST['sName'],
                    'sArticle' => html_entity_decode($product['articleName']),
                    'sLink' => $product['linkDetails'],
                ];

                if ($this->sSYSTEM->_POST['sComment']) {
                    $context['sComment'] = strip_tags(html_entity_decode($this->sSYSTEM->_POST['sComment']));
                } else {
                    $context['sComment'] = '';
                }

                $mail = Shopware()->TemplateMail()->createMail('sTELLAFRIEND', $context, null, [
                    'fromMail' => $this->sSYSTEM->_POST['sMail'],
                    'fromName' => $this->sSYSTEM->_POST['sName'],
                ]);

                $mail->addTo($this->sSYSTEM->_POST['sRecipient']);
                $mail->send();

                $this->View()->assign('sSuccess', true);
                $url = $this->Front()->ensureRouter()->assemble(['controller' => 'tellafriend', 'action' => 'success']);
                $this->redirect($url);
            } else {
                
'number' => $product['ordernumber'],
            ]);

            $context = [
                'sNotifyData' => $notify,
                'sArticleLink' => $link,
                'sOrdernumber' => $notify['ordernumber'],
                'sData' => $job['data'],
                'product' => $productInformation,
            ];

            $mail = Shopware()->TemplateMail()->createMail('sARTICLEAVAILABLE', $context);
            $mail->addTo($notify['mail']);
            $mail->send();

            // Set notification to already sent             $conn->update(
                's_articles_notification',
                ['send' => 1],
                ['orderNumber' => $notify['ordernumber']]
            );
        }
    }
}
$context[$key] = $value;
        }

        if (\array_key_exists('password', $context)) {
            unset($context['password']);
        }

        if (\array_key_exists('passwordConfirmation', $context)) {
            unset($context['passwordConfirmation']);
        }

        $mail = Shopware()->TemplateMail()->createMail('sREGISTERCONFIRMATION', $context);
        $mail->addTo($email);

        $sendConfirmationEmail = $this->config->get('sSEND_CONFIRM_MAIL');
        if (!empty($sendConfirmationEmail)) {
            $mail->addBcc($this->config->get('sMAIL'));
        }

        $this->eventManager->notify(
            'Shopware_Modules_Admin_SaveRegisterSendConfirmation_BeforeSend',
            ['subject' => $this, 'mail' => $mail]
        );

        
foreach ($this->Request()->getPost() as $key => $value) {
            $context['sUser.' . $key] = $value;
            $context['sUser'][$key] = $value;
        }

        $context = Shopware()->Events()->filter('Shopware_Controllers_Frontend_Newsletter_sendMail_FilterVariables', $context[
            'template' => $template,
            'recipient' => $recipient,
            'optin' => $optin,
        ]);

        $mail = Shopware()->TemplateMail()->createMail($template$context);
        $mail->addTo($recipient);
        $mail->send();
    }

    /** * Returns whether or not the current request contains * a valid newsletter confirmation * * @return bool */
    protected function isConfirmed()
    {
                    $blogCommentModel = new CommentConfirm();
                    $blogCommentModel->setCreationDate(new DateTime('now'));
                    $blogCommentModel->setHash($hash);
                    $blogCommentModel->setData(serialize($this->Request()->getPost()));

                    $this->get('models')->persist($blogCommentModel);
                    $this->get('models')->flush();

                    $link = $this->Front()->ensureRouter()->assemble(['sViewport' => 'blog', 'action' => 'rating', 'blogArticle' => $blogArticleId, 'sConfirmation' => $hash]);

                    $context = ['sConfirmLink' => $link, 'sArticle' => ['title' => $blogArticleData['title']]];
                    $mail = Shopware()->TemplateMail()->createMail('sOPTINBLOGCOMMENT', $context);
                    $mail->addTo($this->Request()->getParam('eMail'));
                    $mail->send();
                } else {
                    // Save comment                     $commentData = $this->Request()->getPost();
                    $this->sSaveComment($commentData$blogArticleId);
                }
            } else {
                $this->View()->assign('sFormData', Shopware()->System()->_POST->toArray());
                $this->View()->assign('sErrorFlag', $sErrorFlag);
            }
        }


        $availableSerials = $this->getAvailableSerialsOfEsd($esdProduct['id']);

        if ((\count($availableSerials) <= $this->config->get('esdMinSerials')) || \count($availableSerials) <= $quantity) {
            // Not enough serial numbers anymore, inform merchant             $context = [
                'sArticleName' => $basketRow['articlename'],
                'sMail' => $this->sUserData['additional']['user']['email'] ?? null,
            ];

            $mail = Shopware()->TemplateMail()->createMail('sNOSERIALS', $context);

            if ($this->config->get('sESDMAIL')) {
                $mail->addTo($this->config->get('sESDMAIL'));
            } else {
                $mail->addTo($this->config->get('sMAIL'));
            }

            $mail->send();
        }

        // Check if enough serials are available, if not, an email has been sent, and we can return
return false;
        }

        return true;
    }

    /** * @param array<string, mixed> $data */
    private function sendSepaEmail(string $orderNumber, int $userId, array $data): void
    {
        $mail = Shopware()->TemplateMail()->createMail('sORDERSEPAAUTHORIZATION', [
            'paymentInstance' => [
                'firstName' => $data['firstname'],
                'lastName' => $data['lastname'],
                'orderNumber' => $orderNumber,
            ],
        ]);

        $customerEmail = (string) Shopware()->Models()->createQueryBuilder()
            ->select('customer.email')
            ->from(Customer::class, 'customer')
            ->where('customer.id = ?1')
            
$shopId = is_numeric($user['language']) ? $user['language'] : $user['subshopID'];
            $shop = $repository->getActiveById($shopId);
            $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

            // language subshopID             $context = [
                'sUser' => $user,
                'sVoucher' => $voucher,
                'sData' => $job['data'],
            ];

            $mail = Shopware()->TemplateMail()->createMail('sBIRTHDAY', $context);
            $mail->addTo($user['email']);
            $mail->send();
        }

        return \count($users) . ' birthday email(s) with voucher was send.';
    }
}
        $orderModel = $this->get('models')->find(Order::class$orderId);
        if (!$orderModel instanceof Order) {
            $shop = $this->get('models')->getRepository(Shop::class)->getActiveDefault();
        } else {
            $shop = $orderModel->getLanguageSubShop();
        }

        $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

        // Try to send the actual mail         try {
            $mail = Shopware()->TemplateMail()->createMail($template$context$shop);
            $mail->addTo($mailTo);

            if ($orderModel !== null) {
                $mail->setAssociation(LogEntryBuilder::ORDER_ASSOCIATION, $orderModel);
            } else {
                $mail->setAssociation(LogEntryBuilder::ORDER_ID_ASSOCIATION, $orderId);
            }

            $mail->send();
        } catch (Exception $e) {
            $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);

            
Home | Imprint | This part of the site doesn't use cookies.