File: D:/HostingSpaces/SBogers10/tops.komma.pro/wwwroot/app/controllers/c_contact_form.class.php
<?php
/**
* c_contact_form.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 30/04/14
*/
require_once DOCUMENT_ROOT . 'lib/form/form.class.php';
require_once DOCUMENT_ROOT . 'lib/mail/php_mailer.class.php';
class Contact_Form extends Controller
{
private $name;
public function __construct()
{
parent::__construct();
$this->name = 'contact';
}
/*
* Validate contact form
*/
public function validate()
{
$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'] = $data['first_name'] . ' ' . $data['last_name'];
$to['email'] = COMPANY_EMAIL;
$to['name'] = COMPANY_NAME;
// Create message for mail
$msg = 'Er is een bericht binnen gekomen via het contactformulier op de website:<br /><br />';
foreach($data as $prop => $value)
{
$msg .= '<strong>' . $this->lang[$prop] . '</strong>:<br /> ' . $value . '<br /><br />';
}
switch (URL_LANG){
case "nl":
$clientMsg = 'Geachte heer / mevrouw, ' . ucfirst($data['last_name']) . ',<br /><br />';
$clientMsg .= 'Bedankt voor uw aanvraag.<br />';
$clientMsg .= 'Deze is in behandeling genomen en we nemen zo spoedig mogelijk contact met u op.<br /><br />';
$clientMsg .= 'Met vriendelijke groet,<br /><br />';
$clientMsg .= 'TOPS Luchtfilters';
break;
case "de":
$clientMsg = 'Geachte heer / mevrouw ' . ucfirst($data['last_name']) . ',<br /><br />';
$clientMsg .= 'Bedankt voor uw aanvraag.<br />';
$clientMsg .= 'Deze is in behandeling genomen en we nemen zo spoedig mogelijk contact met u op.<br /><br />';
$clientMsg .= 'Met vriendelijke groet,<br /><br />';
$clientMsg .= 'TOPS Luchtfilters';
break;
default:
$clientMsg = 'Dear Sir / Madam, ' . ucfirst($data['last_name']) . ',<br /><br />';
$clientMsg .= 'Thank you for your request.<br />';
$clientMsg .= 'It has been received and we will contact you as soon as possible. <br /><br />';
$clientMsg .= 'With kind regards,<br /><br />';
$clientMsg .= 'TOPS Airfilters';
}
// Send e-mail
$Mailer = new PHPMailer(TRUE);
try
{
// Mail TOPS
$Mailer->AddAddress($to['email'], $to['name']);
$Mailer->AddReplyTo($data['email'], $data['first_name'] . ' ' . $data['last_name']);
$Mailer->SetFrom($from['email'], $from['name']);
$Mailer->Subject = 'TOPS - Contact formulier';
$Mailer->MsgHTML($msg);
$Mailer->Send();
// Mail Client
$ClientMailer = new PHPMailer(TRUE);
$ClientMailer->AddAddress($data['email'], $data['first_name'] . ' ' . $data['last_name']);
$ClientMailer->SetFrom(COMPANY_EMAIL, COMPANY_NAME);
switch (URL_LANG) {
case "nl":
$ClientMailer->Subject = 'Bedankt voor uw vraag';
break;
case "de":
$ClientMailer->Subject = 'Bedankt voor uw vraag';
break;
default:
$ClientMailer->Subject = 'Thank you for your question';
break;
// Catch mail problems
}
$ClientMailer->MsgHTML($clientMsg);
$ClientMailer->Send();
// Success message
switch (URL_LANG){
case "nl":
$_SESSION[$this->name]['success'] = 'Geachte heer / mevrouw ' . ucfirst($data['last_name']) . ',<br /><br />
Bedankt voor uw aanvraag. Deze is in behandeling genomen en we nemen zo spoedig mogelijk contact met u op.';
break;
case "de":
$_SESSION[$this->name]['success'] = 'Geachte heer / mevrouw ' . ucfirst($data['last_name']) . ',<br /><br />
Bedankt voor uw aanvraag. Deze is in behandeling genomen en we nemen zo spoedig mogelijk contact met u op.';
break;
default:
$_SESSION[$this->name]['success'] = 'Dear Sir / Madam ' . ucfirst($data['last_name']) . ',<br /><br />
Thank you for your request. It has been received and we will contact you as soon as possible.';
}
}
catch (phpmailerException $e)
{
switch (URL_LANG) {
case "nl":
$_SESSION[$this->name]['main_error'] = 'Er is iets fout gegaan bij verzenden. <br />Neem contact op met <a href="mailto:info@topsluchtfilters.nl">info@topsluchtfilters.nl</a>';
break;
case "de":
$_SESSION[$this->name]['main_error'] = 'Er is iets fout gegaan bij verzenden. <br />Neem contact op met <a href="mailto:info@topsluchtfilters.nl">info@topsluchtfilters.nl</a>';
break;
default:
$_SESSION[$this->name]['main_error'] = 'There was a problem with sending. <br />Please contact <a href="mailto:info@topsluchtfilters.nl">info@topsluchtfilters.nl</a>';
break;
// Catch mail problems
}
}
unset($_SESSION[$this->name]['data']);
}
Fn::redirect(LANG_ROOT . $this->urls[$this->name]);
}
}