Copy link to clipboard
Copied
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>brief</title>
<style type="text/css">
@import url("webfonts/Audiowide/stylesheet.css");
body,td,th {
font-family: Audiowide;
font-size: 14px;
}
body {
background-image: url(images/wallpaper-sinterklaas-pakjes-op-het-dak.jpg);
font-size: 18px;
color: #F5F5F5;
text-align: left;
}
.tekst{
font-size: 24px;
color: #FFFFFF;
float: left;
text-align: left;
}
#form1 #textarea {
width: 800px;
height: 500px;
align-content: center;
color: #000000;
font-family: Audiowide;
text-align: left;
font-size: 18px;
}
.naambox {
width: 200px;
height: 35px;
align-content: center;
color: #000000;
font-family: Audiowide;
text-align: left;
font-size: 18px;
}
.myButton
{
background-color: #ED1A1A;
border: 1px solid #ED1A1A;
display: inline-block;
cursor: pointer;
color: #f0ebf0;
font-family: Audiowide;
font-size: 13px;
font-weight: bold;
margin: 5px;
padding: 7px 35px;
text-decoration: none;
}
@media print {
#printbtn {
display : none;
}
}
</style>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<p>Schrijf een brief aan Sinterklaas.</p>
<p>Print hem af en steek hem in je schoen of email hem rechtstreeks naar de Sint</p>
<p> </p>
<form action="mailto:sinterklaas@kiwanis-zonhoven.be" method="post" name="form1" id="form1">
<p>Jouw naam:
<textarea name="textarea2" class="naambox" id="textarea2"></textarea>
</p>
<p>Jouw bericht aan Sinterklaas</p>
<p>
<textarea name="textarea" maxlength="500" autofocus="autofocus" id="textarea" form="form1"></textarea>
</p>
<p> </p> <p> </p><p>
<div class="g-recaptcha" data-sitekey="mykey"></div>
<input type="submit" class="myButton" id="printbtn" value="Emailnaar Sinterklaas">
<input name="submit" type="button" class="myButton" id="printbtn" value="Print af en steek hem in je schoen" onclick='window.print()' />
</p
></form>
<script src='https://www.google.com/recaptcha/api.js?hl=es'></script>
</body>
</html>
I need to integrate recaptcha into my page.
Is this possible in an HTML page?
The form action is a mailto:
i think i don't need recaptcha, just a name and a message are sent
and this can only be seen in a private environment, it is not the intention to make this public
By @LyaSmidtsx
Just consolidate everything to the same php page, the form, the script etc: Copy code below, create a blank php file (no doctype - just blank) named feedback_form.php and paste in the code. Change the $to= php variable from me@me.com to the correct recipient email address.........if your server allows use of the php mail
...thanks, I'm still adjusting it a bit to my needs.
Can I insert a standard from address in the code?
I tried with $from="myemail"; but that doesn't work.
By @LyaSmidtsx
Just add the additional code marked in bold below:
$to="me@me.com";
$subject = "You have feedback";
$from = "whoever@whoever.com";
$feedback = "Letter from: ". $name . "\n";
$feedback .= "\nThey write: ". $message . "\n";
$headers = "From: $from";
$headers .= "MIME-Version: 1.0";
$headers .= "Content-type:text/html;charset=UTF-8";
mail ($to,
...Copy link to clipboard
Copied
The short answer is yes, but it's complicated. The form needs to be processed in order to use recaptcha. With mailto, the button simply opens the mail client of the end user so there is no validation. So you would need to build a form that has a validation script, then redirect after the validation to a mailto link. Personally it's more work than what it's worth. I would just implement a script to process your form and send you the results (email or to a database) and get rid of mailto.
Copy link to clipboard
Copied
can the page with the form itself be an html and the form action then a php form script?
Copy link to clipboard
Copied
can the page with the form itself be an html and the form action then a php form script?
By @LyaSmidtsx
Yes, if I remember correctly. It's a long time since I used .html file when using a php workflow. If you're using php as part of your workflow then all of your pages may as well be .php even if there is no php in them. The form script obviously needs to go into a .php page where you would point your forms action attribute to, you cant have the php script in the .html page
If you are going to use php to process the form then you have 2 options, use the default php mail function IF your server will allow or you may have to use PHPMailer library or similar as some hosts deem it more secure in the hands of amatuer coders and deactivate the default php mail function.
Copy link to clipboard
Copied
I just need a very simple script
send to : me@me.com
form field: name
form field : message
after success to: thankyou.html
no email address is entered (they are children)
the email that is received
it will look like this
letter from: (child's name)
he writes: (test message)
Copy link to clipboard
Copied
I tried someting, but it isn't work properly
when I click send I get to the form.php
I do receive the email, but:
my email sender is empty
and the message too
<?php
$name = $HTTP_POST_VARS['naam'];
$email = $HTTP_POST_VARS['email'];
$message = $HTTP_POST_VARS['bericht'];
$message = stripslashes($message);
$sendTo = "vivke@telenet.be";
$subject = "Brief aan de Sint";
$redirectUrl = "http://www.kiwanis-zonhoven.be/sinterklaas/danku.html";
$msg_body = "Naam: $name\n";
$msg_body .= "Hij schrijft: $message\n";
$header_info = "From: ".$name." <".$email.">";
mail($sendTo, $subject, $msg_body, $header_info);
?>
Copy link to clipboard
Copied
my form
<form action="formscript.php" method="post" name="form1" id="form1">
<p>Jouw naam:
<textarea name="naam" class="naambox" id="naam"></textarea>
</p>
<p>Jouw bericht aan Sinterklaas</p>
<p>
<textarea name="bericht" maxlength="500" class="berichtbox" id="bericht" form="form1"></textarea>
</p>
<p> </p> <p>
<input name="email" type="hidden" id="email" value="vivke@telenet.be">
</p>
Copy link to clipboard
Copied
Assumes your application uses securely scripted processing, form validation & sanitization procedures, you can add Google's latest reCaptcha API to your form. However you'll need to obtain a unique Google ID and key to deploy it on your site. Depending on how much protection your APP requires, use Google's free version 3 or paid Enterprise.
https://www.google.com/recaptcha/about/
https://support.google.com/a/answer/1217728?hl=en
Copy link to clipboard
Copied
i think i don't need recaptcha, just a name and a message are sent
and this can only be seen in a private environment, it is not the intention to make this public
Copy link to clipboard
Copied
ReCaptcha is the title of your topic.
I answered the topic question.
For form data processing script in PHP, use the PHPMailer example on Github. PHPMailer is a reliable & secure form sending library that's recommended by most server hosts.
https://github.com/PHPMailer/PHPMailer
Good luck with your project.
Copy link to clipboard
Copied
i think i don't need recaptcha, just a name and a message are sent
and this can only be seen in a private environment, it is not the intention to make this public
By @LyaSmidtsx
Just consolidate everything to the same php page, the form, the script etc: Copy code below, create a blank php file (no doctype - just blank) named feedback_form.php and paste in the code. Change the $to= php variable from me@me.com to the correct recipient email address.........if your server allows use of the php mail function then it should work.
<?php
if(isset($_POST['spamAnswer'])) {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
}
else {
$num1 = rand(1, 5);
$num2 = rand(1, 5);
}
if(isset($_POST['submit'])) {
$correctAnswer = $_POST['num1'] + $_POST['num2'];
$error = [];
$name = test_input($_POST['name']);
if(empty($name)) {
$error['name'] = "<p>Please supply your name</p>";
}
$message = test_input($_POST['message']);
if(empty($message)) {
$error['message'] = "<p>Please supply your message</p>";
}
$spamAnswer = $_POST['spamAnswer'];
if(empty($spamAnswer)) {
$error['spamAnswer'] = "<p>Please supply your answer</p>";
}
elseif(number_format($spamAnswer) !== number_format($correctAnswer)) {
$error['spamAnswer'] = "<p>The answer is incorrect</p>";
}
if(!$error) {
$to="me@me.com";
$subject = "You have a message";
$feedback = "Letter from: ". $name . "\n";
$feedback .= "\nThey write: ". $message . "\n";
$headers = "MIME-Version: 1.0";
$headers .= "Content-type:text/html;charset=UTF-8";
mail ($to, $subject, $feedback, $headers);
$success = true;
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
return htmlspecialchars($data);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Message Form</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: helvetica, sans-serif;
}
.feedbackForm {
width: 60%;
margin: 0 auto;
background-color: #e0e0eb;
padding: 30px;
border-radius: 6px;
}
.feedbackForm input[type=text], .feedbackForm textarea {
width: 100%;
padding: 15px;
border: 1px solid #b3b3cc;
margin: 5px 0 0 0;
border-radius: 6px;
font-family: helvetica, sans-serif;
font-size: 16px;
}
.feedbackForm textarea {
min-height: 200px;
font-family: helvetica, sans-serif;
font-size: 16px;
}
.feedbackForm input[type=submit] {
background-color: #5c5c8a;
color: #fff;
border: none;
border-radius: 6px;
padding: 20px 30px;
margin: 30px 0 0 0;
}
.feedbackForm input[type=submit]:hover {
background-color: #52527a;
}
.feedbackForm label {
display: block;
margin: 20px 0 0 0;
}
.feedbackForm p {
margin: 6px 0 0 0;
padding: 0;
color: #cc0000;
font-weight: 600;
}
.thankyou {
color: #cc0000;
font-weight: 600;
}
</style>
</head>
<body>
<form class="feedbackForm" name="feedbackForm" method="POST" action="feedback_form.php">
<h2>Contact Form</h2>
<?php
if(isset($success)) {
echo "<h2 class='thankyou'>Thank you - your message has been sent</h2>";
}
?>
<label for="name">Name<br>
<input type="text" name="name" value="<?php if(isset($name)) { echo $name; } ?>"><br>
<?php if(isset($error['name'])) { echo $error['name']; } ?>
</label>
<label for="message">Message<br>
<textarea name="message"><?php if(isset($message)) { echo $message; } ?></textarea><br>
<?php if(isset($error['message'])) { echo $error['message']; } ?>
</label>
<input type="hidden" name="num1" value="<?php echo $num1; ?>">
<input type="hidden" name="num2" value="<?php echo $num2; ?>">
<label for="spamAnswer">Sum of <?php echo $num1.' + '.$num2; ?> is:<br>
<input type="text" name="spamAnswer" value="<?php if(isset($spamAnswer)) { echo $spamAnswer; } ?>"><br>
<?php if(isset($error['spamAnswer'])) { echo $error['spamAnswer']; } ?>
</label>
<input type="submit" name="submit" value="SUBMIT">
</form>
</body>
</html>
Copy link to clipboard
Copied
thanks, I'm still adjusting it a bit to my needs.
thanks, I'm still adjusting it a bit to my needs.
I want to put the name in the "from": so no email address
if(!$error) {
$to="vivke@telenet.be";
$from="vivke@telenet.be";
$subject = "Sinterklaas, you have mail!!";
$feedback = "Letter from: ". $name . "\n";
$feedback .= "\nContent: ". $message . "\n";
$headers = "MIME Version: 1.0";
$headers .= "Content-type:text/html;charset=UTF-8";
mail ($to,$subject, $feedback, $headers, "-f".$from );;
$success = true;
}
Copy link to clipboard
Copied
thanks, I'm still adjusting it a bit to my needs.
Can I insert a standard from address in the code?
I tried with $from="myemail"; but that doesn't work.
By @LyaSmidtsx
Just add the additional code marked in bold below:
$to="me@me.com";
$subject = "You have feedback";
$from = "whoever@whoever.com";
$feedback = "Letter from: ". $name . "\n";
$feedback .= "\nThey write: ". $message . "\n";
$headers = "From: $from";
$headers .= "MIME-Version: 1.0";
$headers .= "Content-type:text/html;charset=UTF-8";
mail ($to, $subject, $feedback, $headers);
$success = true;
You dont really need the last 2 $headers, that's only if you intend to format the email as html.
Copy link to clipboard
Copied
ok thank you! I tried a last change: I want to go to a thankyou url instead of
<?php
if(isset($success)) {
echo "<h2 class='thankyou'>Thank you! Your message has been sent!</h2>";
}
?>
When I change the form action url, nothing is send
Copy link to clipboard
Copied
Where the script shows $success = true; change that to a php header location redirect pointing to the page you want to go to.
Copy link to clipboard
Copied
I'm almost there!
I have this code, but now it shows the text: oops... before I enter it.
<?php
if(isset($success)) {
header('Location: danku.html'); // Redirect to 'thank you' page. Make sure you have it
} else {
echo "<h2>oops, Something goes wrong</h2>";
}
?>
Copy link to clipboard
Copied
Replace $success = true; in the script at the top of the page, with header('Location: danku.html');
And delete the code which you've shown above, it now doesn't need to be there.
Copy link to clipboard
Copied
Solved, forgot: "-f".$from );
I have still 1 question:
I also created an email field.
I have adjusted the code, but $from is not correct.
The email is not sent
if(!$error) {
$to="myemailadres@";
$from= $email . "\n";
$subject = "Sinterklaas, u heeft mail!!";
$feedback = "Brief van: ". $name . "\n";
$feedback .= "\nInhoud: ". $message . "\n";
$headers = "MIME-Version: 1.0";
$headers .= "Content-type:text/html;charset=UTF-8";
mail ($to,$subject, $feedback, $headers, $from );
$success = true;