Repository navigation
Expand file tree
/
Copy pathsend_email.php
More file actions
91 lines (75 loc) · 3.21 KB
/
Copy pathsend_email.php
File metadata and controls
91 lines (75 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* Name: send_email.php
* Author: Roger C. Guilherme
* Created: 2026-07-01
* Description: This file is part of the ODDS plugin for the ABCD application. It handles sending email notifications based on user actions within the plugin. The script reads SMTP configuration from a secure file, processes incoming requests, and sends emails accordingly. It ensures that only authenticated users can trigger email sending and provides feedback on the success or failure of the operation.
*
* * @package ABCD_Plugins_ODDS
* @requires PHP 8.1+
*
* changelog:
* 20260701 rogercgui Initial creation of LanguageManager class.
*
* */
if (!class_exists('PluginBridge')) {
header("HTTP/1.1 403 Forbidden");
die("Direct access forbidden.");
}
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// Verifica se é um bibliotecário/admin logado no ABCD
if (!isset($_SESSION['permiso'])) {
header("HTTP/1.1 403 Forbidden");
die("<b><font color='red'>Access Denied: Authentication required.</font></b>");
}
require_once __DIR__ . '/OddsMailer.php';
$bridge = PluginBridge::getInstance();
$lang = $bridge->get('lang', 'en');
// 1. Carregamos o seu arquivo seguro de configurações SMTP
$smtpConfigFile = __DIR__ . '/config/smtp.php';
if (!file_exists($smtpConfigFile)) {
die("<b><font color='red'>Error: SMTP configuration file not found.</font></b>");
}
$smtpConfig = require $smtpConfigFile;
try {
// 2. Recebendo os dados da requisição (Vindos do clique do Bibliotecário)
$status = trim($_REQUEST['status'] ?? '');
$email = trim($_REQUEST['email'] ?? '');
if (empty($email)) {
throw new Exception("E-mail address missing");
}
if ($status === '2') {
// 3. Montagem correta dos arrays de dados que estavam faltando
$requestData = [
'title' => trim(str_replace("/", " ", $_REQUEST['title'] ?? '')),
'name' => $_REQUEST['name'] ?? '',
'date' => $_REQUEST['fecha'] ?? '',
'notes' => $_REQUEST['notes'] ?? ''
];
// Formato legado usava pipe '|' para separar arquivos múltiplos
$rawFiles = $_REQUEST['uploadFiles'] ?? '';
$uploadedFiles = empty($rawFiles) ? [] : explode('|', $rawFiles);
// 4. Instanciamos o Mailer com as credenciais do seu smtp.php
$mailer = new OddsMailer(
$smtpConfig['host'],
$smtpConfig['port'],
$smtpConfig['username'],
$smtpConfig['password'],
$smtpConfig['from_email'],
$smtpConfig['from_name']
);
// 5. Dispara a notificação
$result = $mailer->sendDeliveryNotification($email, $lang, $requestData, $uploadedFiles);
if ($result) {
echo "<b><font face='Verdana' size='2' color='#3669c6'>Email successfully sent to: {$email}</font></b>";
} else {
echo "<b><font face='Verdana' size='2' color='red'>Failed to send email. Check logs.</font></b>";
}
} else {
echo "<b><font face='Verdana' size='2'>Status not configured for automatic email.</font></b>";
}
} catch (Exception $e) {
echo "<b><font face='Verdana' size='2' color='red'>Error: " . htmlspecialchars($e->getMessage()) . "</font></b>";
}