I have created a form to send messages to Telegram through a bot. I use ajax to send all the data of my form to my php code and that in this the link of the sending of the message is generated. In my ajax I have a success and error, and here the problem:
When I execute my code in the Xampp everything is fine and the messages are sent and the link goes to the success and it is shown, but when executing in the localhost of Netbeans it does not work and the error arrives "Object Object", in my hosting seems to be done and it arrives at the success but the messages are not sent.
This is the form:
<form method="post" id="formu" autocomplete="off">
<fieldset>
<legend>Enviar mensaje a José</legend>
<label for="nomb">Nombre</label>
<input id="nomb" name="nombre" type="text" placeholder="tu nombre">
<label for="asunt">Asunto</label>
<input id="asunt" name="asunto" type="text" placeholder="opcional">
<label for="mail">E-mail</label>
<input id="mail" name="correo" type="text" placeholder="[email protected]">
<br>
<textarea id="msj" name="mensaje" rows="5" placeholder="Escribe tu mensaje"></textarea>
<input type="button" value="Enviar" onclick="post()"/>
</fieldset>
</form>
This is the javascript:
function post() {
alert("Enviando.....");
var formulario = $("#formu").serialize();
$.ajax({
type: 'POST',
url: 'bot.php',
data: formulario,
success: function (result) {
alert("Enviado correctamente"+result);
},
error: function (result) {
alert("No se envio"+result);
}
});
}
and this my bot.php:
<?php
define('BOT_TOKEN', '344659915:AAEQQbBhXcovEWgj4UkSMnoin1XP8P2TsZE');
define('CHAT_ID', '442754015');
define('API_URL', 'https://api.telegram.org/bot');
$msj=$_POST['nombre'].",
".$_POST['asunto']."\n\n".$_POST['mensaje']."\n".$_POST['correo'];
$queryArray = ['chat_id'=>CHAT_ID,'text'=> $msj];
$url=API_URL.BOT_TOKEN.'/sendMessage?'.http_build_query($queryArray);
$result = file_get_contents($url);
//header("Location: ".$url);
//echo file_get_contents($url,"UTF-8");
?>
The parts of code discussed in bot.php I have because they are valid to make the code work, but as I said only happens in the xampp.
I can say that everything is imported into my html, the jquery-3.2.1.js and my javascript with my function post ().
here my hosting: joseluna.ml