Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda