Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- require_once 'phpmailer/PHPMailerAutoload.php';
- $errors = [];
- if(isset($_POST['name'], $_POST['email'], $_POST['message'])) {
- $fields = [
- 'name' => $_POST['name'],
- 'email' => $_POST['email'],
- 'email' => $_POST['email']
- ];
- foreach($field as $field => $data) {
- }
- if(empty($data)) {
- $errors[] = 'The ' . $field . ' Field is required';
- }
- if(empty($errors)) {
- $m = new PHPMailer;
- $m->isSMTP();
- $m->SMTPAuth = true;
- $m->Host = 'smtp.gmail.com';
- $m->Username = '';
- $m->Password = '';
- $m->SMTPSecure = 'SSL';
- $m->Port = 465;
- $m->isHTML();
- $m->Subject - 'Contact form submitted';
- $m->Body = 'From: ' . $fields['name'] . ' ( ' . $fields['email'] . ' )<p>' . $fields['message'] . '</p>';
- $m->FromName = 'Contact';
- $m->AddAddress('christianbreen1337@gmail.com', 'Christian Breen');
- if($m->send()) {
- header('Location: index.php');
- die();
- } else {
- $errors[] = 'Sorry, could not send email. Try again later!';
- }
- }
- } else {
- $errors[] = 'Something has gone wrong';
- }
- $_SESSION['errors'] = $errors;
- $_SESSION['fields'] = $fields;
- header('Location: index.php');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement