I have a json that is stored in the variable projects which is sent by jquery.ajax in this way:
var proyectos = [{"Paso1": selectEmpStar},{"Paso2": selectEtapa},{"Paso3": selectServ},{"Paso4": selectCarac},{"Paso5": selectCuent},{"Paso6": selecDatos}];
Sending by post the json
var datos = JSON.stringify(proyectos);
jQuery.ajax({
type: 'POST',
cache: false,
url:'<?php echo admin_url('admin-ajax.php') ?>',
data:{
action: 'contact_send',
dataProyectos : datos,
dataAsunto : valNombres
},
success: function() {
alert("Mensaje Enviado");
}
});
and in wordpress php for sending mail:
function callback_contact_send() {
$send_to = '[email protected]';
$subject = $_POST['dataAsunto'];
$message = $_POST['dataProyectos'];
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";
$headers .= 'From: proyectos-tecnologicos' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$mail = mail($send_to,$subject,$message,$headers);
if($mail){
echo "Mensaje enviado";
}else{
echo "Error";
}
die();
}
The message arrives correctly but in this way: In what way could the json be formatted and not arrive in that way for a better visualization?