Skip to content

Instantly share code, notes, and snippets.

@1823alex
Created November 18, 2017 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1823alex/a343b38f8011885552526ff972bccd78 to your computer and use it in GitHub Desktop.
Save 1823alex/a343b38f8011885552526ff972bccd78 to your computer and use it in GitHub Desktop.
<?php
session_start();
include_once 'assets/libs/class.phpmailer.php';
require_once 'assets/libs/PHPMailerAutoload.php';
$errors = [];
if(isset($_POST['name'], $_POST['email'], $_POST['message'])) {
$fields = [
'name' => $_POST['name'],
'email' => $_POST['email'],
'message' => $_POST['message']
];
foreach($fields as $field => $data) {
if(empty($data)) {
$errors[] = 'The ' . $field . ' field is required.';
}
}
if(empty($errors)) {
$m = new PHPMailer(true);
$mail->isSMTP();
$mail = new PHPMailer();
$mail->Host = "smtpout.secureserver.net";
$mail->Username = "sender@website.com"; /*Substitute with your real email*/
$mail->Password = "password"; /*Substitute with your real password*/
$mail->SMTPAuth = true;
$mail->Port = 80;
$m->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$m->isHTML(true);
$m->Subject = 'Contact form submitted';
$m->Body = '<html> From: ' . $fields['name'] . ' <br> Email: ' . $fields['email'] . ' <br> <p>' . $fields['message'] . '</p> </html>';
$m->From = 'name@company.com';
$m->FromName = 'Mail Handler';
$m->Sender = 'name@company.com';
$m->AddAddress('personalemail@gmail.com', 'ME');
if($m->send()) {
header('Location: index.html');
die();
} else {
$errors[] = 'Sorry, we were unable to process your request at this time. Please try again later.';
}
}
} else {
$errors[] = 'Something went wrong!';
}
$_SESSION['errors'] = $errors;
header('Location: index.php');
<?php
session_start();
require_once('assets/helpers/security.php');
$errors = isset($_SESSION['errors']) ? $_SESSION['errors'] : [];
$fields = isset($_SESSION['fields']) ? $_SESSION['fields'] : [];
?>
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Development</title>
<meta name="description" content="A demo landing page for agencies or product oriented businesses built using Shards, a free, modern and lightweight UI toolkit based on Bootstrap 4.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSS Dependencies -->
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<link rel="stylesheet" href="css/theme.css">
<link rel="stylesheet" href="css/extras.css">
</head>
<body>
<!-- Bunch of Extra Code Removed -->
<!-- Contact Section -->
<a name="contact"></a>
<div class="contact section-invert py-4">
<h3 class="section-title text-center m-5">Contact Me & Get a free Quote</h3>
<div class="container py-4">
<div class="row justify-content-md-center px-4">
<div class="contact-form col-sm-12 col-md-10 col-lg-7 p-4 mb-4 card">
<form action="contact.php" method="post">
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label for="contactFormFullName">Full Name</label>
<input type="text" class="form-control" id="contactFormFullName" placeholder="Enter your full name" <?php echo isset($fields['name']) ? ' value="' . e($fields['name']) . '"' : '' ?>>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label for="contactFormEmail">Email address</label>
<input type="email" class="form-control" id="contactFormEmail" placeholder="Enter your email address" <?php echo isset($fields['email']) ? ' value="' . e($fields['email']) . '"' : '' ?>>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-group">
<label for="exampleInputMessage1">Message</label>
<textarea id="exampleInputMessage1" class="form-control mb-4" rows="10" placeholder="Enter your message..." name="message"> <?php echo isset($fields['message']) ? e($fields['message']) : '' ?> </textarea>
</div>
</div>
</div>
<input class="btn btn-primary btn-pill d-flex ml-auto mr-auto" type="submit" value="Send Your Message">
</form>
</div>
</div>
</div>
</div>
<!-- / Contact Section -->
<!-- JavaScript Dependencies -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
</body>
</html>
<?php
unset($_SESSION['errors']);
unset($_SESSION['fields']);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment