114 lines
4.4 KiB
PHP
114 lines
4.4 KiB
PHP
<?php
|
|
ini_set('include_path', '../_class/');
|
|
|
|
include '../_class/class_user_parent.php';
|
|
foreach (glob("../_class/*.php") as $filename) {
|
|
//echo $filename;
|
|
$skip = array(
|
|
'../_class/class_user_parent.php',
|
|
'../_class/class_Exception.php',
|
|
);
|
|
if (in_array($filename, $skip))
|
|
continue;
|
|
|
|
include $filename;
|
|
}
|
|
|
|
|
|
/*
|
|
foreach ($_POST as $key => $value) {
|
|
trigger_error($_SERVER['HTTP_HOST'], E_USER_NOTICE);
|
|
}
|
|
*/
|
|
include('../_include/include_db_conn.php');
|
|
|
|
if (empty($_POST['uk_id'])) {
|
|
echo json_encode(null);
|
|
} else {
|
|
$toNotify = new user_kid();
|
|
$toNotify->set_user_data_by_id($_POST['uk_id']);
|
|
|
|
if (null === $toNotify->get_uk_parent_1()->get_up_email() || null === $toNotify->get_uk_parent_1()->get_up_name()) {
|
|
echo json_encode('missing-data');
|
|
} else {
|
|
$email_template_id = $sql->single_variable('select et_id from email_template where et_name = \'below_zero\'');
|
|
if (null !== $email_template_id) {
|
|
$emailTemplate = new email_template();
|
|
$emailTemplate->set_et_data_by_id($email_template_id);
|
|
|
|
$raw_subject = $emailTemplate->get_et_subject();
|
|
$raw_message = $emailTemplate->get_et_message();
|
|
//var_dump($toNotify_array);
|
|
//foreach ($toNotify_array as $toNotify) {
|
|
$personalizedSubject = $emailTemplate->personalize($raw_subject, array(
|
|
'uk_name' => $toNotify->get_uk_name(),
|
|
));
|
|
|
|
$personalizedMessage = $emailTemplate->personalize($raw_message, array(
|
|
'notify_name' => $toNotify->get_uk_parent_1()->get_up_name(),
|
|
'uk_name' => $toNotify->get_uk_name(),
|
|
));
|
|
|
|
$mail = new PHPMailer(true); // Passing `true` enables exceptions
|
|
try {
|
|
//Server settings
|
|
$mail->SMTPDebug = 4; // Enable verbose debug output
|
|
$mail->isSMTP(); // Set mailer to use SMTP
|
|
$mail->CharSet = PHPMailer::CHARSET_UTF8; // UTF-8
|
|
$mail->Host = 'mail.livingsport.hu'; // Specify main and backup SMTP servers
|
|
$mail->SMTPAuth = true; // Enable SMTP authentication
|
|
$mail->Username = 'notify@livingsport.hu'; // SMTP username
|
|
$mail->Password = 'dpDiKSqU0V'; // SMTP password
|
|
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
|
|
$mail->Port = 465;
|
|
|
|
//Recipients
|
|
$mail->setFrom($emailTemplate->get_et_from_email(), $emailTemplate->get_et_from_name());
|
|
// $mail->addAddress($toNotify->get_uk_parent_1()->get_up_email(), $toNotify->get_uk_parent_1()->get_up_name());
|
|
$mail->addAddress('tricsusz@gmail.com', 'Tóth Richárd'); // TEST
|
|
|
|
|
|
//Content
|
|
$mail->isHTML(true); // Set email format to HTML
|
|
$mail->Subject = $personalizedSubject;
|
|
$mail->Body = $personalizedMessage;
|
|
$mail->AltBody = 'Az Ön levelezője nem támogatja a HTML tartalom megjelenítését!';
|
|
|
|
//send mail
|
|
$mail->send();
|
|
//LOG SUCCESS
|
|
email_log::create_email_log(
|
|
$personalizedMessage,
|
|
$personalizedSubject,
|
|
$toNotify->get_uk_parent_1()->get_up_name(),
|
|
$toNotify->get_uk_parent_1()->get_up_email(),
|
|
$emailTemplate->get_et_id()
|
|
);
|
|
|
|
//Update kids last noti date
|
|
$sql->update_table('user_kid', array('uk_last_notification' => date('Y-m-d H:i:s')), array('uk_id' => $toNotify->get_uk_id()));
|
|
|
|
echo json_encode('success');
|
|
|
|
} catch (Exception $e) {
|
|
//LOG ERROR
|
|
email_log::create_email_log(
|
|
$personalizedMessage,
|
|
$personalizedSubject,
|
|
$toNotify->get_uk_parent_1()->get_up_name(),
|
|
$toNotify->get_uk_parent_1()->get_up_email(),
|
|
$emailTemplate->get_et_id(),
|
|
mysql_escape_string($e)
|
|
);
|
|
|
|
echo json_encode(null);
|
|
}
|
|
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|
|
|