0

I tried about a million things on the internet to get this working but I am just stumped. I can't figure out why it doesn't send a mail anymore.

It gives an alert just like a wanted it to do, but the mail doesn't send to my email.

Here is my code:

<script>
        $(document).ready(function(){
        $("#contact-form").on("submit", function(e){
                e.preventDefault();
            dataString = jQuery('form#contact-form').serialize();
            jQuery.ajax({
                type: "POST",
                url: "mail.php",
                data: dataString,
                success:  function(data)
                { 
                    alert('Form successfully submitted.');
                },
                error:  function(data)
                { 
                    
                }
            }); 
        });
        });
       
       
       
    </script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<form id="contact-form" name="contactform" method="POST">

<input contenteditable="true" style="width:68%;" maxlength="32" placeholder="" class="contact_input" name="name" id="naam" required/></h2>

<input contenteditable="true" style="width:100%;" maxlength="512" placeholder="" class="contact_input" name="message" id="onderwerp" required/></h2>

<input contenteditable="true" maxlength="50" style="width:47.5%;" placeholder="" class="contact_input" name="email" id="contact1" required/> en

<input contenteditable="true" maxlength="50" style="width:92.7%;" placeholder="" class="contact_input" name="contact2" id="contact2"/></h2>

<h3><input type="submit" id="submit-button" value="groetjes" class="btn btn-primary"></h3>
 
 </form>

Mail.php

<?php
$name = $_POST['name'];
$contact1 = $_POST['email'];
$contact2 = $_POST['contact2'];
$inhoud = $_POST['message'];
        
        
$to = "";
$subject = "Contactform";
$from = "";

$message = "";
$headers = "From:" . $from;
            
mail($to, $subject, $message, $headers);
Community
  • 1
  • 1
  • have you tried alerting/console-logging the acutal data instead of a selfdefined string? Also, your $to and $from variables in mail.php are empty.. – kscherrer Feb 17 '17 at 15:40
  • All the console logs look normal, nothing weird. Also I made the to and from variables empty only here for privacy. They are not really empty tho. – Jordy Senssen Feb 17 '17 at 15:43
  • check out the question that yours was marked as a duplicate. it has many useful tips. – kscherrer Feb 17 '17 at 15:45
  • that is not the problem tho. Without the AJAX part it does send email. So I'm actually 99% sure it's in the ajax part and that is not covered in that question. – Jordy Senssen Feb 17 '17 at 15:49
  • Im not sure how the serialization of the form works with sending post variable. try to print_r $_POST in your mail.php so that in the ajax success you can wee how the variables arrive in the php script – kscherrer Feb 17 '17 at 16:15

0 Answers0