File: D:/HostingSpaces/SBogers10/tops.komma.pro/wwwroot/app/controllers/c_offer_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 Offer_Form extends Controller
{
private $name;
public function __construct()
{
parent::__construct();
$this->name = 'offer';
}
/*
* 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 offerte formulier op de website:<br /><br />';
foreach($data as $prop => $value)
{
$msg .= '<strong>' . $this->lang[$prop] . '</strong>:<br /> ' . $value . '<br /><br />';
}
// Message client
$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';
// 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 - Offerte 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);
$ClientMailer->Subject = 'Bedankt voor uw aanvraag';
$ClientMailer->MsgHTML($clientMsg);
$ClientMailer->Send();
// Success message
$_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.';
}
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@topsluchtfilters.nl">info@topsluchtfilters.nl</a>';
}
unset($_SESSION[$this->name]['data']);
}
Fn::redirect(LANG_ROOT . '/' . $this->urls[$this->name]);
}
}