This repository has been archived on 2024-07-18. You can view files and clone it, but cannot push or open issues or pull requests.
lwb5/scripts/game/main/library/sendMail.inc

49 lines
1.1 KiB
PHP
Raw Normal View History

2016-01-10 11:01:49 +01:00
<?php
class main_sendMail {
function main_sendMail($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
function run($file, $to, $vars) {
if (! config::$main['sendmails']) {
return true;
}
// Read the file
$mail = @file_get_contents("{$this->lib->game->dir}/mail/$file");
if (is_bool($mail)) {
logText("Mail '$file' to $to failed: file not found", LOG_WARNING);
return false;
}
// Generate the substitution arrays from the variables
$vals = array_values($vars);
$subst = array();
foreach (array_keys($vars) as $name) {
array_push($subst, "/_{$name}_/");
}
$mail = preg_replace($subst, $vals, $mail);
$tmp = explode("\n", $mail);
$subject = array_shift($tmp);
$mail = join("\n", $tmp);
$header = "From: webmaster@legacyworlds.com\r\n"
. "Reply-To: webmaster@legacyworlds.com\r\n"
. "X-Mailer: LegacyWorlds\r\n"
. "Mime-Version: 1.0\r\n"
. "Content-Type: text/plain; charset=iso-8859-1";
if (!mail($to, $subject, $mail, $header)) {
logText("Mail '$file' to $to failed: unable to send", LOG_WARNING);
return false;
}
return true;
}
}
?>