// Index contact form add_action('wp_ajax_my_action', 'data_fetch'); add_action('wp_ajax_nopriv_my_action', 'data_fetch'); function data_fetch() { $form_errors = array(); if( isset($_POST['submit_form']) ) { $name = $_POST['fullname']; $email = $_POST['email']; $message = $_POST['message']; $file = $_POST['file_field']; $subject = 'Z formularza na stronie'; $content = "

WIADOMOŚĆ Z FORMULARZA NA STRONIE

NADAWCA:

$name, $email

TREŚĆ:

$message


"; foreach ($fields as $field) { if (isset($_POST[$field])) $posted[$field] = stripslashes(trim($_POST[$field])); else $posted[$field] = ''; } $errors = array_filter($form_errors); if (empty($errors)) { if ( ! function_exists( 'wp_handle_upload' ) ) { require_once( ABSPATH . 'wp-admin/includes/file.php' ); } $uploadedfile = $_FILES['attachmentFile']; $upload_overrides = array( 'test_form' => false ); $movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); if ( $movefile && ! isset( $movefile['error'] ) ) { $movefile['url']; } $to = get_option('admin_email'); $attachments = array($movefile['file']); $headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$name.' <'.$email.'>', 'Reply-To: '.$name.' <'.$email.'>'); if(wp_mail($to , $subject , $content , $headers , $attachments)){ echo '
Wiadomość wysłana :)
' ; } else { echo '
Niestety, wiadomość nie została wysłana, spróbuj jeszcze raz.
' ; } } } wp_die(); } wp_register_script ( 'contact_form', get_template_directory_uri() . '/js/contact_form.js' ); wp_enqueue_script ( 'contact_form' );