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.
Related
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.
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.
I would use some help because I don't know what to do at all...
I created an HTML form (which isn't a problem) :
<form method="post" action="form-page.php" class="cta">
<div class="row gtr-uniform gtr-50">
<div class="col-8 col-12-xsmall"><input type="text" name="user_name" id="name" required placeholder="Votre nom"></div>
<div class="col-8 col-12-xsmall"><input type="email" name="email" id="email" placeholder="Votre adresse e-mail" /></div>
<div class="col-8 col-12-xsmall"><textarea name="user_message" id="msg" required placeholder="Votre message"></textarea></div>
<div class="col-4 col-12-xsmall"><input type="submit" value="Envoyer." class="fit primary" /></div>
</div>
</form>
I created the file "form-page.php" which treat the form with this code :
<?php
// We get the infos of the form
$user_name = $_POST['user_name']; // Nom / Pseudo.
$email = $_POST['email']; // e-mail.
$user_message = $_POST['user_message']; // Message.
//=========
// We put the adress where the mail is going to be send.
//P.S : "myemail#gmail.com" isn't MY email, I just put it here to hide my email :)
$mail = 'myemail#gmail.com';
//=========
// We filtrate servers to avoid bugs.
if (!preg_match("#^[a-z0-9._-]+#(hotmail|live|msn).[a-z]{2,4}$#", $mail))
{
$passage_ligne = "\r\n";
}
else
{
$passage_ligne = "\n";
}
//=========
// We define the subject of the mail.
$sujet = "Suggestion ou bug de ton site, Pokemon Reality";
//=========
// We create the header of the email.
$header = "From: \"$user_name\" $email".$passage_ligne;
$header.= "MIME-Version: 1.0".$passage_ligne;
//==========
// We create the message.
$message = $user_message;
//==========
// Finally, we send the email.
mail($mail,$sujet,$message,$header);
//==========
?>
Buuuut... This doesn't work! After I press the button "Envoyer." of the form, I wait while the page is loading and I see an error :
ERROR
ERROR2
I didn't touch to anything, and before that, I test it 3 times, and it send the mail, but there was a blank page.
So I want to fix the error, and then, I want to redirect the user to the form and say "Thank You !".
Thanks for your help!
I have an HTML form where you can enter your email and a message.
After you submit this form i would like an email to be sent to my email (fixed) and to the email that is filled in trough the form.
I got my email to work but i can't seem to get the email from my HTML form into the send list in PHP. Any suggestions?
Code (html):
<form id="contact-form" method="post" action="js/contact.php" role="form">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="form_email">Email</label>
<input id="form_email" type="email" name="email" class="form-control" placeholder="Vul hier je email adres in" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="form_message">message</label>
<textarea id="form_message" name="message" class="form-control" placeholder="Vul hier een eventuele opmerking of message in." rows="4" required="required" data-error="Please,leave us a message."></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-12">
<input type="submit" class="btn btn-success btn-send" value="Versturen">
</div>
</div>
</div>
</form>
Code PHP:
<?php
$from = 'info#mywebsite';
$sendTo = 'myemail#gmail.com'; //Here the email from the form should be added
$subject = 'Nieuwe reservering';
$fields = array('kosten' => 'kosten' , 'name' => 'Naam', 'surname' => 'Achternaam', 'phone' => 'Telefoonnummer', 'kamer' => 'Kamer', 'aankomst' => 'aankomst', 'vertrek' => 'vertrek', 'email' => 'Email', 'message' => 'Bericht');
$okMessage = 'Je bericht is verzonden!';
$errorMessage = 'Oei er ging iets fout, geeft niks. Probeer het later opnieuw.';
error_reporting(E_ALL & ~E_NOTICE);
try {
if(count($_POST) == 0) throw new \Exception('Form is empty');
$emailText ="<table>";
$emailText .="<p>Bedankt voor uw reservering, hieronder de ingevulde info:</p><br><br>";
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailText .= "<tr><td>{$fields[$key]}</td>";
$emailText .= "<td>$value</td></tr>";
}
}
$emailText .="<br><br><p>Voor vragen of wijzigingen mail naar: info#bmyemail</p>";
$emailText .="</tr></table>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers = array('Content-type:text/html;charset=UTF-8";',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
);
mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e){
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
} else {
echo $responseArray['message'];
}
You can specify all recipients like this: (check official guideline here)
$sendTo = 'myemail#gmail.com, abc#example.com, xyz#example.com'; // note the comma
//actual message
$message = "Message Content";
mail($sendTo, $subject, $message));
Hope it helps! :)
After your email is done, you just need to send it twice :
<?php
mail($addr1, $subject, $message, $header);
mail($addr2, $subject, $message, $header);
?>
You can also concatenate differents addresses (I've managed to send a mail to different addresses by changing my input to a textarea and writing one address per line).
Good luck!
I'm testing a PHP form to send email in local.
I put all input but when I press the submit button it always returns "false" and then the error message. Is that because I'm working in local and don't have any mail server, or is there something wrong in my code?
here the code:
<?php
if(isset($_POST['submit']))
{
if(empty($_POST['nome']) ||
empty($_POST['email']) ||
empty($_POST['motivo']) ||
empty($_POST['messaggio']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
// return false;
}
else
{
$nome = strip_tags(htmlspecialchars($_POST['nome']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$motivo = strip_tags(htmlspecialchars($_POST['motivo']));
$messaggio = strip_tags(htmlspecialchars($_POST['messaggio']));
// Create the email and send the message
$to = 'mirkocoppola80#gmail.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $nome";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $nome\n\nEmail: $email_address\n\nOggetto: $motivo\n\nMessaggio:\n$messaggio";
$headers = "From: mirkocoppola80#gmail.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
if (!#mail($to,$email_subject,$email_body,$headers))
{
// return true;
echo "<p>Email error</p>";
}
else
{
echo "<p>Email sent successfully!</p>";
}
}
}
?>
<form class="form-horizontal col-sm-6 col-sm-offset-3" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="POST">
<div class="form-group">
<div class="row">
<label for="email" class="col-sm-12">Email</label>
</div>
<div class="row">
<div class="col-sm-12">
<input type="email" name="email" class="form-control" id="email" placeholder="Email">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<label for="nome" class="col-sm-12">Nome</label>
</div>
<div class="row">
<div class="col-sm-12">
<input type="text" name="nome" class="form-control" id="nome" placeholder="Nome">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<label for="motivo" class="col-sm-12">Motivo</label>
</div>
<div class="row">
<div class="col-sm-12">
<input type="text" name="motivo" class="form-control" id="motivo" placeholder="Motivo">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<label for="messaggio" class="col-sm-12">Messaggio</label>
</div>
<div class="row">
<div class="col-sm-12">
<textarea class="form-control" name="messaggio" rows="5" id="messaggio" placeholder="Motivo">Inserisci il tuo messaggio...</textarea>
</div>
</div>
</div>
<div class="form-group">
<div class="">
<button type="submit" name="submit" class="btn btn-default">Invia</button>
</div>
</div>
</form>
Any help?
Is that because I'm working in local and don't have any mail server
Yes.
PHP's mail() function will always fail and return false if you don't have a local mail server running.
This answer has some useful tips
You need to setup a mail server on your machine for the mail function to work. If you are on Windows (which I am guessing you are from your use of WAMP) you can setup a Pegasus mail server.
Other options include using a wrapper class such as SwiftMailer or PHPMailer and using them to connect to another SMTP server such as your GMail account. Even if you go the Pegasus mail server on your own localhost route then I would still recommend using one of the two classes I have mentioned above. They give you far more flexibility and are safer.
Connecting to either your ISPs SMTP server or GMail or whatever is the easiest route out of this one.
To expand on the above, you can also look into Mailhog or Mailcatcher to capture your mail locally and examine its contents.
remove the "#" in
if (#mail($to,$email_subject,$email_body,$headers))
<?php
if(isset($_POST['submit']))
{
if(empty($_POST['nome']) ||
empty($_POST['email']) ||
empty($_POST['motivo']) ||
empty($_POST['messaggio']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
// return false;
}
else
{
$nome = strip_tags(htmlspecialchars($_POST['nome']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$motivo = strip_tags(htmlspecialchars($_POST['motivo']));
$messaggio = strip_tags(htmlspecialchars($_POST['messaggio']));
// Create the email and send the message
$to = 'mirkocoppola80#gmail.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $nome";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $nome\n\nEmail: $email_address\n\nOggetto: $motivo\n\nMessaggio:\n$messaggio";
$headers = "From: mirkocoppola80#gmail.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
if (mail($to,$email_subject,$email_body,$headers))
{
// return true;
echo "<p>Email error</p>";
}
else
{
echo "<p>Email sent successfully!</p>";
}
}
}
?>
it should work then.