Email spamming issues

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Th12eat
Forum Newbie
Posts: 1
Joined: Thu Jan 31, 2008 1:49 pm

Email spamming issues

Post by Th12eat »

I am currently writing a site with a form for submitting information to an email. I switched to php for the versatility of the variables and I've had issues with multiple blank forms being sent to said email. The template i laid out used to come back with teh pre-set text already on it but no input information every time someone visited the site or 3 times if they actually submitted it. I fixed the problem using an "If(isset($submit))" line to ensure that it would not be sent every time someone looked at the page. My only problem now is that when the submit button is actually hit it sends the form and a blank one. I have no idea how the code looks to send 2 emails in the first place, let alone one of them being blank.

Code: Select all

<?php$nameF = $HTTP_POST_VARS['nameF']; 
$nameL= $HTTP_POST_VARS['nameL'];
$email= $HTTP_POST_VARS['email'];
$year = $HTTP_POST_VARS['year'];
$GPA = $HTTP_POST_VARS['GPA'];
$phone = $HTTP_POST_VARS['phone'];
$hths = $HTTP_POST_VARS['hths'];
$hear = $HTTP_POST_VARS['hear'];
$frat = $HTTP_POST_VARS['org'];
$activity = $HTTP_POST_VARS['activity'];
$question = $HTTP_POST_VARS['question'];
$school = $HTTP_POST_VARS['school'];
 
if(isset($Submit))
{
$to = "someone@somewhere.com";  
$subject = "Recruitment";  
$body = "Name: $nameL, 
$nameF \n
Email: $email \n
Year: $year \n
GPA: $GPA \n
Phone: $phone \n
Hometown/Highschool: $hths \n
How he heard about said organization: $hear \n
Why he wants to be in the organization: $org \n
What activities he is in: $activity \n
Questions or Comments he has: $question"; mail($to, $subject, $body);
}  
?>
//code for the rest of the site
<form action="organizationreg.php" method="post" textalign=center>
//code for the form
<br /><input name="Submit"  type="submit" class="input" value="Send" />
</form>
My second issue is error checking. Im a novice at php and I found out that I am unable to request a seperate dialog box to confirm and/or error check the information. To prevent spammers or accidents I would like a set of code to display whether any given field is "" and if so, request the user to fill out that portion.

Any suggestions?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: Email spamming issues

Post by JAM »

You could look up empty() ( as opposed to isset() ) as it works abit different, and read the examples about mail().
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Email spamming issues

Post by Chris Corbyn »

You should also be using $_POST instead of $HTTP_POST_VARS unless you're using a *really old* version of PHP.

EDIT | That script will be generating warnings too. You assign variables to $HTTP_POST_VARS data which won't exist during a GET request. You really want this:

Code: Select all

$some_value = isset($_POST['some_value']) ? $_POST['some_value'] : null;
Your $Submit variable can never exist unless register_globals is turned on in php.ini too. You need to pull that from $_POST like the other variables.
Post Reply