Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
Send email on submit with AJAX is not working

I want to send an email when a button has been clicked. The button is created with bootstrap 5. Jquery will then send an AJAX request to a php file which should send the email. But it looks like the requested email.php file is not called. No code in that file is executed, no exit.In the console I got the success message from ajax and 'Button 2 clicked'. I have checked several posts. What is wrong? Please see below code.

form.php

            <div class="text-center mt-4 mb-4 ftp-order">
            <button type="submit" name="ftp-submit" id="ftp-submit" class="btn btn-success"><?php echo $arr_lang['bestellen']; ?></button>
        </div>

main.js

    $('#ftp-submit').click(function (e) {
    e.preventDefault();
    console.log("Button clicked");
        $.ajax({
            url: 'dateien/ajax/premium_account.php',
            data: '{pressed:pressed}',
            datatype: 'JSON',
            type: "POST",
            success: function (data) {
                console.log("Button clicked 2");
            },
            error: function (error) {
                alert('There was some error');
                console.log(error);
            },
        });
    $('#ftp-alert').css("display", "block");
    return false;
});

email.php

    $sender = "sender@example.com";

if(mail('info@example.com', 'FTP', 'Test', $sender)) {
    echo 'sent mail';
    exit('exit1');
} else {
    echo 'error sending email';
    exit('exit2');
}

if (isset($_POST)) {
    exit('exit');
    ?>
    <script>console.log("received")</script>
<?php
}

?>

<div id="test"></div>
<script>console.log("received")</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try to check your mail server it must be configured properly to mail() function be workable.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda