File: D:/HostingSpaces/SBogers68/resortouddorpduin.nl/wwwroot/app/controllers/c_nieuwsbrief.class.php
<?php
/**
* c_home.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 11/02/14
*/
require_once DOCUMENT_ROOT . 'lib/form/form.class.php';
require_once DOCUMENT_ROOT . 'lib/mail/php_mailer.class.php';
class Nieuwsbrief extends Controller
{
public function __construct()
{
if (LANG_ROOT == "/de/"){
$this->name = 'nieuwsbrief_de';
}else{
$this->name = 'nieuwsbrief';
}
}
/*
* Index of the home page
*/
public function index()
{
// Title
$this->View->setData('page_title', SITE_NAME);
// Generate form
$Form = new Form($this->name);
$fields = $Form->generate();
$this->View->setData('form_fields',$fields);
// Load template view
$this->View->render('v_nieuwsbrief');
}
public function validate()
{
if(isset($_POST['secret_code']) && $_POST['secret_code'] == 'spam_check_komma')
{
$Form = new Form($this->name);
if($Form->validate())
{
// Get data for mail
$data = $_SESSION[$this->name]['data'];
// Convert message
//$data['message'] = nl2br($data['message']);
$from['email'] = COMPANY_EMAIL;
$from['name'] = COMPANY_NAME;
$to['email'] = COMPANY_EMAIL;
$to['name'] = COMPANY_NAME;
// Create message for mail
$msg = 'Er is een inschrijving voor de nieuwsbrief binnengekomen via de website:<br /><br />';
foreach($data as $prop => $value)
{
$msg .= '<strong>' . $this->lang[$prop] . '</strong>:<br /> ' . $value . '<br /><br />';
}
// Send e-mail
$Mailer = new PHPMailer(TRUE);
try
{
// Mail
$Mailer->AddAddress($to['email'], $to['name']);
$Mailer->SetFrom($from['email'], $from['name']);
$Mailer->Subject = 'Nieuwsbrief Ouddorp Duin';
$Mailer->MsgHTML($msg);
$Mailer->Send();
if (LANG_ROOT == '/de/'){
$_SESSION['nieuwsbrief']['success'] = 'Sehr geehrte(r) Herr/Frau,<br /><br />
Vielen Dank für Ihne eingabe, Sie bekommen ein Bestätigungsmail.<br /><br />
Freundliche grüße<br />
Strand Resort Ouddorp Duin';
}else{
$_SESSION['nieuwsbrief']['success'] = 'Geachte heer / mevrouw,<br /><br />
Bedankt voor uw aanvraag. U ontvangt de informatie spoedig per mail.<br /><br />
Met vriendelijke groet,<br />
Strand Resort Ouddorp Duin';
}
}
catch (phpmailerException $e)
{
// Catch mail problem?
$_SESSION[$this->name]['main_error'] = 'Er is iets fout gegaan bij verzenden. <br />Neem contact op met <a href="mailto:info@resortouddorpduin.nl">info@resortouddorpduin.nl</a>';
}
unset($_SESSION[$this->name]['data']);
Fn::redirect(LANG_ROOT.'nieuwsbrief');
}
}
Fn::redirect(LANG_ROOT.'nieuwsbrief');
}
}