Files

54 lines
1.8 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// ============================================================
// ODESÍLÁNÍ EMAILŮ
// ============================================================
// Tento soubor obsahuje pomocnou funkci odesli_mail(), kterou
// používají ostatní soubory systému (reset_hesla.php, admin.php).
//
// Funkce odesílá email přes PHP mail(), které je dostupné
// na všech běžných webhostinzích bez dalších závislostí.
// ============================================================
if (!defined('DB_HOST')) {
require_once __DIR__ . '/config.php';
}
/**
* Odešle email.
*
* @param string $komu Emailová adresa příjemce
* @param string $predmet Předmět emailu
* @param string $text Tělo emailu (prostý text)
* @return bool true pokud mail() hlásí úspěch, jinak false
*/
function odesli_mail(string $komu, string $predmet, string $text): bool
{
// Sestavíme hlavičky emailu
// Kódování UTF-8 zajistí správné zobrazení diakritiky
$hlavicky = 'MIME-Version: 1.0' . "\r\n";
$hlavicky .= 'Content-Type: text/plain; charset=UTF-8' . "\r\n";
$hlavicky .= 'Content-Transfer-Encoding: 8bit' . "\r\n";
$hlavicky .= 'From: ' . MAIL_ODESILATEL_JMENO
. ' <' . MAIL_ODESILATEL . '>' . "\r\n";
// Předmět s diakritikou musíme zakódovat do base64
// (standard RFC 2047 pro non-ASCII znaky v hlavičkách emailu)
$predmet_encoded = '=?UTF-8?B?' . base64_encode($predmet) . '?=';
// Odeslání přes PHP mail()
// Čtvrtý parametr "-f" nastavuje envelope-from adresu
// pomáhá předcházet označení emailu jako spam
$vysledek = mail(
$komu,
$predmet_encoded,
$text,
$hlavicky,
'-f ' . MAIL_ODESILATEL
);
if (!$vysledek) {
error_log('Nepodařilo se odeslat email na: ' . $komu);
}
return $vysledek;
}