Advertisement
Guest User

Contact php

a guest
Mar 8th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. require_once 'phpmailer/PHPMailerAutoload.php';
  6.  
  7. $errors = [];
  8.  
  9. if(isset($_POST['name'], $_POST['email'], $_POST['message'])) {
  10.  
  11. $fields = [
  12. 'name' => $_POST['name'],
  13. 'email' => $_POST['email'],
  14. 'email' => $_POST['email']
  15. ];
  16.  
  17. foreach($field as $field => $data) {
  18. }
  19. if(empty($data)) {
  20. $errors[] = 'The ' . $field . ' Field is required';
  21. }
  22.  
  23. if(empty($errors)) {
  24.  
  25. $m = new PHPMailer;
  26.  
  27. $m->isSMTP();
  28. $m->SMTPAuth = true;
  29.  
  30. $m->Host = 'smtp.gmail.com';
  31. $m->Username = '';
  32. $m->Password = '';
  33. $m->SMTPSecure = 'SSL';
  34. $m->Port = 465;
  35.  
  36. $m->isHTML();
  37.  
  38. $m->Subject - 'Contact form submitted';
  39. $m->Body = 'From: ' . $fields['name'] . ' ( ' . $fields['email'] . ' )<p>' . $fields['message'] . '</p>';
  40.  
  41. $m->FromName = 'Contact';
  42.  
  43. $m->AddAddress('christianbreen1337@gmail.com', 'Christian Breen');
  44.  
  45. if($m->send()) {
  46. header('Location: index.php');
  47. die();
  48. } else {
  49. $errors[] = 'Sorry, could not send email. Try again later!';
  50. }
  51. }
  52.  
  53. } else {
  54. $errors[] = 'Something has gone wrong';
  55. }
  56.  
  57. $_SESSION['errors'] = $errors;
  58. $_SESSION['fields'] = $fields;
  59. header('Location: index.php');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement