Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery('#contactForm').submit(ajaxSubmit);
- function ajaxSubmit(){
- var contactReplyForm = jQuery(this).serialize();
- if ( jQuery(this).parsley().isValid() ) {
- jQuery.ajax({
- type:"POST",
- url: "<?php get_template_directory_uri().'/wp-admin/admin-ajax.php'?>",
- data: contactReplyForm,
- success:function(result){
- jQuery( 'div#contactFormSuccess' ).show().delay(5000).fadeOut();
- console.log(result);
- }
- });
- }
- return false;
- }
- function ajaxFormSubmission(){
- $contact_form_name = $_POST['contact_form_name'];
- $contact_form_phone = $_POST['contact_form_phone'];
- $contact_form_email = $_POST['contact_form_email'];
- $contact_form_address = $_POST['contact_form_address'];
- $contact_form_comments = $_POST['contact_form_comments'];
- //include phpMailer
- require_once (__DIR__."/PHPMailer/PHPMailerAutoload.php");
- //PHPMailer Object
- $mail = new PHPMailer;
- //Enable SMTP debugging.
- $mail->SMTPDebug = 3;
- //Set PHPMailer to use SMTP.
- $mail->isSMTP();
- //Set SMTP host name
- $mail->Host = "smtp.gmail.com";
- //Set this to true if SMTP host requires authentication to send email
- $mail->SMTPAuth = true;
- //Provide username and password
- $mail->Username = "mnengwamkongo@gmail.com";
- $mail->Password = "Shadow-walker";
- //If SMTP requires TLS encryption then set it
- $mail->SMTPSecure = "tls";
- //Set TCP port to connect to
- $mail->Port = 587;
- //From email address and name
- $mail->From = $contact_form_email;
- $mail->FromName = $contact_form_name;
- //To address and name
- $mail->addAddress("mnengwamkongo@gmail.com", "Kabugu and Co Advocates");
- //Send HTML or Plain Text email
- $mail->isHTML(true);
- $mail->Subject = "Email from website";
- $mail->Body = "Phone: ".$contact_form_phone."<br/>".
- "Address: ".$contact_form_address."<br/>".
- $contact_form_comments;
- $mail->AltBody = "This is the plain text version of the email content";
- if(!$mail->send())
- {
- echo "Mailer Error: " . $mail->ErrorInfo;
- }
- else
- {
- echo "Form Successfully Submitted!";
- }
- die();
- }
- add_action('wp_ajax_ajaxFormSubmission', 'ajaxFormSubmission');
- add_action('wp_ajax_nopriv_ajaxFormSubmission', 'ajaxFormSubmission');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement