Path in the Gestor bibliotecas/comunicacao.php
Every e-mail the Gestor sends (sign-up, password recovery, 2FA, forms) goes through comunicacao_email(), which uses the PHPMailer bundled in gestor/bibliotecas/PHPMailer/. The library also has comunicacao_impressao().
Configuration
From the .env (global variables): EMAIL_ACTIVE, EMAIL_HOST, EMAIL_USER, EMAIL_PASS, EMAIL_PORT, EMAIL_SECURE, EMAIL_FROM(_NAME) and EMAIL_REPLY_TO(_NAME). With EMAIL_ACTIVE=false, comunicacao_email() does not send and returns false.
Sending
gestor_incluir_biblioteca('comunicacao');
$ok = comunicacao_email([
'destinatarios' => [
['email' => 'ana@example.com', 'nome' => 'Ana'],
['email' => 'archive@example.com', 'tipo' => 'bcc'],
],
'mensagem' => [
'assunto' => 'Order received',
'html' => '<p>Hello, #name#!</p>',
'htmlVariaveis' => [['variavel' => '#name#', 'valor' => htmlspecialchars($name)]],
'htmlAssinaturaAutomatica' => true,
'anexos' => [['caminho' => '/tmp/order.pdf', 'nome' => 'order.pdf', 'tmpCaminho' => '/tmp/order.pdf']],
],
]);| Parameter | |
|---|---|
destinatarios[] |
email, nome and tipo (cc, bcc or empty for a regular recipient) |
mensagem.assunto / html |
Subject and HTML body |
mensagem.htmlTitulo |
The e-mail <title> (default: the subject) |
mensagem.htmlVariaveis |
List of ['variavel', 'valor'] replaced in the final HTML (unescaped) |
mensagem.htmlLayoutID |
Id of a component that replaces html as the body |
mensagem.htmlAssinaturaAutomatica |
Appends the layout-emails-assinatura component |
mensagem.htmlCompleto |
Ready HTML: skips the layout |
mensagem.anexos[] |
caminho, nome, tmpCaminho (deleted after sending) |
mensagem.imagens[] |
caminho, cid, nome, imagemTmpCaminho: embedded images, referenced in the HTML with cid: |
remetente |
de, deNome, responderPara, responderParaNome: override the .env |
servidor |
hospedeiro, usuario, senha, porta, seguro, debug: override the .env |
EMAIL_TESTS + EMAIL_* |
Test send with credentials passed on the spot, even with e-mail turned off (what admin-environment uses) |
The layout
Without htmlCompleto, the body goes into the layout-emails layout: its CSS goes into a <style>, and the <!-- mail#titulo -->, <!-- mail#css --> and <!-- mail#corpo --> markers are replaced. Then come the htmlVariaveis and the global variables (@[[…]]@). To change the look of every e-mail of the site, edit that layout. The alternative text (no HTML) is hard-coded in Portuguese.
Return value and errors
It returns true if the server accepted the message and false in any other case: e-mail off, connection error, invalid recipient. The reason goes to gestor/logs/email-<date>.log (or, with debug, to the historico table).
Printing
comunicacao_impressao(['pagina' => $html, 'titulo' => …]) stores the HTML in the session (impressao) for the print page to display it ready to print (the impressao option, handled in gestor/modulos/global.php; without data, it shows the impressao-sem-dados component).
Functions
Generated from gestor/bibliotecas/comunicacao.php · 2 functions
comunicacao_impressao
view source · line 50 ↗comunicacao_impressao(array|false $params = false): voidPrepara página para impressão armazenando dados na sessão.
Parameters
$paramsarray|false- Parâmetros da função.
Returns
comunicacao_email
view source · line 137 ↗comunicacao_email(array|false $params = false): bool|stringEnvia emails via SMTP usando PHPMailer.
Parameters
$paramsarray|false- Parâmetros da função.
Returns