plateforme-tfjm2/server_files/services/mail.php

82 lines
2.9 KiB
PHP
Raw Normal View History

<?php
function sendMail($email, $subject, $content, $from = "contact")
{
global $MAIL_DOMAIN, $URL_BASE, $YEAR;
$content = preg_replace("#{URL_BASE}#", $URL_BASE, $content);
$content = preg_replace("#{YEAR}#", $YEAR, $content);
$headers = "From: " . $from . "@" . $MAIL_DOMAIN . "\r\n";
$headers .= "Reply-To: contact@" . $MAIL_DOMAIN . "\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
mail($email, $subject, $content, $headers);
}
/**
* @param NewUser
*/
function sendRegisterMail($new_user)
{
global $LOCAL_PATH, $YEAR;
$content = file_get_contents("$LOCAL_PATH/server_files/services/mail_templates/register.html");
$content = preg_replace("#{FIRST_NAME}#", $new_user->first_name, $content);
$content = preg_replace("#{SURNAME}#", $new_user->surname, $content);
$content = preg_replace("#{TOKEN}#", $new_user->confirm_email_token, $content);
sendMail($new_user->email, "Inscription au TFJM² $YEAR", $content);
}
/**
* @param $user User
* @param $team Team
* @param $tournament Tournament
*/
2019-09-07 15:26:30 +00:00
function sendAddTeamMail($user, $team, $tournament)
{
global $LOCAL_PATH, $YEAR;
$content = file_get_contents("$LOCAL_PATH/server_files/services/mail_templates/add_team.html");
$content = preg_replace("#{FIRST_NAME}#", $user->getFirstName(), $content);
$content = preg_replace("#{SURNAME}#", $user->getSurname(), $content);
$content = preg_replace("#{TEAM_NAME}#", $team->getName(), $content);
$content = preg_replace("#{TRIGRAM}#", $team->getTrigram(), $content);
$content = preg_replace("#{TOURNAMENT_NAME}#", $tournament->getName(), $content);
$content = preg_replace("#{ACCESS_CODE}#", $team->getAccessCode(), $content);
2019-09-07 15:26:30 +00:00
sendMail($user->getEmail(), "Ajout d'une équipe TFJM² $YEAR", $content);
}
/**
* @param NewUser
*/
function sendAddOrganizerMail($new_orga)
{
global $LOCAL_PATH, $YEAR;
$content = file_get_contents("$LOCAL_PATH/server_files/services/mail_templates/add_organizer.html");
$content = preg_replace("#{FIRST_NAME}#", $new_orga->first_name, $content);
$content = preg_replace("#{SURNAME}#", $new_orga->surname, $content);
$content = preg_replace("#{PASSWORD}#", $new_orga->password, $content);
sendMail($new_orga->email, "Ajout d'un organisateur -- TFJM² $YEAR", $content);
}
/**
* @param $organizer User
* @param $tournament Tournament
*/
function sendAddOrganizerForTournamentMail($organizer, $tournament)
{
global $LOCAL_PATH, $YEAR;
$content = file_get_contents("$LOCAL_PATH/server_files/services/mail_templates/add_organizer_for_tournament.html");
$content = preg_replace("#{FIRST_NAME}#", $organizer->getFirstName(), $content);
$content = preg_replace("#{SURNAME}#", $organizer->getSurname(), $content);
$content = preg_replace("#{TOURNAMENT_NAME}#", $tournament->getName(), $content);
sendMail($organizer->getEmail(), "Ajout d'un organisateur pour le tournoi " . $tournament->getName() . "-- TFJM² $YEAR", $content);
2019-09-07 15:26:30 +00:00
}