I am making a form, with an input for PDF , validating that all the fields are filled in order to be sent to a predetermined mail, but when the mail arrives the file of the > PDF does not arrive as it should.
The code is as follows:
window.onload = function() {
var $form2 = $('#trip');
function validateEmail(email) {
var re = /^(([^<>()\[\]\.,;:\s@"]+(\.[^<>()\[\]\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
$('#trip').submit( function(e) {
e.preventDefault();
var campo_email = $('input[name="email"]').val();
var campo_name =$('input[name="name"]').val();
var campo_coment =$('textarea[name="coment"]').val();
var campo_cv = $('input[type="file"]')[0].files[0].size;
if(campo_email && campo_name && campo_coment && campo_cv){
if(validateEmail(campo_email) === true && campo_name && campo_coment && campo_cv){
/* EMAIL */
var datos = { action:'siteWideMessage', nombre:campo_name, comentario:campo_coment, email:campo_email, fileCurriculum:campo_cv };
$.post('<?php echo admin_url("admin-ajax.php"); ?>',
datos, function(response) {
console.log(response);
});
/* END EMAIL */
$("#modal-up").hide();
alert("Message sent!");
window.location.reload(false);
}else{
alert("The mail is invalid");
}
}else{
alert("Please, complete all the fields");
}
})
}
** functions.php code **
/ * SEND EMAIL POPUP * /
add_action( 'wp_ajax_siteWideMessage', 'wpse_sendmail' );
add_action( 'wp_ajax_nopriv_siteWideMessage', 'wpse_sendmail' );
function wpse_sendmail()
{
$nombre = $_POST["nombre"];
$email = sanitize_text_field( $_POST["email"] );
$comentario = $_POST["comentario"];
$fileCurriculum = $_POST["fileCurriculum"];
// get the blog administrator's email address
$to = "[email protected]";
$message = 'Hola mi nombre es ' . $nombre . ' y mi correo es ' . $email . ' estoy postulando para ' . $comentario . 'mi Curriculum ' . $fileCurriculum;
$subject = 'PUESTO DE TRABAJO';
$headers = "From: <$email>" . "\r\n";
// If email has been process for sending, display a success message
if ( wp_mail( $to, $subject, $message, $headers ) ) {
echo '<div class="mensaje" style="display:none;">';
echo '<p>Thanks! Your personalised itinerary will be emailed very soon!</p>';
echo '</div>';
} else {
echo 'An unexpected error occurred';
}
die();
}