G
G
Genri_Rus2020-02-27 23:17:14
PHPMailer
Genri_Rus, 2020-02-27 23:17:14

How to include phpmailer library in wordpress?

I just can’t understand, there is a form:

5e582246988b7217759079.png

There is a phpmailer library, I tried to do this:

var data = {
  action : 'not_found_form',
  found_form : sendForm
}	
$.ajax({
     type: "POST",
     url: not_found_404.ajax_url,
     data: data,   
     success: function(data) {
  console.log(data);
      },
     error:  function(xhr){
      
     }
 });

In function.php

function scripts() {
  if ( is_404() ) {
    wp_enqueue_script( '404-form', get_template_directory_uri() . '404-form.js', array( 'jquery' ), '1', true );
    wp_localize_script( '404-form', 'not_found_404', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
  }
}

add_action( 'wp_enqueue_scripts', 'scripts' );

add_action('wp_ajax_not_found_form', 'form_not_found_page');
add_action('wp_ajax_nopriv_not_found_form', 'form_not_found_page');

function form_not_found_page() {
   if ( isset($_POST['name'] ) ) {
    $name = trim( strip_tags( $_POST['name'] ) );
   }

  if ( isset($_POST['phone'] ) ) {
    $phone = trim( strip_tags( $_POST['phone'] ) );
  }
  
  ContactMailer::send( $name, $phone );

  exit;
}

There is an error in the console, supposedly admin-ajax.php cannot send

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Just Me, 2020-02-28
@Just__Den

built-in function wp_mail is a wrapper over PHPMailer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question