This example shows how to send report via Email. First, you need to add the Stimulsoft libraries and scripts, required for the component to work. All code should be added in the <head> block of the HTML page:
<?php
require_once 'vendor/autoload.php';
?>

...

<?php
$js = new \Stimulsoft\StiJavaScript(\Stimulsoft\StiComponentType::Viewer);
$js->renderHtml();
?>

Next, in the <script> block, create and configure an event handler:
<script type="text/javascript">
<?php
$handler = new \Stimulsoft\StiHandler();
$handler->renderHtml();

Next, create the viewer with the necessary options and define the onEmailReport event. If value set to true, this event will be passed to the server-side event handler:
$options = new \Stimulsoft\Viewer\StiViewerOptions();
$options->appearance->fullScreenMode = true;
$options->toolbar->showSendEmailButton = true;

$viewer = new \Stimulsoft\Viewer\StiViewer($options);
$viewer->onEmailReport = true;

Next, create and load a report. The loadFile() method does not load the report object on the server side, it only generates the necessary JavaScript code. The report will be loaded into a JavaScript object on the client side:
$report = new \Stimulsoft\Report\StiReport();
$report->loadFile('reports/SimpleList.mrt');
$viewer->report = $report;
?>

Next, render the necessary JavaScript code and visual HTML part of the component, and close the </script> block. The rendered code will be placed inside the specified HTML element:
function onLoad() {
	<?php
	$viewer->renderHtml('viewerContent');
	?>
}
</script>

...

<body onload="onLoad();">
<div id="viewerContent"></div>
</body>

Finally, you need to fill your Email account options on the server-side in the onEmailReport() method, they will not be passed to the client side. By default, all server-side events are located in the handler.php file:
$handler->onEmailReport = function ($args)
{
    $args->emailSettings->from = '*****@gmail.com';
    $args->emailSettings->host = 'smtp.google.com';
    $args->emailSettings->login = '*****';
    $args->emailSettings->password = '*****';

    // These parameters are optional
    //$args->emailSettings->name = 'John Smith';
    //$args->emailSettings->port = 465;
    //$args->emailSettings->cc[] = 'copy1@gmail.com';
    //$args->emailSettings->bcc[] = 'copy2@gmail.com';
    //$args->emailSettings->bcc[] = 'copy3@gmail.com John Smith';

    return StiResult::success('Email sent successfully.');
};

На скриншоте ниже Вы можете увидеть результат выполнения данного кода:

Sending a Report by Email

Используя этот сайт, вы соглашаетесь на использование файлов Cookie для аналитики и персонализированного контента. Файлы Cookie хранят полезную информацию на вашем компьютере, чтобы помочь нам повысить эффективность и удобство использования. Для получения дополнительной информации, пожалуйста, прочтите Конфиденциальность и Использование Cookie.