NEW - discovered that I have a javascript validating and submitting the form on my website - have added the relevant js
Hope someone can help! I am not a coder but stitch together elements to achieve my ends. Have a web form and am using PHP to submit to my email but it is not happening. Email is not sending and the success or failure text is not appearing - Solutions please.
Website is www.ogracing.eu
HTML
<!-- CONTACT FORM -->
<div class="col-sm-7 col-md-9">
<!-- IMPORTANT: change the email address at the top of the php/mail.php file to the email address that you want this form to send to -->
<form class="form-style validate-form clearfix" action="php/mail.php" method="POST" role="form">
<!-- form left col -->
<div class="col-md-6">
<div class="form-group">
<input class="text-field form-control validate-field required" data-validation-type="string" id="name" placeholder="Name" name="name" type="text">
</div>
<div class="form-group">
<input class="text-field form-control validate-field required" data-validation-type="email" id="email" placeholder="Email" name="email" type="email">
</div>
<div class="form-group">
<input class="text-field form-control validate-field required" data-validation-type="phone" id="phone" placeholder="Telephone" name="phone" type="tel">
</div>
</div><!-- end: form left col -->
<!-- form right col -->
<div class="col-md-6">
<div class="form-group">
<textarea placeholder="Message..." class="form-control validate-field required" name="message"></textarea>
</div>
<div class="form-group">
<img src="images/loader-form.GIF" class="form-loader">
<button type="submit" name="submit" class="btn btn-sm btn-outline-inverse">Submit</button>
</div>
<div class="form-group form-general-error-container">
<?php echo $result; ?>
</div>
</div><!-- end: form right col -->
</form>
</div><!-- end: CONTACT FORM -->
JS this is only the validate and submit portion of the script - functions.js. I have removed the captcha elemnts from the HTML as I did not want to leave it in - this may or may not be causing a validation issue.
function validate_and_submit_forms(b){var a=(b!==undefined&&b.length>0)?b:$("form.validate-form");a.each(function(){var
c=$(this);c.find(".validate-field").each(function(){$(this).change(function(){$(this).siblings(".alert").fadeOut("fast",function()
{$(this).remove()});if($(this).val().trim()!=""){var e=validate_fields(c,$(this));if(e.length>0){if(e[0]["message"]!==undefined&&e[0]
["message"]!=""&&e[0]["message"]!="success"){var d='<div class="alert">'+e[0]["message"]+"</div>";$(this).after(d);$(this).siblings
(".alert").fadeIn("fast")}}}})});c.find("#form-captcha-refresh").click(function(){reset_captcha(c)});c.submit(function(e)
{e.preventDefault?e.preventDefault():e.returnValue=false;$(this).find(".form-loader").fadeIn("fast");var d=$(this).attr("action");if
(d===undefined&&d==""){return false}$(this).find(".alert").fadeOut("fast",function(){$(this).remove()});$(this).find(".form-general-
error-container").fadeOut("fast",function(){$(this).empty()});var f=false;$(this).find(".validate-field").each(function(){var
h=validate_fields(c,$(this));if(h.length>0){if(h[0]["message"]!==undefined&&h[0]["message"]!=""&&h[0]["message"]!="success"){var
g='<div class="alert">'+h[0]["message"]+"</div>";$(this).after(g);$(this).siblings(".alert").fadeIn("fast");f=true}}});if(f==true)
{$(this).find(".form-loader").fadeOut("fast");return false}$.ajax({type:"POST",url:d,data:$(this).serialize
(),dataType:"html",success:function(k){c.find(".form-loader").fadeOut("fast");var l=(k=="success")?true:false;var h=(k=="captcha")?
false:true;var g="";switch(k){case"success":g="Form submitted successfully.";break;case"captcha":g="Incorrect text entered. (Case-
sensitive)";break;case"incomplete":g="Please fill in all required fields.";break;case"error":g="An error occured. Please try again
later.";break}var j='<div class="alert ';j+=(l==true)?"success":"error";j+='">'+g+"</div>";if(!h){c.find("#form-captcha").parent
(".form-group").append(j);c.find("#form-captcha").siblings(".alert").fadeIn("fast")}else{c.find(".form-general-error-container").html
(j).fadeIn("fast",function(){$(this).delay(10000).fadeOut("fast",function(){$(this).html("")})})}reset_captcha(c);if(l==true){c.find
(".form-control").val("")}},error:function(h){c.find(".form-loader").fadeOut("fast");var g='<div class="alert">An error occured. Please
try again later.</div>';c.find(".form-general-error-container").html(g).fadeIn("fast")}})})})}function reset_forms(b){if(b!
==undefined&&b.length>0){var a=b;a.find("input").val("");a.find(".alert").remove();a.find(".form-general-error-container").empty
().hide();reset_captcha(b)}}function reset_captcha(b){var a=(b!==undefined&&b.length>0)?b:$("form.validate-form");a.each(function(){var
e=$(this);var c=e.find("#form-captcha-img");if(c.length>0&&e.is(":visible")){var f=new Date().getTime();c.replaceWith('<img id="form-
captcha-img" src="assets/php/form_captcha/captcha_img.php?t='+f+'" style="display:none">');e.find("#form-captcha").val("");setTimeout
(function(){e.find("#form-captcha-img").show()},500)}})}function validate_fields(d,a){if(d!==undefined&&d.length>0){var b=(a!
==undefined&&a.length>0)?a:d.find(".validate");var c=new Array();b.each(function(){var e=$(this).attr("data-validation-type");var
h=$(this).hasClass("required");var g=$(this).val().trim();var f=new Array();f.field_object=$(this);f.message="success";if(h==true&&
(g==""||g===null||g===undefined)){f.message="This field is required"}if(e=="string"&&(g!=""&&g!==null&&g!==undefined)){if(g.match(/^[a
-z0-9 .\-]+$/i)==null){f.message="Invalid characters found."}}else{if(e=="email"&&(g!=""&&g!==null&&g!==undefined)){if(g.match(/^
(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]
+\.)+[a-zA-Z]{2,}))$/)==null){f.message="Please enter a valid email address."}}else{if(e=="phone"&&(g!=""&&g!==null&&g!==undefined))
{if(g.match(/^\(?\+?[\d\(\-\s\)]+$/)==null){f.message="Invalid characters found."}}}}c.push(f)});return c}}function
contact_form_IE9_placeholder_fix(){var a=$("form");a.each(function(){var b=$(this);$(this).find(".form-control").each(function(){var
c=$(this).attr("placeholder");if(c!==undefined&&c!=""){$(this).val(c);$(this).focus(function(){if($(this).val()==c){$(this).val
("")}});$(this).blur(function(){if($(this).val()==""){$(this).val(c)}})}})})}function change_bg_check(){return
((jQuery.browser.mobile&&background_settings.change_on_mobile)||(!jQuery.browser.mobile&&background_settings.change_on_nonmobile))?
true:false}function tabs_uniform_height(){var g=$(".tabpanel.uniform-height");for(var f=0,a=g.length;f<a;f++){var e=0;var h=$(g
[f]).find(".tab-pane");for(var d=0,b=h.length;d<b;d++){var c=$(h[d]).attr("style");$(h[d]).css
({position:"absolute",visibility:"hidden",display:"block"});e=($(h[d]).outerHeight(true)>e)?$(h[d]).outerHeight(true):e;$(h[d]).attr
("style",c?c:"")
}h.css({"min-height":e+"px"})}};
PHP
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$from = 'Contact Form';
$to = 'race@ogracing.eu';
$subject = 'Message from website ';
$body = "From: $name\n E-Mail: $email\n Telephone: $phone\n message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
//Check if telephone number has been entered
if (!$_POST['phone']) {
$errMessage = 'Please enter a telephone number';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errPhone && !$errMessage) {
if (mail($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
}
else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
Update
I have found some responses from my mail.php - shown below. These are appearing in a window within firebug!!
Response headers
- Content-Length 0
- Content-Type text/html
- Date Fri, 21 Aug 2015 11:14:10 GMT
- Server Microsoft-IIS/8.5
- X-Powered-By-Plesk PleskWin
- x-powered-by ASP.NET
Request headers
- Accept text/html, /; q=0.01
- Accept-Encoding gzip, deflate
- Accept-Language en,en-US;q=0.5 Content-Length 69
- Content-Type application/x-www-form-urlencoded; charset=UTF-8
- Cookie _ga=GA1.2.1848665366.1439996290
- DNT 1 Host www.ogracing.eu
- Referer http://www.ogracing.eu/
- User-Agent Mozilla/5.0 (Windows NT 6.0; rv:40.0) Gecko/20100101 Firefox/40.0 X-
- Requested-With XMLHttpRequest
Post
- email aidan@pulce.co.uk
- message more
- name Aidans analytics
- phone 56
- Source name=Aidans+analytics&email=aidan%40pulce.co.uk&phone=56&message=more
HTML Nothing Nada and Nix - guess this is part of the problem
Cookies are being sent
So it appears we are not generating any HTML for the email thus it is not being sent. Any more help and advice is welcome. Thanks.