init
This commit is contained in:
parent
7428ff8b8f
commit
9b15ac9fd3
87 changed files with 4975 additions and 1 deletions
50
src/app.php
Normal file
50
src/app.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
namespace app;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
class app
|
||||
{
|
||||
public static $db;
|
||||
public static function init_db()
|
||||
{
|
||||
try {
|
||||
self::$db = new \PDO('sqlite:../' . $_ENV['SQLITE_DB']);
|
||||
self::$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
} catch (\PDOException $e) {
|
||||
die("Database error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
public static function send_mail($to, $from, $from_name, $subject, $message, $HTML_message)
|
||||
{
|
||||
$mail = new PHPMailer(exceptions: true);
|
||||
//Server settings
|
||||
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $_ENV['SMTP_HOST'];
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $_ENV['SMTP_USER'];
|
||||
$mail->Password = $_ENV['SMTP_PASS'];
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$mail->Port = 587;
|
||||
$mail->isHTML(true);
|
||||
$mail->setFrom($from, $from_name);
|
||||
$mail->addAddress(address: $to);
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $HTML_message;
|
||||
$mail->AltBody = $message;
|
||||
|
||||
// Buffer the output
|
||||
ob_start();
|
||||
$mail->send();
|
||||
ob_end_clean();
|
||||
}
|
||||
public static function sendJson($data, $status = 200)
|
||||
{
|
||||
http_response_code($status);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data);
|
||||
exit;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue