404 error contact form bootstrap - php

After reading about every single forum post I still cannot figure out how to get my contact form to work correctly. I got the frontend part of it looking good but I am getting a 404 error every time I try to use it. Obviously, because of that none of the information submitted is getting through. Here is my code:
Here is my contact.php which has a
<script src="email/validation.js" type="text/javascript"></script>
at the top between the header
<div class="span12" id="divMain">
<div id="contact">
<h1>Contact Us</h1></div>
<h3 style="color:#FF6633;"><?php echo $_GET[msg];?></h3>
<hr>
<!--Start Contact form -->
<form name="enq" method="post" action="email/index.php" onsubmit="return
validation();">
<fieldset>
<input type="text" name="name" id="name" value="" class="input-block-level" placeholder="Name" />
<input type="text" name="email" id="email" value="" class="input-block-level" placeholder="Email" />
<textarea rows="9" name="message" id="message" class="input-block- levelplaceholder="Let's hear what you've got to say"> </textarea>
<div class="actions">
<input type="submit" value="Send" name="submit" id="submitButton" class="btn btn-success pull -right" title="Click here to submit your message!" />
</div>
</fieldset>
<hr>
</form>
<!--End Contact form -->
</div>
Next here is my validation.js
function validation()
{
var contactname=document.enq.name.value;
var name_exp=/^[A-Za-z\s]+$/;
if(contactname=='')
{
alert("Name Field Should Not Be Empty!");
document.enq.name.focus();
return false;
}
else if(!contactname.match(name_exp))
{
alert("Invalid Name field!");
document.enq.name.focus();
return false;
}
var email=document.enq.email.value;
//var email_exp=/^[A-Za-z0-9\.-_\$]+#[A-Za-z]+\.[a-z]{2,4}$/;
var email_exp=/^\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
if(email=='')
{
alert("Please Enter Email-Id!");
document.enq.email.focus();
return false;
}
else if(!email.match(email_exp))
{
alert("Invalid Email ID !");
document.enq.email.focus();
return false;
}
var message=document.enq.message.value;
if(message=='')
{
alert("Query Field Should Not Be Empty!");
document.enq.message.focus();
return false;
}
return true; }
Followed by my index.php
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$query = $_POST['message'];
$email_from = $name.'<'.$email.'>';
$to="marketing#durangoconnections.com";
$subject="Enquiry!";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$email_from."\r\n";
$message="
Name:
$name
<br>
Email-Id:
$email
<br>
Message:
$query
";
if(mail($to,$subject,$message,$headers))
header("Location:../contact.php?msg=Successful Submission! Thankyou for contacting us.");
else
header("Location:../contact.php?msg=Error To send Email !");
//contact:-your-email#your-domain.com
}
?>

You dont have a contact.php file on your server, you mean contact_us.php
if(mail($to,$subject,$message,$headers))
header("Location:../contact_us.php?msg=Successful Submission! Thankyou for contacting us.");
else
header("Location:../contact_us.php?msg=Error To send Email !");
//contact:-your-email#your-domain.com
}

Related

How to check return value of mail() using Ajax

Im getting success from Ajax but not receiving the intended email and there does not seem to be anything wrong with the PHP. I have little experience with PHP, I need some way to get some feedback from the PHP.
Jquery
function PHP_EMAIL(name, email, message){
var emailInfo = [name,email,message];
$.ajax ({
type: "POST",
url:"the_php_file.php",
data: {email_info_array: emailInfo},
success: function(data) {
alert(data); <---alerts the entire php script back
alert("Email was successfuly sent!); <<<--- alerts success!
but no email recieved
}
});
}
PHP
$email_info = json_decode($_POST['email_info_array']);
$to = "my_email#gmail.com";
$subject = 'portfolio contact';
$user_name = $email_info[0];
$user_email = $email_info[1];
$message = $email_info[2];
$headers = "From: website.com";
$headers.= "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
if(mail($to,$subject,$message,$headers))
{
echo "sent";
}
else
{
echo "fail";
}
HTML
<div class="site-contact-box site-text-20 site-text-grey-violet">
<!-- form -->
<form onsubmit="return false" id="emailform">
<div class="site-form-error">* You must fill all fields of the form *</div>
<br> Name <input type="text" name="name" value="" required> <div class="site-name-error site-text-12"> * invalid name </div>
<br> E-mail <input type="text" name="email" value="john.doe#example.com" required> <div class="site-email-error site-text-12"> * invalid email </div>
<br>
<div class="site-message-error site-text-12"> * message must be more than (8 characters) </div>
<br> <br> please leave a message...
<br> <p class="site-text-12"> (minimum 8 characters) <p>
<br>
<textarea rows="12" cols="50" name="message" form="emailform" required></textarea>
<br>
<div class="site-agree-error site-text-12"> you must agree to terms </div>
<br> <br>
<div class="site-agreement site-text-13 site-text-black">
* I agree to the Terms & Agreement <input type="checkbox" id="agree" required>
</div>
<br>
<input class="site-text-bold site-text-15" type="submit" name="submit" onclick="checkInput()">
</form>
</div>
<?php
header('Content-type: application/json');
echo json_encode($response_array);?>
query succeed or not.
if(mysql_query($query)){
$response_array['status'] = 'success';
}else {
$response_array['status'] = 'error';
}
On the client side:
success: function(data) {
if(data.status == 'success'){
alert("Thank you for subscribing!");
}else if(data.status == 'error'){
alert("Error on query!");
}
},

not working google recaptcha in my php website

I'm using bluehost as my web server.
I'm trying to implement reCAPTCHA into my email form for my website,
The mail is sent without passing through the recaptcha.
Below are some of the html codes.
<div class="letterbox">
<form method="post" name="enewsform" id="enewsform" action="enewsletter_ins.php">
<h3 class="tit2">Subscribe To Newsletter</h3>
<div style="margin-top:10px;">
<label class="tit2">Name
<input type="text" name="name" value="" /></label>
<label class="tit2">Email Address
<input type="text" name="email" value="" /></label></br>
<div class="g-recaptcha" data-sitekey="itmysitekey!!"></div>
<input type="button" value="subscribe" class="btn_letter" onclick="sendData(document.enewsform)" />
</div>
</form>
<script type="text/javascript">
<!--
function sendData(f){
if(f.name.value==""){
alert("Required to name.");
f.name.focus();
return false;
}
if(f.email.value==""){
alert("Required to email.");
f.email.focus();
return false;
}
if (f.email.value.search(/(\S+)#(\S+)\.(\S+)/) == -1 ) {
alert("Not Valid Email.");
f.email.focus();
return false;
}
f.submit();
}
//-->
</script>
Below are some of the php codes.
<?
include_once $_SERVER[DOCUMENT_ROOT]."/include/initiate.php";
if(trim($name)=="" or trim($email)==""){
alert("send errer!!");
}
$form_title=$name." 님의 Subscribe to eNewsletter 신청";
$user_name=$name;
$user_email=$email;
$body="
date : ".date("Y-m-d H:i:s")."
<hr>
Name : $name
<hr>
E-Mail : $email
";
$sql = "
insert into prd_form_data set
form_type = '3',
form_title = '".$form_title."',
user_name = '".$user_name."',
user_email = '".$user_email."',
user_content = '".$body."',
insdt = now()
";
mysql_query($sql) or error(mysql_error());
//메일발송
$comments = $body;
$mailTo = ADMIN_MAIL; // 받는 메일 주소;
$mailFrom = "inquiry#example.com"; //
$mailSubject = "Subscribe to eNewsletter";
$mailContent = $comments;
$mailHeader = "From: $mailFrom\r\n";
$mailHeader .= "MIME-Version: 1.0\r\n";
$mailHeader .= "Content-type: text/html; charset=utf-8\r\n";
$mailResult = mail ($mailTo, $mailSubject, $mailContent, $mailHeader,'-f'.$mailFrom);
?>
<form method="post" action="/" name="frm">
</form>
<script type="text/javascript">
<!--
alert("ok!!");
document.frm.submit();
//-->
</script>
function sendData(f){
if(f.name.value==""){
alert("Required to name.");
f.name.focus();
return false;
}
if(f.email.value==""){
alert("Required to email.");
f.email.focus();
return false;
}
if (f.email.value.search(/(\S+)#(\S+)\.(\S+)/) == -1 ) {
alert("Not Valid Email.");
f.email.focus();
return false;
}
if(document.forms["enewsform"]["g-recaptcha-response"].value==""){
alert("Please fill reCAPTCHA");
document.forms["enewsform"]["g-recaptcha-response"].focus();
return false;
}
f.submit();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://www.google.com/recaptcha/api.js"></script>
<div class="letterbox">
<form method="post" name="enewsform" id="enewsform" action="enewsletter_ins.php">
<h3 class="tit2">Subscribe To Newsletter</h3>
<div style="margin-top:10px;">
<label class="tit2">Name
<input type="text" name="name" value="" />
</label>
<br />
<label class="tit2">Email Address
<input type="text" name="email" value="" />
</label>
<br />
<div class="g-recaptcha" data-sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"></div>
<input type="button" value="subscribe" class="btn_letter" onclick="sendData(document.enewsform)" />
</div>
</form>
</div>

jQuery.post not POSTing

I am trying to use jQuery to post data to an emailus.php script.
Here is the script part:
<script>
jQuery(document).ready(function(){
jQuery('#submitt').click(function(){
jQuery.post("/emailus.php", jQuery("#mycontactform").serialize(), function(response) {
jQuery('#success').html(response);
});
return false;
});
});
</script>
and here is the HTML used:
<form action="" method="get" id="mycontactform" >
<label for="name">Your Name:</label><br />
<input type="text" name="name" class="cleann" /><br />
<label for="email">Your Email:</label><br />
<input type="text" name="email" class="cleann" /><br />
<label for="message">Your Message:</label><br />
<textarea name="message" class="cleann" rows="7"></textarea><br />
<input type="button" value="send" id="submitt" class="cleannsubmit" /><div id="success" style="color:green;"></div>
</form>
and here is the php script:
<?php
// Here we get all the information from the fields sent over by the form.
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = 'nohanada#gmail.com';
$subject = 'Fortrove Contact';
$message = 'FROM: '.$name.' Email: '.$email.'Message: '.$message.'\n\nItem:'.$itemname;
print_r($_POST);
if($name && $email && $message){
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
mail($to, $subject, $message);
echo "Your email was sent!";
}
else echo "<span style='color:red'>Invalid email format.</span>";
}
else echo "<span style='color:red'>Please fill all fields</span>";
?>
Problem is that it does not POST the actual fields to the php script. What am i doing wrong?
you have placed the mycontactform inside product_addtocart_form that is the reason which is not allowed so the browser seems to be remocing the mycontactform

How to fix jQuery/PHP form submission?

I am updating a client site and the simple contact form that used to work is now broken. It appears that the HTML form sends and receives data from the jQuery file as I get the error messages returned, though it is not passing the data through to the PHP file for sending an email. If I send the data direct from the HTML form to the PHP file, then an email is sent. The error is probably at the end of the jQuery, though my search for how to fix has not revealed an answer. Any ideas on how to make this work?
HTML Form
<form id="rsForm" action="#" onsubmit="return goContact(this);" name="rsForm">
<input id="formNam" type="hidden" name="formNam" value="3" />
<div class="CU_row">
<div class="CU_form_title"><label for="firstName">First Name:</label></div>
<div class="CU_form_entry"><input id="firstName" maxlength="120" size="39" name="first" type="text" /> <span class="redT">*</span></div>
</div>
<div class="CU_row">
<div class="CU_form_title"><label for="lastName">Last Name:</label></div>
<div class="CU_form_entry"><input id="lastName" maxlength="120" size="39" name="last" type="text" /> <span class="redT">*</span></div>
</div>
<div class="CU_row">
<div class="CU_form_title"><label for="emailAddress">Email:</label></div>
<div class="CU_form_entry"><input id="emailAddress" maxlength="120" size="39" name="email" type="text" /> <span class="redT">*</span></div>
</div>
<div class="CU_row">
<div class="CU_form_title"><label for="subjectLine">Subject:</label></div>
<div class="CU_form_entry"><input id="subjectLine" maxlength="120" size="39" name="subject" type="text" /> <span class="redT">*</span></div>
</div>
<div class="CU_row">
<div class="CU_form_title"><label for="messageCopy">Message:</label></div>
<div class="CU_form_entry"><textarea id="messageCopy" rows="6" cols="30" name="message"></textarea> <span class="redT">*</span></div>
</div>
<div id="CU_reset"><input type="reset" value="Reset" /></div>
<div id="CU_submit"><input type="submit" name="Submit" value="Submit" /></div>
jQuery File
// JavaScript Document
function goContact(theForm){
//Validate the forms and create the array to send.
var frmName = theForm.formNam.value;
//Validate Common elements.
if(theForm.firstName.value.length < 1){
alert("You must supply a First Name");
theForm.firstName.focus();
return false;
}
if(theForm.lastName.value.length < 1){
alert("You must supply a Last Name");
theForm.lastName.focus();
return false;
}
if(theForm.email.value.length < 1){
alert("You must supply an Email");
theForm.email.focus();
return false;
}
if(theForm.subjectLine.value.length < 1){
alert("You must supply a Subject");
theForm.subjectLine.focus();
return false;
}
if(theForm.messageCopy.value.length < 1){
alert("You must supply a Message");
theForm.messageCopy.focus();
return false;
}
sendAjaxReq($(theForm).serialize(true));
return false;
}
function showResult(messageText){
//Show the pop up with the confirmation.
$('msgWindow').innerHTML = messageText;
$('rsForm').reset();
$('frmInter').hide();
}
function sendAjaxReq(formEms){
//Send he ajax request
var rSp = new Ajax.Request("includes/sendContact.php", {
method: 'get',
parameters: formEms,
onComplete: receiveRespon});
}
function receiveRespon(oReq, JSONRsp){
//Receive the response from the ajax request.\
var result = JSONRsp;
if(result){
showResult(result);
}
}
PHP File
<?php
if(isset($_GET['Submit'])){
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: no-reply#sitename.com' . "\r\n";
'X-Mailer: PHP/' . phpversion();
$to = "info#sitename.com";
$subject = "Inquiry from " . $_SERVER['HTTP_HOST'];
$message = "A client has sent a contact us email\n\n";
foreach($_GET AS $field => $value) {
$message .= "field = $field, value = $value \n\n";
}
$mailSent = mail($to, $subject, $message, $headers);
$arr = "Your message has been received.";
header('X-JSON: ('.json_encode($arr).')');
}
?>

Html5 contact form - issues with javascript and php validation

Before I begin please except my appologises if this is to long, I'm totaly new to Html5 (usually design in Flash)and just getting started. I recently downloaded a free template called Brownie and understand most things but the contact form. It's using Javascript, PHP and Ajax I think. Ive got it kinda workin locally but things aren't working how I want. What I'm trying to do is make it validate fields with error message or success message e.t.c. this is the html form code I have:
<p class="required_info"><span>*</span> Required</p>
<!-- SUCCESS MESSAGE -->
<div class="success_box none"> Email successfully sent. Thank you! </div>
<!-- END SUCCESS MESSAGE -->
<!-- START CONTACT FORM -->
<form action="#" class="contact_form">
<p>
<label for="name">Name <span>*</span></label>
<input type="text" class="inputText" id="name" name="name" placeholder="Please enter your full name" pattern="[a-zA-Z ]+" onkeypress="return alpha(event,letters)" required minlength="5" maxlength="50" onpaste="return false;" tabindex="1"/>
<div class="success_title none"> You've entered your name. </div>
<div class="error_title none">* Please enter your full name. </div>
</p>
<div class="clear"></div>
<p>
<label for="company">Company </label>
<input type="text" class="inputText" id="company" name="company" placeholder="Company Name" minlength="3" maxlength="50" onpaste="return false;" tabindex="2"/>
</p>
<div class="clear"></div>
<p>
<label for="email">E-mail <span>*</span></label>
<input type="text" class="inputText" id="email" name="email" placeholder="Please enter a valid email address" required minlength="5" maxlength="50" onpaste="return false;" tabindex="3"/>
<div class="error_title none">* Please enter a valid email. </div>
</p>
<div class="clear"></div>
<p>
<label for="message">Message <span>*</span></label>
<textarea class="inputTextarea" cols="88" rows="6" id="message" name="message" placeholder="Please enter your message" required tabindex="4"></textarea>
<div class="error_title none">* Please enter your message. </div>
</p>
<div class="clear padding20"></div>
<p class="submit"><input type="reset" class="resetBtn button white" onclick="resetFields()" value="Reset" /> Send </p>
</form>
<!-- END CONTACT FORM -->
<!-- ERROR MESSAGE -->
<div class="error_box none"> Please complete all required fields [ highlighted in red ]. </div>
<!-- END ERROR MESSAGE -->
and this is the javascript code:
$(document).ready(function () {
$('#name').focus(function () {
$(this).removeClass('error_class');
});
$('#email').focus(function () {
$(this).removeClass('error_class');
});
$('#message').focus(function () {
$(this).removeClass('error_class');
});
$('.contact_form').submit(function () {
hasError = false;
if ($('#name').val() == '') {
$('#name').addClass('error_class');
hasError = true;
}
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
var emailaddressVal = $('#email').val();
if (emailaddressVal == '') {
$('#email').addClass('error_class');
hasError = true;
}
else if (!emailReg.test(emailaddressVal)) {
$('#email').addClass('error_class');
hasError = true;
}
if ($('#email').val() == '') {
$('#email').addClass('error_class');
hasError = true;
}
if ($('#message').val() == '') {
$('#message').addClass('error_class');
hasError = true;
}
if (hasError == true) {
$('.info_box').hide();
$('.error_box').show();
$('.error_title').show();
}
else {
$.ajax({
type: 'POST',
url: 'contact.php',
cache: false,
data: $(".contact_form").serialize(),
success: function (data) {
if (data == "error") {
$('.success_box').hide();
$('.success_title').hide();
$('.error_box').show();
$('.error_title').show();
}
else {
$('.error_box').hide();
$('.error_title').hide();
$('.success_box').show();
$('.success_title').hide();
$('.resetBtn').hide();
$('.submit').hide();
}
}
});
}
return false;
});
});
This is the PHP code:
<?php
$your_email = 'name#domain.com'; // Your email address
$subject = 'Email from your contact form'; // Email subject
$name = isset($_POST['name']) && $_POST['name'] ? $_POST['name'] : ''; // Visitor Name
$company = isset($_POST['company']) && $_POST['company'] ? $_POST['company'] : ''; // Visitor Company
$email = isset($_POST['email']) && $_POST['email'] ? $_POST['email'] : ''; // Visitor Email
$message = isset($_POST['message']) && $_POST['message'] ? $_POST['message'] : ''; // Visitor Message
$website = isset($_POST['website']) && $_POST['website'] ? $_POST['website'] : ''; // Visitor Message
$full_message = 'Website: '.$website. "\r\n\r\n Message:".$message;
if($name && $email && $message)
{
$headers = 'From: '.$name.' <'.$email.'>' . "\r\n" .
'Reply-To: '.$email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
//------------------------------------------------
// Send out email to site admin
//------------------------------------------------
if(#mail($your_email, $subject, $full_message, $headers))
die("success");
else
die("error");
}
else
{
die("error");
}
?>
When the send button is pressed i want it to check if any data has been entered in each input field - if yes add success message if no add error message. I have the error message working but cant get the success message working on individual input fields. Any sugestions would be helpful...
I suspect it is because you are assigning true or false to each variable instead of the value of the variable in your php script. Isset($_POST[test]) is true, not the value of the test form value.

Categories