Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. jQuery('#contactForm').submit(ajaxSubmit);
  2.  
  3. function ajaxSubmit(){
  4. var contactReplyForm = jQuery(this).serialize();
  5. if ( jQuery(this).parsley().isValid() ) {
  6. jQuery.ajax({
  7. type:"POST",
  8. url: "<?php get_template_directory_uri().'/wp-admin/admin-ajax.php'?>",
  9. data: contactReplyForm,
  10. success:function(result){
  11. jQuery( 'div#contactFormSuccess' ).show().delay(5000).fadeOut();
  12. console.log(result);
  13. }
  14. });
  15. }
  16.  
  17. return false;
  18. }
  19.  
  20. function ajaxFormSubmission(){
  21. $contact_form_name = $_POST['contact_form_name'];
  22. $contact_form_phone = $_POST['contact_form_phone'];
  23. $contact_form_email = $_POST['contact_form_email'];
  24. $contact_form_address = $_POST['contact_form_address'];
  25. $contact_form_comments = $_POST['contact_form_comments'];
  26.  
  27. //include phpMailer
  28. require_once (__DIR__."/PHPMailer/PHPMailerAutoload.php");
  29. //PHPMailer Object
  30. $mail = new PHPMailer;
  31.  
  32. //Enable SMTP debugging.
  33. $mail->SMTPDebug = 3;
  34. //Set PHPMailer to use SMTP.
  35. $mail->isSMTP();
  36. //Set SMTP host name
  37. $mail->Host = "smtp.gmail.com";
  38. //Set this to true if SMTP host requires authentication to send email
  39. $mail->SMTPAuth = true;
  40. //Provide username and password
  41. $mail->Username = "mnengwamkongo@gmail.com";
  42. $mail->Password = "Shadow-walker";
  43. //If SMTP requires TLS encryption then set it
  44. $mail->SMTPSecure = "tls";
  45. //Set TCP port to connect to
  46. $mail->Port = 587;
  47.  
  48. //From email address and name
  49. $mail->From = $contact_form_email;
  50. $mail->FromName = $contact_form_name;
  51.  
  52. //To address and name
  53. $mail->addAddress("mnengwamkongo@gmail.com", "Kabugu and Co Advocates");
  54.  
  55. //Send HTML or Plain Text email
  56. $mail->isHTML(true);
  57.  
  58. $mail->Subject = "Email from website";
  59. $mail->Body = "Phone: ".$contact_form_phone."<br/>".
  60. "Address: ".$contact_form_address."<br/>".
  61. $contact_form_comments;
  62. $mail->AltBody = "This is the plain text version of the email content";
  63.  
  64. if(!$mail->send())
  65. {
  66. echo "Mailer Error: " . $mail->ErrorInfo;
  67. }
  68. else
  69. {
  70. echo "Form Successfully Submitted!";
  71. }
  72. die();
  73. }
  74. add_action('wp_ajax_ajaxFormSubmission', 'ajaxFormSubmission');
  75. add_action('wp_ajax_nopriv_ajaxFormSubmission', 'ajaxFormSubmission');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement