-1

Based on this solution, I have created a form for my landing page, and I expected it to work, but I don't see where it is failing, as nothing happens (no mail sent and no echo message) when you click on the button.

PHP (form.php):

   <?php
   if (isset($_POST['submit'])) {
    $to         = "my@email.com"; 
    $from       = $email; 
    $first_name = $_POST['first_name'];
    $phone      = $_POST['phone'];
    $email      = $_POST['email'];
    $subject    = "Nuevo lead";
    $message    = $first_name . " " . $phone . " " . $email . " wrote the following:" . "\n\n";
    $headers    = "From:" . $from;
    mail($to, $subject, $message, $headers);
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
}
?>

HTML:

<form action="form.php" method="post" id="mc-embedded-subscribe-form" 
      name="mc-embedded-subscribe-form" class="validate">

    <div id="mc_embed_signup_scroll">
        <div class="flex-md-wrap">
            <div class="mc-field-group flex-md-1">
                <input type="text" value="" name="first_name" id="mce-FNAME" placeholder="Nombre" autocomplete='given-name'>
            </div>
            <div class="mc-field-group flex-md-1">
                <input type="email" value="" name="email" id="mce-EMAIL" placeholder="Email" autocomplete='email'>
            </div>
            <div class="mc-field-group flex-md-1">
                <input type="number" value="" name="phone" id="mce-PHONE" placeholder="Teléfono" autocomplete='tel'>
            </div>
            <div class="mc-field-group">
                <input type="submit" value="ENVIAR" name="submit" id="mc-embedded-subscribe" class="btn btn--secondary">
            </div>
        </div>
    </div>
</form>

Does anyone have a clue on what is going on?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
anxoestevez
  • 190
  • 2
  • 18

2 Answers2

1

Your form submit seems OK but as you've not enabled error reporting that's why undefined variable issue of $email variable is not visible to you and I assume this is causing you the problem.

To enable error reporting, add this line at the top your form.php file.

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Also move this line $from = $email; after $email = $_POST['email'];

$email = $_POST['email'];
$from  = $email;
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
0

I went to your site. Clicking the link sends back a 404 error with this message through dev tools:

Not Found

The requested URL /form.php&c=jQuery19008959887418623141_1563041041943&first_name=Geoger+&email=bill@bigboy.com&phone=3&submit=ENVIAR was not found on this server.

Error is pretty self-explanatory - either you don't have the file created, its named wrong, its in the wrong folder for the server to find, your routing isn't pointing to the right file / path, etc. Your form on that page is working, the button is working.

While your code may be correct, and you may have followed the solution perfectly, you need more than just the code - you need the infrastructure behind it for the back-end PHP, and to have it all wired up correctly. Even if the code is perfect, if the server can't find the file, it will always 'do nothing'.

Your site looks fantastic, by the way, just need to do some research on those infrastructure points I think.

Watercayman
  • 7,970
  • 10
  • 31
  • 49