Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- require_once 'helpers/security.php';
- $errors = isset($_SESSION['errors']) ? $_SESSION['errors'] : [];
- $fields = isset($_SESSION['fields']) ? $_SESSION['fields'] : [];
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Contact form</title>
- <link rel="stylesheet" href="css/style.css"/>
- <script src="js/script.js"></script>
- </head>
- <body>
- <div class="contact">
- <?php if(!empty($errors)): ?>
- <div class="panel">
- <ul>
- <li>
- <?php echo implode('</li><li>', $errors); ?>
- </li>
- </ul>
- </div>
- <?php endif; ?>
- <form action="contact.php" method="post">
- <label>
- Your name*
- <input type="text" name="name" id="name" autocomplete="off" <?php echo isset($fields['name']) ? 'Value="' . e($fields['name']) . '"' : '' ?>>
- </label>
- <label>
- Your email address *
- <input type="email" name="email" id="email" autocomplete="off" <?php echo isset($fields['email']) ? 'Value="' . e($fields['email']) . '"' : '' ?>>
- </label>
- <label>
- Your message *
- <textarea name="message" id="contact" rows="8"><?php echo isset($fields['message']) ? e($fields['message']) : '' ?></textarea>
- </label>
- <input type="submit" value="Send">
- <p class="muted">* Means a required field</p>
- </form>
- </div>
- </body>
- </html>
- <?php
- unset($_SESSION['errors']);
- unset($_SESSION['fields']);
- ?>
- <?php
- session_start();
- require_once "libs/phpmailer/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.';
- }
- }
- // 587 is voor uitgaande email deze is SSL en SMTP.ziggo.nl
- // 993 is voor inkomende email deze is TLS en IMAP.ziggo.nl
- // 110 is voor inkomende email deze is POP3 en
- if(empty($errors)){
- $mail = new PHPMailer;
- $mail->isSMTP();
- $mail->SMTPAuth = true;
- $mail->Host = '';
- $mail->Username = '';
- $mail->Password = '';
- $mail->SMTPSecure = 'tls';
- $mail->Port = 587;
- $mail->isHTML();
- $mail->SMTPDebug = 2;
- $mail->Subject = 'Dit is een test voor birsken.nl Negeer dit';
- $mail->Body = 'From: ' . $fields['name'] . ' ('. $fields['email'] .')<p>'. $fields['message'] .'</p>';
- $mail->FromName = $fields['name'];
- $mail->AddAddress('', '');
- if($mail->send()){
- header('Location: bedankt.php');
- die();
- } else {
- echo $mail->ErrorInfo; exit;
- }
- }
- } else {
- $errors[] = 'Something went wrong.';
- }
- $_SESSION['errors'] = $errors;
- $_SESSION['fields'] = $fields;
- header('location: index.php');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement