MyBB Community Forums

Full Version: Invitation Script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi!
I need a script for Invitation other users to my forum.
I find this:

<?php
// Gather info into variables
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$youremail = $_REQUEST['youremail'];
$message2 = "YourMessageHere!";

// If $email is not set, $message is empty so as $youremail, then show the form
if(!isset($email) && empty($message) && empty($youremail)){
echo "<form action='' method='post'>"
	."<font>Invite your friends</font><br><br>"
	."<font><b>Email: </b> <input type='text' name='email' size='30'><br>"
	."<font><b>Your email: </b><input type='text' name='youremail' size='30'><br>"
	."<font><b>Message: </b><br><textarea name='message' cols='30' rows='5'></textarea><br>"
	."<input type='submit' value='Invite'>";
}
// If $youremail is empty then show the error
elseif(empty($youremail)){
die("Please enter your email!");
}
// If $message is empty then show the error
elseif(empty($message)){
die("Please enter your message!");
//If everything is okay let's send our invitation
}else{
$send = mail($email, "Invitation", $message."

$message2", "From: $youremail");
// If we can not send this email let's show the error
if(!$send){
echo "Can not send your invitation!";
}
// If this invitation was sent then let's show that "Invitation sent" message
else{
echo "Invitation sent!";
}
}

?>

But it hasn't any option for secure form from spammers (like captcha)
has anyone better code?
can anyone help me?
Why not have a security question? It'd be easy to implement.
How to?
Put this in your form:
Some question goes here: <input type='text' name='question' /><br />

And this in the else statement where the form has been submitted.
$answer = _$POST['question'];
$correctanswer = "Answer Here";
if ($answer!=$correctanswer)
{
die ("Incorrect Answer given");
}
else
{
// rest of code
}
I can not add it ! Big Grin
From the above code, change;
$answer = _$POST['question'];
to;
$answer = $_POST['question'];
(2012-04-12, 04:36 PM)Jondan Wrote: [ -> ]anyone has better code that it has captcha?

Edited that code to have Recaptcha.

<?php
require_once('recaptchalib.php');
// Gather info into variables
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$youremail = $_REQUEST['youremail'];
$message2 = "YourMessageHere!";

// If $email is not set, $message is empty so as $youremail, then show the form
if(!isset($email) && empty($message) && empty($youremail)){
$publickey = "your_public_key";

echo "<form action='' method='post'>"
    ."<font>Invite your friends</font><br><br>"
    ."<font><b>Email: </b> <input type='text' name='email' size='30'><br>"
    ."<font><b>Your email: </b><input type='text' name='youremail' size='30'><br>"
    ."<font><b>Message: </b><br><textarea name='message' cols='30' rows='5'></textarea><br>
	<b>Captcha verification</b>:<br />".recaptcha_get_html($publickey)
    ."<input type='submit' value='Invite'>";
}
// If $youremail is empty then show the error
elseif(empty($youremail)){
die("Please enter your email!");
}
// If $message is empty then show the error
elseif(empty($message)){
die("Please enter your message!");
//If everything is okay let's send our invitation
}else{
$privatekey = "your_private_key";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
   
$send = mail($email, "Invitation", $message."

$message2", "From: $youremail");
// If we can not send this email let's show the error
if(!$send){
echo "Can not send your invitation!";
}
// If this invitation was sent then let's show that "Invitation sent" message
else{
echo "Invitation sent!";
}
}
}

?>

You should enter the public and private keys of Re-captcha in their respective variables, and put recaptchalib.php file in your site root.