This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
filespread/res/php/sendmail.php

54 lines
1.1 KiB
PHP
Executable File

<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
$ini = pParse_ini_file("../../filespread.ini");
date_default_timezone_set($ini["timezone"]);
require '../../vendor/autoload.php';
$list = "../../lists/" . $_GET["list"];
$template = "../../templates/" . $_GET["template"];
$addresses = file($list);
$content = file($template);
$email = new PHPMailer;
$email->setFrom($ini["email"], $ini["name"]);
$email->Subject = parseSubject($content);
$email->Body = parseText($content);
foreach ($addresses as $address) {
$email->AddAddress($address);
}
$file_to_attach = '../../assets/file.bin';
$filename = parseFilename($content);
$email->AddAttachment($file_to_attach, $filename);
if (!$email->Send()) {
echo "-1";
echo $email->ErrorInfo;
} else {
echo "0";
}
function parseSubject($content) {
return substr($content[0], 7);
}
function parseFilename($content) {
return substr($content[1], 10);
}
function parseText($content) {
$text = substr($content[2], 6);
for ($i = 3; $i < count($content); $i++) {
$text = $text . $content[$i];
}
return $text;
}