I'm working on a simple single page site from a template. The contact from had only name email and message body. I tried adding the number. It shows up on the page, and the line shows up in the email, but the number does not actually come through.
Ive copied and pasted the existing code for one of the other data points and changed the id, type etc. for the phone number.
The page is live on test.wotactical.com
EDIT: Added the javascript code
PHP
<?php
// Put contacting email here
$php_main_email = "ffl#wotactical.com";
$php_sending_email = "contact#wotactical.com";
//Fetching Values from URL
$php_name = $_POST['ajax_name'];
$php_email = $_POST['ajax_email'];
$php_phone = $_POST['ajax_phone'];
$php_message = $_POST['ajax_message'];
//Sanitizing email
$php_email = filter_var($php_email, FILTER_SANITIZE_EMAIL);
//After sanitization Validation is performed
if (filter_var($php_email, FILTER_VALIDATE_EMAIL)) {
$php_subject = "New WOtactical contact form from " . $php_name;
// To send HTML mail, the Content-type header must be set
$php_headers = 'MIME-Version: 1.0' . "\r\n";
$php_headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$php_headers .= 'From:' . $php_sending_email. "\r\n"; // Sender's Email
$php_headers .= 'Cc:' . $php_email. "\r\n"; // Carbon copy to Sender
$php_template = '<div style="padding:50px;">Hello ' . $php_name . ',<br/>'
. 'Thank you for contacting us.<br/><br/>'
. '<strong style="color:#f00a77;">Name:</strong> ' . $php_name . '<br/>'
. '<strong style="color:#f00a77;">Number:</strong> ' . $php_phone . '<br/>'
. '<strong style="color:#f00a77;">Email:</strong> ' . $php_email . '<br/>'
. '<strong style="color:#f00a77;">Message:</strong> ' . $php_message . '<br/><br/>'
. 'This is a Contact Confirmation mail.'
. '<br/>'
. 'We will contact you as soon as possible .</div>';
$php_sendmessage = "<div style=\"background-color:#f5f5f5; color:#333;\">" . $php_template . "</div>";
// message lines should not exceed 70 characters (PHP rule), so wrap it
$php_sendmessage = wordwrap($php_sendmessage, 70);
// Send mail by PHP Mail Function
mail($php_main_email, $php_subject, $php_sendmessage, $php_headers);
echo "";
} else {
echo "<span class='contact_error'>* Invalid email *</span>";
}
?>
HTML
<!-- CONTACT1 -->
<div class="edina_tm_section" id="contact">
<div class="edina_tm_main_title_holder_wrap contact">
<div class="number_wrap">
<span>06</span>
</div>
<div class="title_wrap">
<span>Contact Form</span>
</div>
</div>
<div class="edina_tm_contact_wrap">
<div class="short_info">
<div class="container">
<div class="subtitle">
<p class="wow fadeIn" data-wow-duration="1.2s">Special order, FFL Transfer, consignment or just have questions? We're happy to help.</p>
</div>
</div>
</div>
<div class="main_input_wrap">
<form action="/" method="post" class="contact_form" id="contact_form">
<div class="returnmessage" data-success="Your message has been received, We will contact you soon."></div>
<div class="empty_notice"><span>Please Fill Required Fields</span></div>
<div class="wrap wow fadeIn" data-wow-duration="1.2s" data-wow-delay="0.2s">
<input id="name" type="text" placeholder="Your Name">
</div>
<div class="wrap wow fadeIn" data-wow-duration="1.2s" data-wow-delay="0.4s">
<input id="email" type="text" placeholder="Your Email">
</div>
<div class="wrap wow fadeIn" data-wow-duration="1.2s" data-wow-delay="0.4s">
<input id="phone" type="tel" placeholder="Contact Number ex 123-456-7890" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}"
required>
</div>
<div class="wrap wow fadeIn" data-wow-duration="1.2s" data-wow-delay="0.6s">
<textarea id="message" placeholder="Type of inquiry, and/or details"></textarea>
</div>
<div class="edina_tm_button wow fadeIn" data-wow-duration="1.2s" data-wow-delay="0.8s">
<a id="send_message" href="#">Send Message</a>
</div>
</form>
</div>
</div>
</div>
<!-- /CONTACT1 -->
javascript
// -----------------------------------------------------
// ---------------- CONTACT FORM -----------------
// -----------------------------------------------------
function edina_tm_contact_form(){
"use strict";
jQuery(".contact_form #send_message").on('click', function(){
var name = jQuery(".contact_form #name").val();
var email = jQuery(".contact_form #email").val();
var phone = jQuery(".contact_form #phone").val();
var message = jQuery(".contact_form #message").val();
var subject = jQuery(".contact_form #subject").val();
var success = jQuery(".contact_form .returnmessage").data('success');
jQuery(".contact_form .returnmessage").empty(); //To empty previous error/success message.
//checking for blank fields
if(name===''||email===''||phone===''||message===''){
jQuery('div.empty_notice').slideDown(500).delay(2000).slideUp(500);
}
else{
// Returns successful data submission message when the entered information is stored in database.
jQuery.post("modal/contact.php",{ ajax_name: name, ajax_email: email, ajax_phone: phone, ajax_message:message, ajax_subject: subject}, function(data) {
jQuery(".contact_form .returnmessage").append(data);//Append returned message to message paragraph
if(jQuery(".contact_form .returnmessage span.contact_error").length){
jQuery(".contact_form .returnmessage").slideDown(500).delay(2000).slideUp(500);
}else{
jQuery(".contact_form .returnmessage").append("<span class='contact_success'>"+ success +"</span>");
jQuery(".contact_form .returnmessage").slideDown(500).delay(4000).slideUp(500);
}
if(data===""){
jQuery("#contact_form")[0].reset();//To reset form fields on success
}
});
}
return false;
});
}
I'm guessing that if you might remove your regex pattern:
pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}"
here in this element:
<div class="wrap wow fadeIn" data-wow-duration="1.2s" data-wow-delay="0.4s">
<input id="phone" type="tel" placeholder="Contact Number ex 123-456-7890" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}"
required>
and change it to just:
<div class="wrap wow fadeIn" data-wow-duration="1.2s" data-wow-delay="0.4s">
<input id="phone" type="tel" placeholder="Contact Number ex 123-456-7890" required>
and test it, it would likely work. Or you might just test it with a 888-888-8888 number and see if it would work.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
HTML for my fields and contact block, my fields are Name, Number. Email, Subject, Message. All of my fields work properly and when submitted I receive the email perfectly, apart from the Number field which for some reason does not populate with the amount or any value at all
<!-- contact section -->
<div class="container">
<div class="section-header">
<h2 class="wow fadeInDown animated">Contact Us</h2>
<p class="wow fadeInDown animated">Please fill in your contact details below and we will get back to you.<br>Alternatively contact us on: 031 464 4801 | 083 555 1202</p>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2 conForm">
<form method="post" action="php/email.php" name="cform" id="cform" onsubmit="return checkform(this);">
<div id="message"></div>
<input name="name" id="name" type="text" class="col-xs-12 col-sm-12 col-md-12 col-lg-12" placeholder="Your name..." >
<input name="cell" id="cell" type="number" class="col-xs-12 col-sm-12 col-md-12 col-lg-12" placeholder="Your Number..." >
<input name="email" id="email" type="email" class=" col-xs-12 col-sm-12 col-md-12 col-lg-12 noMarr" placeholder="Email Address..." >
<textarea name="comments" id="comments" cols="" rows="" class="col-xs-12 col-sm-12 col-md-12 col-lg-12" placeholder="Message..."></textarea>
<!-- START CAPTCHA -->
<br>
<div class="capbox">
<div id="CaptchaDiv"></div>
<div class="capbox-inner">
Type the above number:<br>
<input type="hidden" id="txtCaptcha">
<input type="text" name="CaptchaInput" id="CaptchaInput" size="15"><br>
</div>
</div>
<br><br>
<!-- END CAPTCHA -->
<input type="submit" id="submit" name="send" class="submitBnt" value="Send">
<div id="simple-msg"></div>
</form>
<script type="text/javascript">
// Captcha Script
function checkform(theform){
var why = "";
if(theform.CaptchaInput.value == ""){
why += "- Please Enter CAPTCHA Code.\n";
}
if(theform.CaptchaInput.value != ""){
if(ValidCaptcha(theform.CaptchaInput.value) == false){
why += "- The CAPTCHA Code Does Not Match.\n";
}
}
if(why != ""){
alert(why);
return false;
}
}
var a = Math.ceil(Math.random() * 9)+ '';
var b = Math.ceil(Math.random() * 9)+ '';
var c = Math.ceil(Math.random() * 9)+ '';
var d = Math.ceil(Math.random() * 9)+ '';
var e = Math.ceil(Math.random() * 9)+ '';
var code = a + b + c + d + e;
document.getElementById("txtCaptcha").value = code;
document.getElementById("CaptchaDiv").innerHTML = code;
// Validate input against the generated number
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('CaptchaInput').value);
if (str1 == str2){
return true;
}else{
return false;
}
}
// Remove the spaces from the entered and generated code
function removeSpaces(string){
return string.split(' ').join('');
}
</script>
</div>
</div>
</div>
This is the PHP which pushes the mail, values and email format through to my address, again, everything seems to be in order and works fine, apart from the number (cell) field, which does not populate with any information, no matter what you put into it.
<?php
session_cache_limiter( 'nocache' );
$to = "bjorn#tech5.co.za"; //Recipient's E-mail
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= 'Number: ' . $_REQUEST['cell'] . "<br>";
$message .= 'Email: ' . $_REQUEST['email'] . "<br>";
$message .= $_REQUEST['comments'];
if (#mail($to, 'New Inquiry from Executive Plant Hire', $message, $headers))
{
mail('bjorn#tech5.co.za', 'New Inquiry from Executive Plant Hire', $message, $headers);
// Transfer the value 'sent' to ajax function for showing success message.
echo '<label class="lbl lbl-success">Your email has been sent successfully, we will be in touch</label>';
// header('Location: ../index.html');
}
else
{
// Transfer the value 'failed' to ajax function for showing error message.
echo '<label class="lbl lbl-warning">There was a problem sending you request, please contact us directly</label>';
}
?>
Can anyone provide some assistance or advise what I might be doing wrong? I've tried everything I can think of and nothing seems to work... any help or suggestions would be much appreciated.
Thanks.
#Bjorn,
You can see here that entering any non-digit char (like a symbol that might go in a telephone number), will invalidate the number field.
<input type="number" id="check">
<button type="button" onclick="console.log(document.getElementById('check').value)">Check</button>
I design and developed one website in which I have one contact form. I wanted to send inquiry email through contact form. But I am getting following error in console. I tried on local system as well as on server.
Access to XMLHttpRequest at 'file:///E:/clients/website/contact.php' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
Here is my HTML Code :
<form id="contactform" action="contact.php" name="contactform" method="post" class="form-validation" autocomplete="off">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="single-input">
<input type="text" placeholder="First Name*" name="Fname" id="Fname">
</div> <!-- /.single-input -->
</div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="single-input">
<input type="text" placeholder="Last Name*" name="Lname" id="Lname">
</div> <!-- /.single-input -->
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
<div class="single-input">
<input type="email" placeholder="Your Email*" name="email" id="email">
</div> <!-- /.single-input -->
</div>
</div> <!-- /.row -->
<div class="single-input">
<input type="text" placeholder="Subject" name="sub" id="subject">
</div> <!-- /.single-input -->
<textarea placeholder="Write Message" name="message" id="message"></textarea>
<button type="submit" value="SEND" id="submit" class="tran3s p-color-bg">Send Message</button>
</form>
Here is contact.php
<?php
if(!$_POST) exit;
// Email address verification, do not edit.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(com|coop|cr|cs)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$Fname = $_POST['Fname'];
$Lname = $_POST['Lname'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
if(get_magic_quotes_gpc()) {
$message = stripslashes($message);
}
$address = "sales#abc.com";
$e_subject = 'You\'ve been contacted by ' . $Fname . '.';
$e_body = "You have been contacted by $Fname with regards to $subject, their additional message is as follows." . PHP_EOL . PHP_EOL;
$e_content = "\"$message\"" . PHP_EOL . PHP_EOL;
$e_reply = "You can contact $Fname via email, $email";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$Fname</strong>, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
XMLHttpRequest does not support file scheme.
You could try this:
Solution 1: Use http/https instead of local file.
I would never use the file protocol for server-side files, if you need to test your .php files locally, it's better to use a localhost (like XAMPP) and test your code.
Solution 2 (don't skip the solution 1): Try this if solution 1 didn't work, but please don't use the file protocol (otherwise it won't work anyway).
Try to add the following header to the HTTP response:
Access-Control-Allow-Origin: *
The header above will allow your scripts to read the response regardless of the origin.
Note: Don't use Access-Control-Allow-Origin: * on your production code, otherwise you're exposing your website to security vulnerabilities.
reCaptcha is sending messages without activating the reCaptcha and last night I received over 300 messages a boot.
Help me please how to add so that only sent when the button is activated reCaptcha. Send sends works well but not activation reCaptcha.
To start contact.html within my template I have put this way:
<!-- Start formulario de contacto -->
<div class="row">
<div class="col-md-9">
<h2>Formulario de contacto</h2>
<form action="php/contact-form.php" id="contact-form">
<div class="alert alert-success hidden" id="contact-alert-success">
<strong>Mensaje enviado correctamente!</strong> Muchas gracias, pronto nos pondremos en contacto con usted, normalmente nuestro tiempo de respuesta es inferior a 2 horas.
</div>
<div class="alert alert-danger hidden" id="contact-alert-error">
<strong>Error!</strong> A sucedido un error si lo desea puede contactarnos directamente en XXXX#tize.XXXX
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Nombre <span class="required">*</span></label>
<input type="text"
value=""
data-msg-required="Por favor introduzca su nombre"
class="form-control"
name="name" id="name">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>eMail <span class="required">*</span> </label>
<input type="email"
value=""
data-msg-required="Por favor introduzca su eMail"
data-msg-email="Por favor introduzca un eMail válido"
class="form-control"
name="email"
id="email">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Asunto <span class="required">*</span></label>
<input type="text"
value=""
data-msg-required="Por favor introduzca el asunto"
class="form-control"
name="subject"
id="subject">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Mensaje <span class="required">*</span></label>
<textarea
data-msg-required="Por favor introduzca su mensaje"
rows="10"
class="form-control"
name="message"
id="message"></textarea>
</div>
</div>
</div>
<!-- Start Google Recaptcha -->
<div class="g-recaptcha" data-sitekey="6Lc88P4SAAAAANiT-ZXILUo-ET4xQmbivHy7uHc8"></div><br>
<!-- End Google Recaptcha -->
<div class="row">
<div class="col-md-12">
<input type="submit" value="Enviar mensaje" class="btn btn-primary" data-loading-text="Cargando...">
</div>
</div>
</form>
</div>
<!-- End formulario de contacto -->
And in php form to send the messages have this post with contact-form.php :
<?php
session_cache_limiter('nocache');
header('Expires: ' . gmdate('r', 0));
header('Content-type: application/json');
// Enter your email address
$to = 'XXXX#tize.XX';
$subject = $_POST['subject'];
if($to) {
$name = $_POST['name'];
$email = $_POST['email'];
$fields = array(
0 => array(
'text' => 'Name',
'val' => $_POST['name']
),
1 => array(
'text' => 'Email address',
'val' => $_POST['email']
),
2 => array(
'text' => 'Message',
'val' => $_POST['message']
)
);
$message = "";
foreach($fields as $field) {
$message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
}
$headers = '';
$headers .= 'From: ' . $name . ' <' . $email . '>' . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
if (mail($to, $subject, $message, $headers)){
$arrResult = array ('response'=>'success');
} else{
$arrResult = array ('response'=>'error');
}
echo json_encode($arrResult);
} else {
$arrResult = array ('response'=>'error');
echo json_encode($arrResult);
}
?>
Picture of my form, If anyone wants to see my website please let me know and send you the link. Thank you very much. sending without activating the reCaptcha http://goo.gl/oSLQG9
1.) Using your current provided code <script src='https://www.google.com/recaptcha/api.js'></script> is missing and is required for recaptcha to work.
2.) Per Google's documentation on Re-Captcha, Google will send a response on a verified/non-verified submission in which you must use a $_GET call to evaluate the response for success / fail.
From Google Re-Captcha step 2 - server side integration:
When your users submit the form where you integrated reCAPTCHA, you'll
get as part of the payload a string with the name
"g-recaptcha-response". In order to check whether Google has verified
that user, send a GET request with these parameters:
URL: https://www.google.com/recaptcha/api/siteverify
secret(required) 6LedHvoSAAAAAN4cRa8x1FaVsKPsMrs8SGMqp4ef
response(required) The value of 'g-recaptcha-response'. remoteip The
end user's ip address.
In short - I don't see the required SCRIPT linking in your code provided, I also see no implementation of a $_GET call to Google re-captcha to verifiy success/failure of the re-captcha entered by the user.
Be sure you are implimenting and using the tools/directions provided directly from Google to make your integration located here:
Google Re-Captcha Site
From the code, I can't see link and declaration of private-key and public-key in it.
I myself use this to handle it:
1.Place the google-recaptcha file in a directory.
2.declare on contact.php, as:
require_once('../recpatcha_google.php');
$publickey = '6LcZIfxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$privatekey = '6LcZIf8Sxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
3.to check if user verify and pass the captcha:
$resp = recaptcha_check_answer ($privatekey,$_SERVER['REMOTE_ADDR'],strip_tags($_POST['recaptcha_challenge_field']),strip_tags($_POST['recaptcha_response_field']));
if (!$resp->is_valid) { //if not true ......
................
}
4.call the captcha inside your form, as:
<?php echo recaptcha_get_html($publickey); ?>
Note: Do not forget to register your site with WWW or without WWW to make sure everything runs OK.
I have a pretty basic PHP site and I want a simple spam protection to stop the spam submissions.
I've found one that I like which is a basic 4 character input. Easy to read, small space requirements.
But it says to use a validate.php for the submission action.
My current form's action is to call a the mailer.php (<form id="contact-form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" class="validate-form">) which is actually included on page load (<?php include 'includes/mailer.php'; ?>).
Can I have two 'actions'? If not, how can I implement the use of this captcha?
When I try adding session_start();
if(isset($_POST["captcha"])&&$_POST["captcha"]!=""&&$_SESSION["code"]==$_POST["captcha"])
{
echo "Correct Code Entered";
//Do you stuff
Just after the opening <?php in mailer.php and then }
else
{
die("Wrong Code Entered");
} just before the closing ?>, the whole website just displays "Wrong code entered" on load.
EDIT:
I'm having trouble understanding where I need to place the various parts of the code and how to tweak it so it works with the existing mailer script.
My unmodified index.php basically consists of the following:
<?php
include 'includes/mailer.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/bootstrap-responsive.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<section id="section-home">
<header>
<!-- header content -->
<!-- navigation -->
</header>
</section>
<section class="banner full-width-container">
<div class="container">
<!-- other body content -->
<div id="contact">
<div id="contact-form-message"><?php print $output; ?></div>
<form id="contact-form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" class="validate-form">
<p><span style="color:#f7403a;">Fill in the form below to have an expert contact you</span></p>
<div class="form-left">
<div class="control-group">
<label for="name" class="assistive control-label">Name:</label>
<div class="controls">
<input type="text" name="name" id="name" value="Your Name" class="replace-default required type-text" />
</div>
</div>
<div class="control-group">
<label for="email" class="assistive control-label">Email: </label>
<div class="controls">
<input type="text" name="email" id="email" value="Your email address" class="replace-default required type-text" />
</div>
</div>
</div><!-- end form-left -->
<div class="form-right">
<div class="control-group">
<label for="subject" class="assistive control-label">Subject: </label>
<div class="controls">
<input type="text" name="subject" id="subject" value="Subject" class="replace-default required type-text" />
</div>
</div>
<div class="control-group">
<label for="telephone" class="assistive control-label">Telephone number </label>
<div class="controls">
<input type="text" name="telephone" id="telephone" value="Your phone number" class="replace-default required type-text" />
</div>
</div>
</div><!-- end form-right -->
<div class="control-group">
<label for="message" class="assistive control-label">Message: </label>
<div class="controls">
<textarea name="message" id="message" class="replace-default required type-textarea full-width" rows="5" cols="20">The type of enquiry (e.g. Motor Accident) and a brief message</textarea>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" id="submit" name="submit" class="btn btn-stacks" value="Send Message"/>
<div id="sending-message"><img src="img/ajax-loader.gif" alt="" /></div>
</div>
</div>
</form>
</div>
</div>
</section>
<footer class="full-width-container" id="footer-section">
<div class="container">
<!-- footer content -->
</div>
</footer>
<!-- ============================================== -->
<script src="js/modernizr-1.7.min.js"></script>
<script src="js/jquery-1.8.2.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/jquery.validate.min.js"></script>
<script src="js/jquery.flexslider-min.js"></script>
<script src="js/waypoints.min.js"></script>
<script src="js/jquery.scrollTo-1.4.3.1-min.js"></script>
<script src="js/custom.js"></script>
</body>
</html>
And my unmodified mailer.php consist of:
<?php
function cleanInput($input){
$input = trim($input);
if(strlen($input)>0){
$input = htmlspecialchars(stripslashes($input));
}
return $input;
}
$name = '';
$email = '';
$subject = '';
$message = '';
$telephone = '';
$output = '';
if ( isset($_POST['submit']) || isset($_GET['ajax']) == 'true'){
//set up for form fields
$name = cleanInput($_POST['name']);
$email = cleanInput($_POST['email']);
$subject = cleanInput($_POST['subject']);
$telephone = cleanInput($_POST['telephone']);
$message = cleanInput($_POST['message']);
$output ='';
$regex = "/^([a-z0-9\\+_\\-]+)(\\.[a-z0-9\\+_\\-]+)*#([a-z0-9\\-]+\\.)+[a-z]{2,6}$/ix";
//do some basic validation
if( $name == '' || $name == 'Full Name' ){ $output = '<li class="alert alert-error">Please enter your name.</li>'; }
if ( !preg_match( $regex, $email ) || $email == 'Email address' ) {
$output .= '<li class="alert alert-error">Please check that your email address is valid</li>';
}
if( $subject == '' || $subject == 'Subject' ){ $output .= '<li class="alert alert-error">Please enter a subject</li>'; }
if( $telephone == '' || $telephone == 'Contact number' ){ $output .= '<li class="alert alert-error">Please enter a contact number</li>'; }
if( $message == '' || $message == 'Your Query' ){ $output .= '<li class="alert alert-error">Please enter a message</li>'; }
//if there are errors, add them to the list here
if ( $output!='' ){
$output = '<div class=""><ul class="unstyled">' . $output . '</ul></div>';
}
//if no errors, try to send the form
else {
/*Put the email address to send to here*/
$to = "email1#domain.com.au";
$headers = 'From: noreply#domain.com.au' . "\r\n";
$headers .= 'Cc: '. $email . "\r\n";
$headers .= 'Bcc: email2#domain.com.au' . ', ' . 'email3#domain.com.au' . ', ' . 'email4#otherdomain.com.au' . "\r\n";
$subject = $subject;
$body = "Name: $name\n\n"
. "Email: $email\n\n"
. "Subject: $subject\n\n"
. "Message: $message"
;
$messageOK = ( mail($to, 'Web Enquiry from the landing page for: ' . $subject, $body, $headers ));
//check if the mail was sent or not
if ( $messageOK ){
$output = '<div class="alert alert-success"><p>Thank you for getting in touch. We will be in contact soon.</p></div>';
}
else {
$output = '<div class="alert alert-error"><p>We could not send your message. Please try again.</p></div>';
}
}
//if ajax is being used, output the message
if ( isset($_GET['ajax']) == 'true' ){
print $output;
}
}
?>
Any information that helps me understand what is required to use this captcha code would be greatly appreciated
You could use a random number generated when form is generated, then passing the value using POST AND $_SESSION, and then compare 2 to see if they match. This is for bot protection/spam.
Would you like an example?
EDIT, didn't fully read the question.
What you want to do is to decide whether the page is loaded as POST request, if is not, then display the form, if is, validate $_POST fields and/or send email.
session_start();
$error = null;
if(isset($_POST["captcha"])&&$_POST["captcha"]!=""&&$_SESSION["code"]==$_POST["captcha"])
{
echo "Correct Code Entered";
//Do you stuff`
else
{
$error = "invalid captcha image, please try again!";
}
//the rest of your HTML
//after the recaptcha image HTML
echo isset($error)? $error: '';
This will stop the page from dieing because of the failed captcha, and will produe an error message of 'Invalid captcha image' if the capthc was false.
I am new to programming and after a zillion hours working on this I am not getting any closer to a solution. Any help would be greatly appreciated.
I have a form that I am sending to php via ajax(although I don't see /process.php in the address bar after the domain name, or does that even matter?). The confirmation from php does load on the page but the email with the form values does not get sent. I work very hard at this, and I really do believe I'll get this stuff, but right now I am in need a little help. A live version can be viewed at http://www.hydrodyneh2o.com.
Thanks in advance.
$(document).ready(function(){
//Script for "Submit" button to submit and load 'submission confirmation'
$('#hydrodyne-form input[type="submit"]').click(function(e){
e.preventDefault();
//alert("never!");
$('#hydrodyne-form .warn').remove();
var fields = $('#hydrodyne-form').serializeArray();
$.ajax({
type : 'POST',
url : 'processForm.php',
data : fields,
dataType : 'json',
success: function(data) {
if (data.error) {
$.each(data.fields, function(k, v) {
$('.' + k).append('<span class="warn">' + v + '</span>');
$('.warn').fadeIn(700);
});
} else {
$('#form-content').fadeOut(700, function() {
$(this).hide();
$('#form-content').addClass('processing').html('Processing...').fadeIn(400);
$('#form-content').delay(1300).fadeOut(700).hide(function(){
$(this).removeClass('processing').html(data.confirm).fadeIn(400);
});
});
}
},
error: function(data) {
$('#form-content').hide().html('<p id="error" class="italic inside-text">*Error occurred</p>').fadeIn(700);
}
});
return false;
});
});
PHP (processForm.php):
<?php
$service = $_POST['service'];
$service_type = implode(",\r\n• ",$service);
if ($_POST) {
$expected_inputs = array('company', 'contact_name', 'phone_number', 'email');
$validation = array(
'company' => 'Company Name Required',
'contact_name' => 'Contact Name Required',
'phone_number' => 'Phone Number Required',
'email' => 'Email Address Required'
);
$company = stripslashes($_POST['company']);
$contact_name = stripslashes($_POST['contact_name']);
$phone_number = stripslashes($_POST['phone_number']);
$email = stripslashes($_POST['email']);
$project_summary = stripslashes($_POST['project_summary']);
$to = 'brian#bseifert.com';
$subject = 'You\'ve got a Website Inquiry!';
$message = "\r\n Contact Name: " . $contact_name .
$message = "\r\n\r\n Company: " . $company .
$message = "\r\n\r\n Phone Number: " . $phone_number .
$message = "\r\n\r\n Email Address: " . $email .
$message = "\r\n\r\n\r\n Type of Anticipated Service: \r\n\r\n " . $service_type .
$message = "\r\n\r\n\r\n Message: \r\n\r\n" . $project_summary;
$message = wordwrap($message, 80);
$errors = array();
$output = array();
foreach($expected_inputs as $key) {
if (array_key_exists($key, $_POST)) {
if (empty($_POST[$key])) {
$errors[$key] = $validation[$key];
} else {
$output[$key] = $_POST[$key];
}
} else {
$errors[$key] = $validation[$key];
}
}
if (!empty($errors)) {
$array = array('error' => true, 'fields' => $errors);
} else {
// PROCESS FORM
mail($to, $subject, $message) or die('not working!!!');
$confirm =
'<div id="logo" style="margin:80px 0 0 335px;"></div>
<img class="absolute" style="top:158px; left:265px;" src="IMG/inside-pgs/checkmark.png" alt="" />
<div class="inside-text thank-you">
<p>Your message has been sent.<br/> A representative from Hydrodyne will contact you<br/> as soon as possible.</p>
</div>';
$array = array('error' => false, 'confirm' => $confirm);
}
echo json_encode($array);
}
?>
HTML:
<div id="form-content">
<div id="inside-pg-heading">
<img src="IMG/inside-pgs/contact.gif" alt=""/>
</div><!-- end inside-pg-heading -->
<img class="hydroArrowContact absolute" src="IMG/inside-pgs/hydroArrowContact.png" alt="" />
<p class="hydroArrowContactText absolute">ydrodyne thanks you for stopping by, and asks that you use the form below <br>to ask any questions or place a request. We look forward to hearing from you!</p>
<div class="absolute" style="width:950px; top:132px; left:35px;">
<!-- <div id="response"></div> -->
<form id="hydrodyne-form" action="processForm.php" method="post">
<div id="formCol1">
<h5 class="form-heading inside-text bold italic"><span style="font-size:14px;">Fields marked with an asterisk (*) are required.</span></h5>
<div id="text-inputs" class="inside-text bold italic">
<div id="inputCol1">
<h4 class="company">* Company</h4>
<input type="text" name="company"<br/>
<h4 class="contact_name">* Contact Name</h4>
<input type="text" name="contact_name"<br/>
</div><!-- end inputCol1 -->
<div id="inputCol2">
<h4 class="phone_number">* Phone Number</h4>
<input type="text" name="phone_number"<br/>
<h4 class="email">* Email Address</h4>
<input type="text" name="email"<br/>
</div><!-- end inputCol2 -->
</div><!-- end text-inputs -->
<div class="clear"></div>
<h4 class="form-heading inside-text bold italic">Please check anticipated service(s)</h4>
<div class="checkboxes green">
<div id="checkboxCol1">
<input type="checkbox" name="service[]" value="Wastewater Flushing / Laundry"> Wastewater Flushing / Laundry<br/>
<input type="checkbox" name="service[]" value="Irrigation"> Irrigation<br/>
<input type="checkbox" name="service[]" value="Vehicle Washing"> Vehicle Washing<br/>
<input type="checkbox" name="service[]" value="Animal Feeding"> Animal Feeding
</div><!-- end checkboxCol1 -->
<div id="checkboxCol2">
<input type="checkbox" name="service[]" value="Commercial / Industrial Cooling"> Commercial / Industrial Cooling<br/>
<input type="checkbox" name="service[]" value="Commercial / Industrial Processing"> Commercial / Industrial Processing<br/>
<input type="checkbox" name="service[]" value="Fire Suppression"> Fire Suppression
</div><!-- end checkboxCol2 -->
</div><!-- end checkboxes -->
</div><!-- end formCol1 -->
<div id="formCol2">
<h5 class="form-heading inside-text bold italic">Provide Hydrodyne with more information by typing a brief message in the box below.</h5>
<textarea name="project_summary"></textarea>
<input type="submit" value="">
</div><!-- formCol2 -->
</form>
</div>
</div><!-- end form-content -->
According to the pHp documentation: http://php.net/manual/en/function.mail.php#example-3381
you can add a header to the mail();
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// PROCESS FORM
mail($to, $subject, $message, $headers) or die('not working!!!');
Also you should check the following line as I guess there is a invalid character which can create any unwanted pHp Warnings/errors;
$service_type = implode(",\r\n• ",$service);
it should be:
$service_type = implode(",\r\n",$service);
Thank you Nouphal.M! Man, I spent a lot of time searching for a solution when all I needed to do was check my spam. I really appreciate your time and efforts everyone!