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
Raw Normal View History

2016-04-06 17:30:05 +02:00
<?php
# COPYRIGHT (c) 2016 Marcel Kapfer (mmk2410)
# MIT License
2016-11-12 17:46:40 +01:00
$ini = parse_ini_file("../../filespread.ini");
2016-04-06 17:30:05 +02:00
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;
}