send email on camp apply

This commit is contained in:
2021-04-20 15:39:41 +02:00
parent 515dfe52e8
commit a871a2f585
4 changed files with 259 additions and 0 deletions

View File

@@ -190,6 +190,53 @@ class camp_apply
{
global $sql;
$sql->update_table('camp_apply', ['capp_status' => $_status_id, 'capp_accept_date' => date('Y-m-d H:i:s')], ['capp_id' => $_apply_id]);
if (3 == $_status_id) {
$email_template_id = $sql->single_variable('select et_id from email_template where et_name = \'camp_reply\'');
if (null !== $email_template_id) {
$emailTemplate = new email_template();
$emailTemplate->set_et_data_by_id($email_template_id);
//felelős kapcstartó emailere küld
$contact = self::get_responsible_contact2($_apply_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, [
]);
$personalizedMessage = $emailTemplate->personalize($raw_message, [
]);
$mail = new PHPMailer(true); // Passing `true` enables exceptions
$mail->SMTPDebug = 0; // 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($contact->get_cc_email(), $contact->get_cc_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();
}
}
}
public static function has_contact($_capp_id)
@@ -231,6 +278,16 @@ class camp_apply
return $cc;
}
public static function get_responsible_contact2($_id)
{
global $sql;
$cc_id = $sql->single_variable('SELECT cac_camp_contact_cc_id FROM camp_apply_contact WHERE cac_camp_apply_capp_id = '.$_id.' AND cac_is_responsible = 1;');
$cc = new camp_contact();
$cc->set_cc_data_by_id($cc_id);
return $cc;
}
//egy létező jelentkezésnél felelős kapcsolattartóra állít valakit
public static function make_contact_responsible($_apply_id, $_cc_id, $_is_responsible = false)
{

View File

@@ -0,0 +1,200 @@
<?php
class email_template {
private $et_id;
private $et_name;
private $et_title;
private $et_deleted;
private $et_message;
private $et_subject;
private $et_from_name;
private $et_from_email;
public function set_et_data_by_id($_id) {
global $sql;
$et_data_assoc_array = $sql->assoc_array("select * from email_template where et_id = " . $_id);
$et_data_array = $et_data_assoc_array[0];
foreach ($et_data_array as $field => $value) {
$function_name = "set_" . $field;
$this->$function_name($value);
}
}
/**
* @return mixed
*/
public function get_et_id()
{
return $this->et_id;
}
/**
* @param mixed $et_id
*
* @return self
*/
public function set_et_id($et_id)
{
$this->et_id = $et_id;
return $this;
}
/**
* @return mixed
*/
public function get_et_name()
{
return $this->et_name;
}
/**
* @param mixed $et_name
*
* @return self
*/
public function set_et_name($et_name)
{
$this->et_name = $et_name;
return $this;
}
/**
* @return mixed
*/
public function get_et_title()
{
return $this->et_title;
}
/**
* @param mixed $et_title
*
* @return self
*/
public function set_et_title($et_title)
{
$this->et_title = $et_title;
return $this;
}
/**
* @return mixed
*/
public function get_et_deleted()
{
return $this->et_deleted;
}
/**
* @param mixed $et_deleted
*
* @return self
*/
public function set_et_deleted($et_deleted)
{
$this->et_deleted = $et_deleted;
return $this;
}
/**
* @return mixed
*/
public function get_et_message()
{
return $this->et_message;
}
/**
* @param mixed $et_message
*
* @return self
*/
public function set_et_message($et_message)
{
$this->et_message = $et_message;
return $this;
}
/**
* @return mixed
*/
public function get_et_subject()
{
return $this->et_subject;
}
/**
* @param mixed $et_subject
*
* @return self
*/
public function set_et_subject($et_subject)
{
$this->et_subject = $et_subject;
return $this;
}
/**
* @return mixed
*/
public function get_et_from_name()
{
return $this->et_from_name;
}
/**
* @param mixed $et_from_name
*
* @return self
*/
public function set_et_from_name($et_from_name)
{
$this->et_from_name = $et_from_name;
return $this;
}
/**
* @return mixed
*/
public function get_et_from_email()
{
return $this->et_from_email;
}
/**
* @param mixed $et_from_email
*
* @return self
*/
public function set_et_from_email($et_from_email)
{
$this->et_from_email = $et_from_email;
return $this;
}
public function personalize($_raw, $_variable_array)
{
$matches = null;
preg_match_all('/{\$([a-z0-9\_]+)}/', $_raw, $matches);
//print_r($matches);
//[0] {$variable}
//[1] variable
foreach ($matches[0] as $key => $match) {
$_raw = str_replace($match, $_variable_array[$matches[1][$key]], $_raw);
}
return $_raw;
}
}
?>

BIN
_image/email_footer.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -16,3 +16,5 @@ ALTER TABLE `camp_apply`
DROP `capp_shuttle_type`;
ALTER TABLE `camp_apply` ADD `capp_money` INT NOT NULL DEFAULT '0' AFTER `capp_camp_id`;
INSERT INTO `email_template` (`et_id`, `et_name`, `et_title`, `et_deleted`, `et_message`, `et_subject`, `et_from_name`, `et_from_email`) VALUES (NULL, 'camp_reply', 'Tábor visszaigazolás', '0', 'Kedves szülő / regisztráló!<br>\r\n<br>\r\nTábor regisztrációja sikeresen beérkezett hozzánk és jóváhagytuk!<br>\r\n<br>\r\nA regisztráció véglegesítéséhez kérjük fáradjon be a tábor díjának kiegyenlítésére!<br>\r\nAmennyiben utalással kíván fizetni, kérjük jelezze felénk az alábbi elérhetőségek valamelyikén!<br>\r\n<br>\r\n<img src=\"https://badminton.livingsport.hu/_image/email_footer.jpg\" width=\"378\"><br>\r\nTel: +36204100735 | info@livingsport.hu<br>\r\n2700 Cegléd, Mizsei út 03/24 Hrsz.<br>\r\n<br>\r\nÜdvözlettel,<br>\r\nLiving Sport csapata', 'Sikeres tábor regisztráció', 'Living Sport', 'notify@livingsport.hu');