Jump to content

Recaptcha Form Problem


beanpole136

Recommended Posts

I recently began to have problems with spambots using the forms on my website to send large amounts of spam.  I took the forms off for now, and am trying to use Recaptcha to make them secure.  The code I have written seems to be fine, and when the form is submitted, it returns a successful message.  The only problem is that I never receive the email.  My code is split into two pages, as follow:

 

The form code for survey.php:

<form method="post" name="send" action="surveym.php">
    <input type="hidden" name="action" value="send" />
    <span style="color:#997867"><strong>How did you find out about the Troop website?</strong></span><br />
    <input type="radio" name="how" value="troopmeeting" /> When it was announced at a Troop meeting<br />
    <input type="radio" name="how" value="anotherperson" /> From another Troop member<br />
    <input type="radio" name="how" value="google" /> By searching Google<br />
    <input type="radio" name="how" value="other" /> Other: <input type="text" name="other" id="other" size="20" /><br /><br />
    <span style="color:#997867"><strong>So far, what do you think about the site?</strong></span><br />
    <textarea rows="6" name="thinkabout" cols="40"></textarea><br /><br />
    <span style="color:#997867"><strong>In your opinion, where does the site need improvement?</strong</span><br />
    <textarea rows="6" name="improvement" cols="40"></textarea><br /><br />
    <span style="color:#997867"><strong>The site is working on the development of the following features.  Please select three options as ones you would look forward to the most</strong></span><br />
    <input type="checkbox" name="new1" value="pictures" /> Pictures from Troop events<br />
    <input type="checkbox" name="new2" value="gearreview" /> Gear review section<br />
    <input type="checkbox" name="new3" value="games" /> Interactive games<br />
    <input type="checkbox" name="new4" value="contactinfo" /> Contact information (password protected)<br />
    <input type="checkbox" name="new5" value="redesign" /> A site redesign bringing in new colors and more room for information<br />
    <input type="checkbox" name="new6" value="other" /> Other: <input type="text" name="other2" size="20" /><br /><br />
    <?php
        require_once('recaptchalib.php');
        $publickey = "MY KEY IS HERE";
        echo recaptcha_get_html($publickey);
    ?>
    <br />
    <input type="submit" name="submit" value="Submit" /><br /><br />
</form>

 

The code in surveym.php:

<?php
require_once('recaptchalib.php');
$privatekey = "MY KEY IS HERE";
$resp = recaptcha_check_answer ($privatekey,
							$_SERVER["REMOTE_ADDR"],
							$_POST["recaptcha_challenge_field"],
							$_POST["recaptcha_response_field"]);
if ($_POST["submit"]) {
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
$to_name = "ME";
$to_email = "MY EMAIL";
$subject = "Troop Survey";
$how_find = $_POST['how'];
$other_find = $_POST['other'];
$think_about = $_POST['thinkabout'];
$n_improvement = $_POST['improvement'];
$fav_feat1 = $_POST['new1'];
$fav_feat2 = $_POST['new2'];
$fav_feat3 = $_POST['new3'];
$fav_feat4 = $_POST['new4'];
$fav_feat5 = $_POST['new5'];
$fav_feat6 = $_POST['new6'];
$other_feat = $_POST['other2'];
$body = "How person found site: $how_find\n Other: $other_find\n What person thinks about site:\n $think_about\n What person thinks needs improvement:\n $n_improvement\n Person's favorite features: $fav_feat1, $fav_feat2, $fav_feat3, $fav_feat4, $fav_feat5, $fav_feat6\n Other: $other_feat";
mail("$to_name<$to_email>", $subject, $body);
print "<h2>Thank you for participating! Click the back button in your browser to return to the survey page.</h2>";
}
}
?>

Link to comment
Share on other sites

Perhaps your server can't handle the format of sending to "NAME <EMAIL ADDR>" (are you running on Windows?). It sounds like it's executing the line after mail() properly. If so, then something isn't right about your mail() command. Some folks seem to suggest there needs to be a space between the above NAME and '<'. Maybe that's the problem?

I assume you've changed $to_name and $to_email for the purpose of this discussion and that they are properly filled out.

You could try checking if mail() returned true or false. True, just because the mail was accepted for delivery, it does not mean the mail will actually reach you, however, it will tell you if the problem is between you and your mailer, or your mailer and the world.

Link to comment
Share on other sites

Well, I tried the form with just the email; it still didn't work.  I am editing the site in Windows, but the server is Linux.  Yes, the variables are properly filled out outside of the discussion.  How would I go about checking if the mail function returned true or false?

 

Thanks,

Beanpole136

Link to comment
Share on other sites

Does the mail function work for you? Have you used it in succession before? In mikr's code above, if you haven't noticed, you should change $to to $to_email. Give that a run.

 

Try this too -

<?php
mail('youremail@domain.com', 'subject', 'msg');

 

Replace youremail@domain.com with your email address. Leave everything else as is and see if you get an email.

Link to comment
Share on other sites

Like Ken2k7 said, I assumed you would change the variables as they properly should be changed.

So, assuming that, and you are still having trouble...

You need to figure out if it is something you are doing, or something wrong with the server. So you start small. Don't use any variables, just attempt to use mail...

<?php
mail('me@wherever.com', 'Test Subject', 'Test message');
?>

Replace me@whataever.com with your email address, of course. So, if that works, then replace 'Test Subject' with your $subject variable and test again, then 'Test message' with your $body variable. You may be running afoul of mail in some manner.

Link to comment
Share on other sites

Ken2k7:

Yes, previously I have been able to successfully send mail from my site.  When I tried his code, I did indeed change $to to $to_email.  I tried the variation you suggested, but that still returned a 'Mailer did not accept mail.'

 

mikr:

I tried the code you gave me, too.  It also returned 'Mailer did not accept mail.'

Link to comment
Share on other sites

I think there is some problem with my server and the mail function: I created a new php page to test the mail function again.

 

<?php
mail('MY EMAIL', 'subject', 'msg');
if (mail('MY EMAIL', 'subject', 'msg')) {
    echo "Mailer accepted mail.";
} else {
    echo "Mailer did not accept mail.";
}
?>

 

This returns 'Mailer did not accept mail.'

Link to comment
Share on other sites

In the past, did you have a header containing a From in it? The php manual suggests that if sendmail_from is not set in php.ini and a custom From header is missing, sendmail may fail.

Try adding as a fourth variable, "From: yourself@yourwebsite.com\r\n" .

Link to comment
Share on other sites

Do you still have some of the older forms that worked? If you do, then try them out and see if they still work. If they do, try to compare them with what you've got now.

 

Otherwise, my other suggestion is to check if sendmail_form is set:

<?php
print ini_get("sendmail_from");
?>

If it isn't set, try setting it before executing mail() without the fourth variable.

<?php
ini_set("sendmail_from", "fromaddress@host.com");
?>

 

At some point this may be a server problem, and if it is, the question becomes whether you have access to the server or not. If you don't, you'll have to take it up with the owner. If you do, you may try looking at the sendmail logs and seeing what they say.

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.