1
I’m trying to take an email by an input, stream to the server through Ajax, and on the server side there’s a script that uses the Phpmailer class, to send an email, and the PHP code without receiving variable works, so the error is probably in Ajax
HTML
form id="emailForm">
<label for="campoEmail" class="has-information" hidden="false">Email enviado com sucesso</label>
<input id="campoEmail" class="input-center" placeholder="Digite aqui" type="email" name="email" required="true">
</br>
</br>
<input id="enviar" type="submit">
</form>
Javascript com Jquery
$('#emailForm').submit(function(e){
e.preventDefault();
$.ajax({
type: 'POST',
url: '/email.php',
data: 'email=' + $('#campoEmail').val(),
success:alert("Sucesso")
});
});
});
PHP has been tested separately and is working
And what is the error? The email is not sent or the alert is not displayed?
– rodorgas
The PHP code is not triggered, through AJAX, your answer fixed the parameter "sucess", agr it no longer appears
– Lucas Alves
Take a look here in PHP Code
– Lucas Alves
Dude, if the php code isn’t triggered, it’s your URL that’s wrong. Or, if by chance it is being triggered and does not perform anything, you probably have to check whether the variable
email
is with some value. Run these tests in PHP and see where specifically the error happens.– Simão Ítalo
Like, it’s in the same folder on the server, but if I open 'email.php' separately, it runs smoothly, but when I call through AJAX it doesn’t run
– Lucas Alves
If both are in the same folder, there is no reason to use absolute path. This may be the error, I edited my answer. To see what’s happening, use the Network tab of your browser’s Developer Tools.
– rodorgas
It was the directory of the.php file, already solved, when you put /email php., it searches the root directory
– Lucas Alves