<?php
use phpformbuilder\Form;
use phpformbuilder\Validator\Validator;
/* =============================================
start session and include form class
============================================= */
session_start();
include_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/Form.php';
/* =============================================
validation if posted
============================================= */
if ($_SERVER["REQUEST_METHOD"] == "POST" && Form::testToken('email-styles') === true) {
// create validator & auto-validate required fields
$validator = Form::validate('email-styles');
// additional validation
$validator->email()->validate('user-email');
// recaptcha validation
$validator->recaptcha('6LeNWaQUAAAAAOnei_86FAp7aRZCOhNwK3e2o2x2', 'Recaptcha Error')->validate('g-recaptcha-response');
// check for errors
if ($validator->hasErrors()) {
$_SESSION['errors']['email-styles'] = $validator->getAllErrors();
} else {
$replacements = array();
// bogart theme
if (in_array('bogart', $_POST['theme'])) {
$replacements[] = array(
'tpl-header-image' => 'https://www.phpformbuilder.pro/assets/images/phpformbuilder-bogart-600-160.png',
'tpl-page-background' => 'url(https://www.phpformbuilder.pro/assets/images/noisy-bogart.png) repeat #1d2326',
'tpl-content-dark-background' => '#6a6a61',
'tpl-content-light-background' => '#dddcc5',
'tpl-content-dark-text' => '#1d2326',
'tpl-content-light-text' => '#dddcc5',
'tpl-content-accent-text' => '#dddcc5',
'tpl-content-accent-background' => '#611427',
'user-name' => 'Name',
'user-first-name' => 'First name',
'user-email' => 'Email'
);
}
// coffee theme
if (in_array('coffee', $_POST['theme'])) {
$replacements[] = array(
'tpl-header-image' => 'https://www.phpformbuilder.pro/assets/images/phpformbuilder-coffee-600-160.png',
'tpl-page-background' => 'url(https://www.phpformbuilder.pro/assets/images/noisy-coffee.png) repeat #4d3e39',
'tpl-content-dark-background' => '#222222',
'tpl-content-light-background' => '#f3f0e6',
'tpl-content-dark-text' => '#222222',
'tpl-content-light-text' => '#f3f0e6',
'tpl-content-accent-text' => '#ffffff',
'tpl-content-accent-background' => '#db7447',
'user-name' => 'Name',
'user-first-name' => 'First name',
'user-email' => 'Email'
);
}
// honey-pot theme
if (in_array('honey-pot', $_POST['theme'])) {
$replacements[] = array(
'tpl-header-image' => 'https://www.phpformbuilder.pro/assets/images/phpformbuilder-honey-pot-600-160.png',
'tpl-page-background' => 'url(https://www.phpformbuilder.pro/assets/images/noisy-honey-pot.png) repeat #191919',
'tpl-content-dark-background' => '#ffd34e',
'tpl-content-light-background' => '#fffad5',
'tpl-content-dark-text' => '#444444',
'tpl-content-light-text' => '#a6721a',
'tpl-content-accent-text' => '#fffad5',
'tpl-content-accent-background' => '#bd4932',
'user-name' => 'Name',
'user-first-name' => 'First name',
'user-email' => 'Email'
);
}
// sandy-stone theme
if (in_array('sandy-stone', $_POST['theme'])) {
$replacements[] = array(
'tpl-header-image' => 'https://www.phpformbuilder.pro/assets/images/phpformbuilder-sandy-stone-600-160.png',
'tpl-page-background' => 'url(https://www.phpformbuilder.pro/assets/images/noisy-sandy-stone.png) repeat #002f2f',
'tpl-content-dark-background' => '#a7a37e',
'tpl-content-light-background' => '#f9f8e9',
'tpl-content-dark-text' => '#333333',
'tpl-content-light-text' => '#f9f8e9',
'tpl-content-accent-text' => '#f9f8e9',
'tpl-content-accent-background' => '#198181',
'user-name' => 'Name',
'user-first-name' => 'First name',
'user-email' => 'Email'
);
}
// vintage theme
if (in_array('vintage', $_POST['theme'])) {
$replacements[] = array(
'tpl-header-image' => 'https://www.phpformbuilder.pro/assets/images/phpformbuilder-vintage-600-160.png',
'tpl-page-background' => 'url(https://www.phpformbuilder.pro/assets/images/noisy-vintage.png) repeat #2f343b',
'tpl-content-dark-background' => '#703030',
'tpl-content-light-background' => '#e3cda4',
'tpl-content-dark-text' => '#2f343b',
'tpl-content-light-text' => '#e3cda4',
'tpl-content-accent-text' => '#e3cda4',
'tpl-content-accent-background' => '#e55e3d',
'user-name' => 'Name',
'user-first-name' => 'First name',
'user-email' => 'Email'
);
}
// zen theme
if (in_array('zen', $_POST['theme'])) {
$replacements[] = array(
'tpl-header-image' => 'https://www.phpformbuilder.pro/assets/images/phpformbuilder-zen-600-160.png',
'tpl-page-background' => 'url(https://www.phpformbuilder.pro/assets/images/noisy-zen.png) repeat #10222b',
'tpl-content-dark-background' => '#bdd684',
'tpl-content-light-background' => '#e2f0d6',
'tpl-content-dark-text' => '#10222b',
'tpl-content-light-text' => '#f6ffe0',
'tpl-content-accent-text' => '#f6ffe0',
'tpl-content-accent-background' => '#10222b',
'user-name' => 'Name',
'user-first-name' => 'First name',
'user-email' => 'Email'
);
}
$count = count($replacements);
// posted template
if ($_POST['template'] == 'default-styled') {
$template = 'default-styled.html';
} else {
$template = 'contact-styled.html';
}
// send an email for each posted theme
for ($i=0; $i < $count; $i++) {
$email_config = array(
'sender_email' => 'contact@phpformbuilder.pro',
'sender_name' => 'Php Form Builder',
'recipient_email' => addslashes($_POST['user-email']),
'subject' => 'Contact From Php Form Builder',
'filter_values' => 'email-styles',
'template' => $template,
'values' => $_POST,
'custom_replacements' => $replacements[$i],
'debug' => true
);
$sent_message = Form::sendMail($email_config);
}
Form::clear('email-styles');
}
}
/* ==================================================
The Form
================================================== */
$form = new Form('email-styles', 'horizontal', 'novalidate');
// $form->setMode('development');
$form->startFieldset('Please fill in this form to contact us');
$form->addHtml('<p class="text-warning text-right">All fields are required</p>');
$form->addInput('text', 'user-name', '', 'Name:', 'required');
$form->addInput('text', 'user-first-name', '', 'First name:', 'required');
$form->addInput('email', 'user-email', '', 'Email:', 'required');
$form->addTextarea('message', '', 'Message:', 'cols=30, rows=4, required');
$form->addOption('theme[]', 'bogart', 'bogart', '', 'title=Bogart, data-content=<img src\=\'../assets/img/email-styles-bogart.png\' class\=\'prepend\'> Bogart');
$form->addOption('theme[]', 'coffee', 'coffee', '', 'title=Coffee, data-content=<img src\=\'../assets/img/email-styles-coffee.png\' class\=\'prepend\'> Coffee');
$form->addOption('theme[]', 'honey-pot', 'honey-pot', '', 'title=Honey pot, data-content=<img src\=\'../assets/img/email-styles-honey-pot.png\' class\=\'prepend\'> Honey pot');
$form->addOption('theme[]', 'sandy-stone', 'sandy-stone', '', 'title=Sandy Stone, data-content=<img src\=\'../assets/img/email-styles-sandy-stone.png\' class\=\'prepend\'> Sandy Stone');
$form->addOption('theme[]', 'vintage', 'vintage', '', 'title=Vintage, data-content=<img src\=\'../assets/img/email-styles-vintage.png\' class\=\'prepend\'> Vintage');
$form->addOption('theme[]', 'zen', 'zen', '', 'title=Zen, data-content=<img src\=\'../assets/img/email-styles-zen.png\' class\=\'prepend\'> Zen');
$form->addHelper('If you choose several themes you\'ll receive an email for each one', 'theme');
$form->addSelect('theme[]', 'Choose theme(s):', 'actionsBox=true, selectedTextFormat=static, class=select2, multiple, required');
$form->addRadio('template', '<span class="pr-5">Default styled</span>', 'default-styled');
$form->addRadio('template', 'Contact styled', 'contact-styled');
$form->addHelper('Default styled will add all posted values to the email in a table.<br>Contact styled will send a custom message from contact template.', 'template');
$form->printRadioGroup('template', 'Choose your template', true, 'required');
$form->addHtml('<p> </p>');
$form->addHtml('<div class="row justify-content-center"><div class="col-sm-8">');
$form->addRecaptchaV3('6LeNWaQUAAAAAGO_c1ORq2wla-PEFlJruMzyH5L6', 'bs4-email-styles');
$form->addHtml('</div></div>');
$form->addBtn('reset', 'reset-btn', 1, 'Reset <i class="fa fa-ban" aria-hidden="true"></i>', 'class=btn btn-warning', 'my-btn-group');
$form->addBtn('submit', 'submit-btn', 1, 'Send <i class="fa fa-envelope ml-2" aria-hidden="true"></i>', 'class=btn btn-success ladda-button, data-style=zoom-in', 'my-btn-group');
$form->printBtnGroup('my-btn-group');
$form->endFieldset();
// iCheck plugin
$form->addPlugin('icheck', 'input', 'default', array('%theme%' => 'square-custom', '%color%' => 'green'));
// jQuery validation
$form->addPlugin('formvalidation', '#email-styles');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bootstrap 4 Styled Email Form - How to create PHP forms easily</title>
<meta name="description" content="Bootstrap 4 Form Generator - how to send different styled emails with Php Form Builder Class">
<link rel="canonical" href="https://www.phpformbuilder.pro/templates/bootstrap-4-forms/email-styles.php" />
<!-- Bootstrap 4 CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- Font awesome icons -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<?php $form->printIncludes('css'); ?>
</head>
<body>
<h1 class="text-center">Php Form Builder - Bootstrap 4 Styled Email Form<br><small>send different styled emails using HTML/CSS templates</small></h1>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-11 col-lg-10">
<?php
if (isset($sent_message)) {
echo $sent_message;
}
$form->render();
?>
</div>
</div>
</div>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<!-- Bootstrap 4 JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<?php
$form->printIncludes('js');
$form->printJsCode();
?>
</body>
</html>