Something went wrong. Try again.
Element Exporter makes exporting data from your Craft CMS website easy and repeatable, with events for custom data parsing and elements.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546<?php
namespace studioespresso\exporter\services;
use Craft;use craft\base\Component;use craft\mail\Message;use craft\web\View;use studioespresso\exporter\elements\ExportElement;use studioespresso\exporter\Exporter;use studioespresso\exporter\models\Settings;
class MailService extends Component{ public function send(ExportElement $export, $path): bool { $exportSettings = $export->getSettings(); /* @var Settings $pluginSettings */ $pluginSettings = Exporter::getInstance()->getSettings(); if ($pluginSettings->emailTemplate) { $html = Craft::$app->getView()->renderTemplate( $pluginSettings->emailTemplate, [], View::TEMPLATE_MODE_SITE ); } else { $html = Craft::$app->getView()->renderTemplate( "exporter/_mail/template", [], View::TEMPLATE_MODE_CP ); }
$message = new Message();
$name = $exportSettings['fileName'] ?? "Export"; $fileName = "{$name}.{$exportSettings['fileType']}"; $message->attach($path, ['fileName' => $fileName, 'contentType' => "application/{$exportSettings['fileType']}"]); $message->setSubject($exportSettings['emailSubject'] ?? 'Your export'); $message->setTo($exportSettings['email']); $message->setHtmlBody($html);
return Craft::$app->getMailer()->send($message); }}