Advertisement
Guest User

Untitled

a guest
Jul 27th, 2018
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 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 = 'francois.dumortier@gmail.com';
  24.  
  25. // If the e-mail is not working, change the debug option to 2 | $debug = 2;
  26. $debug = 2;
  27.  
  28. // If contact form don't have the subject input, change the value of subject here
  29. $subject = ( isset($_POST['subject']) ) ? $_POST['subject'] : 'Define subject in php/contact-form.php line 29';
  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.  
  38. // if( $label == 'Email' ) {
  39. // $label = 'Email Address';
  40. // }
  41.  
  42. $message .= $label.": " . htmlspecialchars($value, ENT_QUOTES) . "<br>\n";
  43. }
  44.  
  45. $mail = new PHPMailer(true);
  46.  
  47. try {
  48.  
  49. $mail->SMTPDebug = $debug; // Debug Mode
  50.  
  51. // Step 2 (Optional) - If you don't receive the email, try to configure the parameters below:
  52.  
  53. //$mail->IsSMTP(); // Set mailer to use SMTP
  54. //$mail->Host = 'mail.yourserver.com'; // Specify main and backup server
  55. //$mail->SMTPAuth = true; // Enable SMTP authentication
  56. //$mail->Username = 'user@example.com'; // SMTP username
  57. //$mail->Password = 'secret'; // SMTP password
  58. //$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
  59. //$mail->Port = 587; // TCP port to connect to
  60.  
  61. $mail->AddAddress($email); // Add another recipient
  62.  
  63. //$mail->AddAddress('person2@domain.com', 'Person 2'); // Add a secondary recipient
  64. //$mail->AddCC('person3@domain.com', 'Person 3'); // Add a "Cc" address.
  65. //$mail->AddBCC('person4@domain.com', 'Person 4'); // Add a "Bcc" address.
  66.  
  67. $mail->SetFrom($email, $_POST['name']);
  68. $mail->AddReplyTo($_POST['email'], $_POST['name']);
  69.  
  70. $mail->IsHTML(true); // Set email format to HTML
  71.  
  72. $mail->CharSet = 'UTF-8';
  73.  
  74. $mail->Subject = $subject;
  75. $mail->Body = $message;
  76.  
  77. $mail->Send();
  78. $arrResult = array ('response'=>'success');
  79.  
  80. } catch (Exception $e) {
  81. $arrResult = array ('response'=>'error','errorMessage'=>$e->errorMessage());
  82. } catch (\Exception $e) {
  83. $arrResult = array ('response'=>'error','errorMessage'=>$e->getMessage());
  84. }
  85.  
  86. if ($debug == 0) {
  87. echo json_encode($arrResult);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement