0

So I have an HTML form inside of a Bootstrap modal that I want to send to my email. I have my HTML form pointing to a PHP file named "send_form_email.php" inside of a "php" folder however, once I click "submit" in the form it redirects me to the success page, but the email doesn't appear in my email. I have checked to make sure the email address is correct multiple times and even used a different email address, I also checked my spam folder each time and it isn't there either. Below is my code:

HTML:

<form action="php/send_form_email.php" method="post">
     First Name: <input type="text" name="first_name" required><br>
     Last Name: <input type="text" name="last_name" required><br>
     Email: <input type="text" name="email" required><br>
     Message:<br>
     <textarea rows="5" name="message" cols="30" required></textarea>
     <br>
     <input type="submit" name="submit" value="Submit">
</form>

PHP:

<?php 
if(isset($_POST['submit'])){
    $to = "info@myemail.com"; // changed address for example purposes but put my email in here
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $subject = "Form submission";
    $subject2 = "Copy of your form submission";
    $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
?>

Any Ideas as to why the email will not send?

0 Answers0