Jump to content

Need Help on an Email Script for a form


collegedrew2008

Recommended Posts

This was made for a website my boss is working on and I didnt make it. I cant seem to get it to send the users responses to the default e-mail and I'm looking for some help please. Fill free to ask for better clarification or full source code, I only cut and pasted the code with the e-mail script.


<?php

[color=red]$email_to = "";
$email_subject = "";
$email_headers = "";
$email_string = "";[/color]

//This script runs in steps and are described as follows....
$step = 1; // this variable is used to determine what step the user is on
  // 1: no info entered yet
  // 3: submit basic information
  // 6: submit details information

// the following code sets the step variable to the correct value based on which button was clicked
if( isset($_POST['beginning']) ){
$step = 1;
}
if( isset($_POST['basicFinalize']) ){
$step = 3;
}
if( isset($_POST['detailsFinalize']) ){
$step = 6;
}
//echo "STEP = ".$step."<br>";

if( $step == 3 || $step == 6){
$location = $_POST['location'];
$date = convertDate($_POST['year'],$_POST['month'],$_POST['day']);
$startHour = convertHour($_POST['startHour'],$_POST['startMeridian']);
$endHour = convertHour($_POST['endHour'],$_POST['endMeridian']);
$startTime = $startHour.":".$_POST['startMinute'].":00";
$endTime = $endHour.":".$_POST['endMinute'].":00";
$numMales = $_POST['numMales'];
$numFemales = $_POST['numFemales'];
$maxMales = $_POST['maxMales'];
$maxFemales = $_POST['maxFemales'];
$comments = $_POST['comments'];
$uID = $_SESSION['userID'];

[color=red]// setup email
$email_to .= "[email protected]";
$email_subject .= "Automated Email from PBOT Website Form";
$email_headers .= "From: [email protected]";
$email_string .= "Simple Sighting Submission\n";
$email_string .= "\nUser: ".$_SESSION['username'];
$email_string .= "\nSighting Location: ".$location;
$email_string .= "\nSighting Date: ".$date."\nSighting Start Time: ".$startTime;
$email_string .= "\nSighting End Time: ".$endTime;
$email_string .= "\nNumber of Males Observed: ".$numMales;
$email_string .= "\nNumber of Females Observed: ".$numFemales;
$email_string .= "\nNumber of Males Observed Simultaneously: ".$maxMales;
$email_string .= "\nNumber of Females Observed Simultaneously: ".$maxFemales;
$email_string .= "\nAdditional Comments:\n".$comments;[/color]

if($step == 3){
[color=red]// send the email
mail($string_to, $string_subject, $email_string, $email_headers);[/color]

mysql_close();
header("Location: welcome.php");
}
}//end if($step == 3 || $step == 6)

if($step == 6){
//Get the current sighting ID for use in inserting the bird details data....
    $uID = $_SESSION['userID'];
$query = "SELECT * from sighting where userID = '$uID' and date = '$date' and startTime = '$startTime';";
$result = mysql_query($query);
$sID = mysql_result($result, 0, 'sightingID');

//insert all male details into the data base...
for($i = 1; $i<=$numMales; $i++){

[color=red]// add new bird header to e-mail
$email_string .= "\n\nMale Bird Details\n";
$email_string .= "Male Bird ".($i+1)." Details:\n";[/color]
// -- >

$temp1 = "Mbird".$i;
$temp2 = $_SESSION[$temp1];
$upperleft = $temp2[0];
$upperright = $temp2[1];
$lowerleft = $temp2[2];
$lowerright = $temp2[3];
$numVisits = floor($temp2[4]);
$numFVisits = floor($temp2[5]);
$mfeederTime = ceil($temp2[6]);
$defaultColor = "N/A";
$cul = strcmp($upperleft,$defaultColor);
$cur = strcmp($upperright,$defaultColor);
$cll = strcmp($lowerleft,$defaultColor);
$clr = strcmp($lowerleft,$defaultColor);
$query = "insert into bird(sightingID,gender,numberVisits,numTripstoFeed,feederTime)
values('$sID','male','$numVisits','$numFVisits','$mfeederTime')";
$result = mysql_query($query);
$query = "select max(birdID) as t from bird where sightingID = '$sID'";
$result = mysql_query($query);
$bID = mysql_result($result,0,'t');
if($cul == 0 && $cur == 0 && $cll == 0 && $clr == 0){
[color=red]$email_string .= "\nNO BANDING INFO FOR THIS BIRD\n";[/color]
}
else{
[color=red]$email_string .= "\tUpper Left Band Color: ".$upperleft."\n";
$email_string .= "\tUpper Right Band Color: ".$upperright."\n";
$email_string .= "\tLower Left Band Color: ".$lowerleft."\n";
$email_string .= "\tLower Right Band Color: ".$lowerright."\n";[/color]

$query = "insert into banding(birdID,upperLeft,upperRight,lowerLeft,lowerRight)
values('$bID','$upperleft','$upperright','$lowerleft','$lowerright')";
$result = mysql_query($query);
}
[color=red]// add male details to e-mail
$email_string .= "\tNumber of Area Visits: ".$numVisits."\n";
$email_string .= "\tNumber of Feeder Visits: ".$numFVisits."\n";
$email_string .= "\tFeeder Time: ".$mfeederTime."\n";
$email_string .= "\n";[/color]

}//end insert of male detail data




//insert all female detail data
for($i = 1; $i<=$numFemales; $i++){

[color=red]// add new bird header to e-mail
$email_string .= "\n\nMale Bird Details\n";
$email_string .= "Female Bird ".($i+1)." Details:\n";[/color]
// -- >

$temp1 = "Fbird".$i;
$temp2 = $_SESSION[$temp1];
$upperleft = $temp2[0];
$upperright = $temp2[1];
$lowerleft = $temp2[2];
$lowerright = $temp2[3];
$numVisits = floor($temp2[4]);
$numFVisits = floor($temp2[5]);
$ffeederTime = ceil($temp2[6]);
$defaultColor = "N/A";
$cul = strcmp($upperleft,$defaultColor);
$cur = strcmp($upperright,$defaultColor);
$cll = strcmp($lowerleft,$defaultColor);
$clr = strcmp($lowerleft,$defaultColor);
$query = "insert into bird(sightingID,gender,numberVisits,numTripstoFeed,feederTime)

values('$sID','female','$numVisits','$numFVisits','$ffeederTime')";
$result = mysql_query($query);
$query = "select max(birdID) as t from bird where sightingID = '$sID'";
$result = mysql_query($query);
$bID = mysql_result($result,0,'t');
if($cul == 0 && $cur == 0 && $cll == 0 && $clr == 0){
$email_string .= "\nNO BANDING INFO FOR THIS BIRD\n";
}
else{
[color=red]$email_string .= "\tUpper Left Band Color: ".$upperleft."\n";
$email_string .= "\tUpper Right Band Color: ".$upperright."\n";
$email_string .= "\tLower Left Band Color: ".$lowerleft."\n";
$email_string .= "\tLower Right Band Color: ".$lowerright."\n";[/color]

$query = "insert into banding(birdID,upperLeft,upperRight,lowerLeft,lowerRight)

values('$bID','$upperleft','$upperright','$lowerleft','$lowerright')";
$result = mysql_query($query);
}

// add female details
[color=red]$email_string .= "\tNumber of Area Visits: ".$numVisits."\n";
$email_string .= "\tNumber of Feeder Visits: ".$numFVisits."\n";
$email_string .= "\tFeeder Time: ".$mfeederTime."\n";
$email_string .= "\n";[/color]

}//end insert of Female detail data

[color=red]// send the e-mail
mail($string_to, $string_subject, $email_string, $email_headers);[/color]
}//end if($step == 6)

?>
Link to comment
https://forums.phpfreaks.com/topic/32266-need-help-on-an-email-script-for-a-form/
Share on other sites

You need to test one thing at a time to find the problem. I suggest you first create a test page to send an email to the address in question. It could be that spam filtering is blocking the email or mail() is not even enabled. If you do not receive the test email then you first need to fix that problem.

Assuming you did receive the test email then you can move on to debugging your script. I see that there is already a debuggin line that is commented out:

//echo "STEP = ".$step."";

have you uncommented that line and verified that you are getting the appropriate values. If no, fix that, otherwise move on to the next test. I would next echo all the email variables to the page prior to calling the mail function to verify that the values are what you expect.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.