Jump to content

Annoying empty mail sending


terryds
 Share

Recommended Posts

I created a form that willl automatically send what it's filled in via email.. What is annoying is when i don't fill in the form and click submit.. The mail function also works... Can you tell me how to make it not send anything when the form isn't filled in ?

Link to comment
Share on other sites

you can use isset(), empty() to determine that inputs does not submited empty. you should always validate every input from user before you use it in system. http://php.net/issethttp://php.net/empty

  • Like 1
Link to comment
Share on other sites

This is my code for signup.php

 <!DOCTYPE html><html><head><title>Thanks for signing up!</title></head><body><h2>Wait till the admin validates your account</h2><?php$name = $_POST['fname'] . " " . $_POST['lname'];$email = $_POST['email'];$country = $_POST['country'];$gender = $_POST['gender'];$reason = $_POST['reason']; $to = 'myemail@blahblah.com';$subject = 'Admin - Validating';$msg = "$name wants to join the site.\n" . "$name 's email is $email \n" . "$name is a $gender in $country \n" . "$name wants to join because $reason";$delivery = mail ($to, $subject, $msg, 'From: ' . $email); echo 'Thanks for signing up, ' . $name . '<br />';echo 'Those datas you input will be emailed to admin' . '<br />';echo 'Name : ' . $name . '</br>';echo 'Email : ' . $email . '<br/>';echo 'Country : ' . $country . '<br />';echo 'Gender : ' . $gender . '<br />';echo 'I join this because ' . $reason;?> </body></html>

This is the signup html (the form)

<!DOCTYPE html><html><head><title>Sign Up Now!</title><link rel="stylesheet" type="text/css" href="signup.css" /></head><body><h1>Sign up now and get the gifts!</h1><h3>Type down your identity !</h3><form method="post" action="signup.php"><fieldset><legend>Sign Up</legend><label for="fname">First Name:</label><input type="text" id="fname" name="fname" /><br /><label for="lname">Last Name:</label><input type="text" id="lname" name="lname" /><br /><label for="email">Email</label><input type="text" id="email" name="email" /><br /><label for="country">Country</label><input type="text" id="country" name="country" /><br /><label for="gender">Gender</label><input id="gender1" name="gender" type="radio" value="male">Male<input id="gender2" name="gender" type="radio" value="female">Female<br /><label for="reason">Why do you want to join us ?</label><textarea id="reason" name="reason"></textarea><br /><input type="submit" value="Sign Up!" name="submit" /></fieldset></form></body></html>

Please help me where to add the code? And how it should be ?

Link to comment
Share on other sites

if(!empty($_POST['subject'] && !empty($_POST['message']) //List of required field{ //Process data mail(....);}else{//show error} link on post 2 will help you to get idea how does these functions work.

Edited by birbal
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...