Welcome Guest!

If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:

  • Receive Fast Advice
  • Learn Programming Languages
  • Get Professional Website Reviews
  • Quick Troubleshooting Assistance

> Php Mail Function Form.

This is a discussion on Php Mail Function Form., within the PHP section. This forum and the thread "Php Mail Function Form." are both part of the Programming Your Website category.

 
Reply to this topicStart new topic
> Php Mail Function Form., Having a bit of trouble getting it to work correctly.
mcdanielnc89
post Jul 25 2008, 04:25 PM
Post #1


Rapid Squeezer
****

Posts: 252
Joined: 13-February 08
From: Missouri, USA


Hello,

I'm having a tad bit of trouble with my form. I've been trying to get it to NOT send the email through IF the required fields aren't filled in. I cannot get it to work. Here's the code and maybe one of ya'll can help me out.

CODE
<?php
$ip = getenv("REMOTE_ADDR");

$flag=0;
$retval="";

if(isset($_POST['submit'])) {
   $to = "nbjf@newbreedjesusfreaks.com";
   $subject = "Staff Application";
   $fname = $_POST['FName'];
   $lname = $_POST['LName'];
   $email_field = $_POST['email'];
   $gender = $_POST['gender'];
   $location=$_POST['location'];
   $christian=$_POST['christian'];
   $custom=$_POST['custom'];
   $HighSchoolStudent=$_POST['HighSchoolStudent'];
   $MiddleSchoolStudent=$_POST['MiddleSchoolStudent'];    
   $CollegeStudent=$_POST['CollegeStudent'];
   $OutOfSchool=$_POST['OutOfSchool'];
   $Unemployed=$_POST['Unemployed'];
   $whatpartofstaff=$_POST['whatpartofstaff'];
   $Employed=$_POST['Employed'];
   $Retired=$_POST['Retired'];
   $HowLongMemberOfNBJF=$_POST['HowLongMemberOfNBJF'];
   $WhyOnStaff=$_POST['WhyOnStaff'];
   $HowCanUContribute=$_POST['HowCanUContribute'];
   $InternetAccess=$_POST['InternetAccess'];
   $age=$_POST['age'];
   $msn=$_POST['msn'];
   $yahoo=$_POST['yahoo'];
   $aim=$_POST['aim'];
   $skype=$_POST['skype'];
   $icq=$_POST['icq'];
  
   $body = "IP: \n $ip\n\n Name: \n $fname $lname \n\n Email: \n $email_field \n\n Gender: \n $gender \n\n Age: \n $age \n\n Location: \n $location \n\n Am I a Christian? \n $christian \n\n";
       if($HighSchoolStudent)
      $body .= "I am in High School,";
    if($CollegeStudent)
      $body .= "I am in College,";
    if($MiddleSchoolStudent)
      $body .= "I am in Middle School/Jr. High, ";      
    if($OutOfSchool)
      $body .= "I am no longer in school, ";
    if($Unemployed)
      $body .= "I am currently Unemployed, ";
    if($Employed)
      $body .= "I am Employed, ";
    if($Retired)
      $body .= "I am Retired, ";
      
    $body .= " \n\n What staff position am I applying for? \n $whatpartofstaff \n\n How long have I been a member of NBJF? \n $HowLongMemberOfNBJF \n\n Why I would like to be part of the NBJF staff: \n $WhyOnStaff \n\n How can I contribute to NBJF? \n $HowCanUContribute \n\n Internet access: \n $InternetAccess \n\n Yahoo: \n $yahoo \n\n Skype: \n $skype \n\n Aim: \n $aim \n\n Icq: \n $icq\n\n";
      mail($to, $subject, $body);

      if (empty($fname) || empty($lname) || empty($email) || empty($gender) || empty($age) || empty($location) || empty($christian) || empty($whatpartofstaff) || empty($HowLongMemberOfNBJF) || empty($WhyOnStaff) || empty($HowCanUContribute) || empty($InternetAccess)) echo "You must complete the required fields to send the application.";
        else {
        $retval="Application Sent. Thank You!";        
}  
}

?>

<? echo $retval;?>

<div id="centeredimage">
<img src="/images/pagetitles/staffapplication.png" alt="Staff Application" />
</div>
<form method="post" action="/staffapplication">
<span class="applications"><strong>First Name:</strong></span><br />
<input name="FName" type="text" id="FName" size="20" maxlength="40" class="appstyle" />
<br />
<br />
<span class="applications"><strong>Last Name:</strong></span><br />
<input name="LName" type="text" id="LName" size="20" maxlength="40" class="appstyle" />
<br />
<br />
<span class="applications"><strong>Valid E-mail Address:</strong></span><br />
<input type="text" size="50" maxlength="100" name="email" class="appstyle" />
<br />
<br />
<span class="applications"><strong>Gender:</strong></span><br />
<span class="subapplications">Male:</span><input type="radio" value="Male" name="gender" />
<span class="subapplications">Female:</span><input type="radio" value="Female" name="gender" />
<br />
<br />
<span class="applications"><strong>Age:</strong></span><br />
<select name="age" class="appstyle1">
<option value="13-18">13-18</option>
<option value="19-25">19-25</option>
<option value="26-32">26-32</option>
<option value="33-41">33-41</option>
<option value="42-48">42-48</option>
<option value="49-54">49-54</option>
<option value="55-61">55-61</option>
<option value="62-68">52-68</option>
<option value="69-75">69-75</option>
<option value="76-82">76-82</option>
<option value="83+">83+</option></select>
<br />
<br />
<span class="applications"><strong>What state/province are you in?</strong></span><br />
<input type="text" size="25" maxlength="40" name="location" class="appstyle" />
<br />
<br />
<span class="applications"><strong>Are you a Christian?</strong></span><br />
<select name="christian" class="appstyle1">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br />
<br />
<span class="applications"><strong>Please check all that apply to you:</strong></span><br />
<input name="CollegeStudent" type="checkbox" id="CollegeStudent" value="Yes" />
<span class="subapplications">College Student</span>
<input name="HighSchoolStudent" type="checkbox" id="HighSchoolStudent" value="Yes" />
<span class="subapplications">High-School Student</span>
<input name="MiddleSchoolStudent" type="checkbox" id="MiddleSchoolStudent" value="Yes" />
<span class="subapplications">Middle School/Jr. High Student</span>
<br />
<input name="OutOfSchool" type="checkbox" id="OutOfSchool" value="Yes" />
<span class="subapplications">Out of School</span>
<input name="Unemployed" type="checkbox" id="Unemployed" value="Yes" />
<span class="subapplications">Unemployed</span>
<input name="Employed" type="checkbox" id="Employed" value="Yes" />
<span class="subapplications">Employed</span>
<br />
<input name="Retired" type="checkbox" id="Retired" value="Yes" />
<span class="subapplications">Retired</span>
<br />
<br />
<span class="applications"><strong>What staff position are you applying for?</strong></span><br />
<select name="whatpartofstaff" class="appstyle1">
<option value="Administrator">Administrator</option>
<option value="Senior Manager">Senior Manager</option>
<option value="Manager">Manager</option>
<option value="NBJF Developer">NBJF Developer</option>
<option value="Myspace Editor">Myspace Editor</option>
</select>
<br />
<br />
<span class="applications"><strong>How long have you been a member of NBJF?</strong></span><br />
<input name="HowLongMemberOfNBJF" type="text" id="HowLongMemberOfNBJF" size="25" maxlength="40" class="appstyle" />
<br />
<br />
<span class="applications"><strong>Why do you want to be apart of the NBJF Staff?</strong></span><br />
<textarea name="WhyOnStaff" cols="50" rows="5" id="WhyOnStaff" class="apparea"></textarea>
<br />
<br />
<span class="applications"><strong>What/how can you contribute to NBJF?</strong></span><br />
<textarea name="HowCanUContribute" cols="50" rows="5" id="HowCanUContribute" class="apparea"></textarea>
<br />
<br />
<span class="applications"><strong>How often do you have access to the internet?</strong></span><br />
<select name="InternetAccess" id="InternetAccess" class="appstyle1">
<option value="Less than 6 hrs. a day">Less than 6 hrs. a day</option>
<option value="2-3 times">2-3 times</option>
<option value="6+ times">6+ times</option>
<option value="Off and on throughout the day">Off and on throughout the day</option></select>
<br />
<br />
<span class="applications"><strong>MSN/Windows Live Messenger:</strong></span><br />
<input type="text" size="40" maxlength="50" name="msn" class="appstyle" />
<br />
<br />
<span class="applications"><strong>Yahoo Messenger:</strong></span><br />
<input type="text" size="40" maxlength="50" name="yahoo" class="appstyle" />
<br />
<br />
<span class="applications"><strong>AIM:</strong></span><br />
<input type="text" size="40" maxlength="50" name="aim" class="appstyle" />
<br />
<br />
<span class="applications"><strong>Skype:</strong></span><br />
<input type="text" size="40" maxlength="50" name="skype" class="appstyle" />
<br />
<br />
<span class="applications"><strong>ICQ:</strong></span><br />
<input type="text" size="40" maxlength="50" name="icq" class="appstyle" />
<br />
<br />
<input type="submit" value="Submit" name="submit" class="appstyle" /> <input type="reset" name="Submit2" value="Reset" class="appstyle" />
</form>


--------------------
No Signature... No Images allowed.. :(
Go to the top of the page
 
+Quote Post
Jason
post Jul 26 2008, 01:54 AM
Post #2


Master of the Universe
Group Icon

Posts: 1,298
Joined: 15-February 08
From: London, England


You are sending the mail before you check the fields are full. If you move the mail function into the else it will work the way you want it to.

CODE
if (empty($fname) || empty($lname) || empty($email) || empty($gender) || empty($age) || empty($location) || empty($christian) || empty($whatpartofstaff) || empty($HowLongMemberOfNBJF) || empty($WhyOnStaff) || empty($HowCanUContribute) || empty($InternetAccess))
{
    echo "You must complete the required fields to send the application.";
} else {
    mail($to, $subject, $body);
    $retval="Application Sent. Thank You!";        
}


--------------------
Go to the top of the page
 
+Quote Post
mcdanielnc89
post Jul 26 2008, 04:47 PM
Post #3


Rapid Squeezer
****

Posts: 252
Joined: 13-February 08
From: Missouri, USA


Yea, that didn't work...


--------------------
No Signature... No Images allowed.. :(
Go to the top of the page
 
+Quote Post
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   9 caminowebmaster 241 15th February 2008 - 06:24 PM
Last post by: Jacob
No New Posts 12 xkatx21x 728 28th February 2008 - 11:41 PM
Last post by: Rakuli
No New Posts   4 thesealportalteam 784 20th February 2008 - 09:00 AM
Last post by: thesealportalteam
No new   14 902 724 22nd February 2008 - 02:45 AM
Last post by: c010depunkk
No New Posts   5 thesealportalteam 422 22nd February 2008 - 11:48 PM
Last post by: Monie