Advertisement
Guest User

contact-form.php

a guest
Oct 29th, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. <?php
  2. /*
  3. Name: Contact Form
  4. Written by: Okler Themes - (http://www.okler.net)
  5. Theme Version: 1.1.0
  6. */
  7.  
  8. namespace EZYContactForm;
  9.  
  10. session_cache_limiter('nocache');
  11. header('Expires: ' . gmdate('r', 0));
  12.  
  13. header('Content-type: application/json');
  14.  
  15. use PHPMailer\PHPMailer\PHPMailer;
  16. use PHPMailer\PHPMailer\Exception;
  17.  
  18. require 'php-mailer/src/PHPMailer.php';
  19. require 'php-mailer/src/SMTP.php';
  20. require 'php-mailer/src/Exception.php';
  21.  
  22. // Step 1 - Enter your email address below.
  23. $email = 'info@johnsparksart.co.uk';
  24.  
  25. // If the e-mail is not working, change the debug option to 2 | $debug = 2;
  26. $debug = 0;
  27.  
  28. // If contact form don't have the subject input, change the value of subject here
  29. $subject = $_POST['subject'];
  30.  
  31. $message = '';
  32.  
  33. foreach($_POST as $label => $value) {
  34. $label = ucwords($label);
  35.  
  36. // Use the commented code below to change label texts. On this example will change "Email" to "Email Address"
  37. if( $label == 'Email' ) {
  38. $label = 'Email Address';
  39. }
  40.  
  41. $message .= $label.": " . htmlspecialchars($value, ENT_QUOTES) . "<br>\n";
  42. }
  43.  
  44. $mail = new PHPMailer(true);
  45.  
  46. try {
  47.  
  48. $mail->SMTPDebug = $debug; // Debug Mode
  49.  
  50. // Step 2 (Optional) - If you don't receive the email, try to configure the parameters below:
  51.  
  52. //$mail->IsSMTP(); // Set mailer to use SMTP
  53. //$mail->Host = 'mail.yourserver.com'; // Specify main and backup server
  54. //$mail->SMTPAuth = true; // Enable SMTP authentication
  55. //$mail->Username = 'user@example.com'; // SMTP username
  56. //$mail->Password = 'secret'; // SMTP password
  57. //$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
  58. //$mail->Port = 587; // TCP port to connect to
  59.  
  60.  
  61.  
  62. $mail->SetFrom($email, $_POST['name']);
  63. $mail->AddReplyTo($_POST['email'], $_POST['name']);
  64.  
  65. $mail->IsHTML(true); // Set email format to HTML
  66.  
  67. $mail->CharSet = 'UTF-8';
  68.  
  69. $mail->Subject = $subject;
  70. $mail->Body = $message;
  71.  
  72. $mail->Send();
  73. $arrResult = array ('response'=>'success');
  74.  
  75. } catch (Exception $e) {
  76. $arrResult = array ('response'=>'error','errorMessage'=>$e->errorMessage());
  77. } catch (\Exception $e) {
  78. $arrResult = array ('response'=>'error','errorMessage'=>$e->getMessage());
  79. }
  80.  
  81. if ($debug == 0) {
  82. echo json_encode($arrResult);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement