I will probably get a duplicate, but I searched and searched, and I can not find someone experiencing the same problem with the same syntax, so hopefully someone can see something that I do not see. PHP is not my strong suit, but I went through several tutorials and classes and did a lot of work trying to improve, which is why it annoys me so much. I have a pretty simple html form that I am trying to email via php. I found another way to accomplish this from what I used to use, and wanted to give it a chance. It seems that everything works as a function works (I tested with console.log, alert and a popup, well, a popup, so "success" works in a PHP file if I am not mistaken. As a result, the problem with my problems is that I never receive an email from the form (I put a dummy email address for the purpose of requesting this question).
I know that I do not have the action = "something.php" form or function call directly from the form, but from what I understand from this method, is that everything works when it is served. Again, since everything seems to be functioning, but by email, I'm not sure what the deal is.
I would like to see if more experienced eyes can find what I am missing. The hosting provider is Godaddy, if that matters. Thank you so much for any help anyone can offer.
Here is my html (page is a .php extension):
<form class="main-contact-form" id="main-contact-form"> <div class="row"> <div class="col-md-6"> <input id="first-name" name="firstName" type="text" placeholder="First Name (Required)" onfocus="this.placeholder = ''" onblur="this.placeholder = 'First Name (Required)'" /> </div> <div class="col-md-6"> <input id="last-name" name="lastName" type="text" placeholder="Last Name (Required)" onfocus="this.placeholder= ''" onblur="this.placeholder= 'Last Name (Required)'" /> </div> <div class="col-md-6"> <input id="email" name="email" type="email" placeholder="Email (Required)" onfocus="this.placeholder= ''" onblur= "this.placeholder= 'Email (Required)'" /> </div> <div class="col-md-6"> <input id="phone" name="phone" type="phone" placeholder= "Phone Number" onfocus= "this.placeholder= ''" onblur="this.placeholder= 'Phone Number'" /> </div> <div class="col-md-6"> <input id="company" name="company" type="text" placeholder="Company" onfocus="this.placeholder= ''" onblur= "this.placeholder= 'Company'" /> </div> <div class="col-md-6"> <select id="contact-type" name="contactType"> <option value="" selected>I'd like to...</option> <option class="contact-option" value="Contact sales">Contact sales</option> <option value="Get a quote">Get a quote</option> <option value="Contact customer service">Contact customer service</option> </select> </div> <div class="col-12"> <textarea id="message" placeholder="What can we do for you?" onfocus="this.placeholder= ''" onblur="this.placeholder= 'What can we do for you?'" /></textarea> </div> <div class="col-md-6 push-md-3"> <button type="submit">Submit</button> </div> </div> </form>
Here is my js code:
var contactForm = $("#main-contact-form"); contactForm.submit(function(event) { event.preventDefault(); submitForm(); }); function submitForm() { var firstName = $("#first-name"); var lastName = $("#last-name"); var email = $("#email"); var phone = $("#phone"); var company = $("#company"); var contactType = $("#contact-type"); var message = $("#message"); $.ajax({ type: "POST", url: "php/main-contact-form.php", data: "firstName=" + firstName + "&lastName" + lastName + "&email" + email + "&phone" + phone + "&company" + company + "&contactType" + contactType + "&message" + message, success: function(text) { if (text == "success"){ formSuccess(); } } }); } var contactSuccess = $(".contact-submission-success") function formSuccess(){ contactSuccess.addClass("show", 200); } });
Here is my php code:
<?php $firstName = $_POST["firstName"]; $lastName = $_POST["lastName"]; $email = $_POST["email"]; $phone = $_POST["phone"]; $company = $_POST["company"]; $contactType = $_POST["contactType"]; $message = $_POST["message"]; $EmailTo = " fakeemail@fakeemail.com "; $subject = "New Contact Form Message Received"; $Body .= "First Name: "; $Body .= $firstName; $Body .= "\n"; $Body .= "Last Name: "; $Body .= $lastName; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $Body .= "Phone: "; $Body .= $phone; $Body .= "\n"; $Body .= "Company: "; $Body .= $company; $Body .= "\n"; $Body .= "Contact Type: "; $Body .= $contactType; $Body .= "\n"; $Body .= "Message: "; $Body .= $message; $Body .= "\n"; $success = mail($EmailTo, $Subject, $Body, "From:".$email); if ($success) { echo "success"; } else { echo "invalid"; } ?>