By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,510 Members | 1,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,510 IT Pros & Developers. It's quick & easy.

Image Captcha has messed up php email form

P: 2
Hi guys, (Newbie member here!)

Having some serious difficulty getting our php email system working after implementing an image captcha to stop the hundreds of bots spamming it.

I may as well post the src first:

Subscription Form:

Expand|Select|Wrap|Line Numbers
  1. <form action="newsletter.php" method="post" enctype="multipart/form-data" name="form" id="form">
  2.                                                         <label>Your Email Address:
  3.  
  4.                                                           <input type="addemail" name="textfield" id="addemail">
  5.                                                         </label>
  6.                                                         <p><img src="CaptchaSecurityImages.php" />
  7.                                                           <br>
  8.                                                           Security Code: 
  9. <input id="security_code" name="security_code" type="text" />
  10. <br>
  11. <input type="submit" name="submit" value="Submit" />
  12.  
  13.  
  14. <br>
  15.                                                           </p>
  16.                                                       </form>
  17.  
PHP File:

[PHP]<?php
session_start();
if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {
// Insert your code for processing the form here, e.g emailing the submission, entering it into a database.
$to = "newsletter@boccaccio.com.au";
$subject = "New Mailing List Entry - $email";
$email = $_REQUEST['addemail'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Thankyou. Your subscription has been successful. You will now be redirected home..."; }

echo "<META http-equiv='Refresh' content='5; url=http://www.boccaccio.com.au'>";

unset($_SESSION['security_code']);
} else {
{print "Incorrect security code. Please try again. You will now be redirected back..."; }
echo "<META http-equiv='Refresh' content='5; url=http://www.boccaccio.com.au/join.html'>";
// Insert your code for showing an error message here
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Boccaccio Cellars Newsletter Subscription</title>
</head>

<body>

[/PHP]

Now, the problem is, i'm suddely only receiving blank emails, when in order for our subscription program to work it needs their email in the subject line and also in the 'from' field.

Any help appreciated, (You can view the page on www.boccaccio.com.au/join.htm)

Cheers.
Mar 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: 2
Hmm, still experimenting. Heres another one, the only problem is i'm having problems nesting the IF statement to verify the image captcha. Its commented out because it works without it in there (But is obviously pointless cause it ignores the captcha)

[PHP]<?php
session_start();
// Hello! welcome to the settings page.
// Here's your two steps guide:

// FIRST:
// Instead of newsletter@test.com put the email address of the mailing list,
// (the same that SendBlaster uses in Manage Subscriptions Section)
// ... please pay attention to the ' ' apostrophes, they must remain around the email address.

$emailmanager = 'newsletter@boccaccio.com.au';

// SECOND:
// save this file, and close it. Thank you!


error_reporting(0);

$email = trim($_POST['email']);
$Ok = ereg("^([a-zA-Z0-9_\.-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", $email);
if ($Ok) {

// {if ($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) )
mail($emailmanager,'Subscribe','','From: '.$email);
//else {alert('Incorrect image entry. Please try again.');

if(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$UNameFrm))
{
?>
<script language = 'javascript'>
alert('Thank you, your address was added to our Mailing List');
history.go(-1);
</script>
<?
exit();
}
}

else {
if(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$UNameFrm))
{
?>
<script language = 'javascript'>
alert('Sorry, please provide a valid Email address.');
history.go(-1);
</script>
<?
exit();
}
}
?>
[/PHP]
Mar 27 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.