Title: Send mail without Plugins and with Javascript
Last modified: August 22, 2016

---

# Send mail without Plugins and with Javascript

 *  [ebarroso](https://wordpress.org/support/users/ebarroso/)
 * (@ebarroso)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/send-mail-without-plugins-and-with-javascript/)
 * Hi,
 * I have a problem, I have a form in mi front-end with 3 fields and a submit button.
   This submit button has to send me an email.
    I dont want to use more plugins,
   this is a very simple form. I only need send this form without reloading the 
   page, so i need JS and AJAX, but, it doesn´t work…
 * I have this in my index.php:
 *     ```
       <form method="post" name="fcontacto" id="fcontacto" action="<?php the_permalink(); ?>" >
       <div class="fcontacto">
                                                                                       <fieldset class="contact-form">
                                                                                           <p class="form-group">
                                                                                               <label id="lblName" for="txtName">
                                                                                                   Nombre
                                                                                               </label>
                                                                                               <input type="text" tabindex="1" id="txtName" name="txtName">
                                                                                           </p>
                                                                                           <p class="form-group">
                                                                                               <label id="Email" for="txtEmail">
                                                                                                   Email
                                                                                               </label>
                                                                                               <input type="text" tabindex="2" id="txtEmail" name="txtEmail">
                                                                                           </p>
                                                                                           <p class="form-group">
                                                                                               <label id="lblPostcode" for="txtPostcode">
                                                                                                   Código Postal
                                                                                               </label>
                                                                                               <input type="text" tabindex="3" id="txtPostcode" name="txtPostcode">
                                                                                           </p>
                                                                                           <input type="submit" class="btn btn-default" tabindex="7" id="submit" value="Enviar" name="submit">
                                                                                           <div id="respuesta" style="display:none;"></div>
   
                                                                                       </fieldset>
                                                                                   </div>
       </form>
       ```
   
 * This in my custom.js:
 *     ```
       $(document).ready(function(){
       	$("#fcontacto").submit(function( event ){
       		event.preventDefault();
       		$.ajax({
       			type: 'POST',
       			url: '../send.php',
       			data: $(this).serialize(),
       			success: function(data){
       				$("#respuesta").slideDown();
       				$("#respuesta").html(data);
       			}
       		});
       		return false;
       	});
   
       });
       ```
   
 * And this in my send.php:
 *     ```
       <?php
       require '../../../class.phpmailer.php';
       $mail = new PHPMailer;
       $to = "elisabeth.barroso@pulsar-energy.com"; // Nuestro correo de contacto
       // recogeremos los datos del formulario
       $nombre = $_POST['txtName'];
       $email = $_POST['txtEmail'];
       $asunto = $_POST['txtPostcode'];
       if($nombre == "" || $email == "" || $asunto == ""):
       echo '<div class="alert alert-danger">Todos los campos son requeridos para el envio</div>';
       else:
       $mail->From = $email;
       $mail->addAddress($to);
       $mail->Subject = $asunto;
       $mail->isHtml(true);
       $mail->Body = '<strong>'.$nombre.'</strong> le ha contactado desde su web, y le ha enviado el siguiente mensaje: <br><p></p>';
       $mail->CharSet = 'UTF-8';
       $mail->send();
       endif;
       ?>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [fornoam](https://wordpress.org/support/users/fornoam/)
 * (@fornoam)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/send-mail-without-plugins-and-with-javascript/#post-5830557)
 * You could use emailjs.com for that.
 *  [Justin Greer](https://wordpress.org/support/users/justingreerbbi/)
 * (@justingreerbbi)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/send-mail-without-plugins-and-with-javascript/#post-5830559)
 * There is not need to to use direct file linking. There IS a correct way to use
   AJAX with WP.
 * Here is some references:
    – [http://www.1stwebdesigner.com/implement-ajax-wordpress-themes/](http://www.1stwebdesigner.com/implement-ajax-wordpress-themes/)–
   [http://codex.wordpress.org/AJAX_in_Plugins](http://codex.wordpress.org/AJAX_in_Plugins)
 * WordPress using PHPMailer already as default so you can simply using
    `wp_mail()`(
   [http://codex.wordpress.org/Function_Reference/wp_mail](http://codex.wordpress.org/Function_Reference/wp_mail))

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Send mail without Plugins and with Javascript’ is closed to new replies.

## Tags

 * [ajax](https://wordpress.org/support/topic-tag/ajax/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [phpmailer](https://wordpress.org/support/topic-tag/phpmailer/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [Justin Greer](https://wordpress.org/support/users/justingreerbbi/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/send-mail-without-plugins-and-with-javascript/#post-5830559)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
