wrathican Posted August 10, 2007 Share Posted August 10, 2007 hey guys i have a function that sends an email in that function i have an if statement to decide what email address that email should be sent to. the problem is i cant see the email address outside of the if statement when i echo it. am i meant to be able to see it? if not then how do get to see it? if so then take a look at my code n see if you can tell whats up. please help me this is the last bit needed to complete the website! function sendbooking($name, $email, $house, $street, $town, $postcode, $home, $mobile, $tour, $price, $type, $day, $month, $year, $experience, $health) { //this is gets the name of the tour instead of id $query = "SELECT * FROM cy_list WHERE li_id='" . $tour . "'"; $result = mysql_query($query); while($row = mysql_fetch_array($result,MYSQL_NUM)) { $tourn = $row[2]; } if (($type == 'course') && ($tour == 'INTERMEDIATE')) { $sendto = "intermediatecourses@cycleyorkshire.co.uk"; } elseif (($type == 'course') && ($tour == 'BEGGINNER')) { $sendto = "begginercourses@cycleyorkshire.co.uk"; }elseif ($type == 'tour') { $sendto = "tours@cycleyorkshire.co.uk"; } echo $sendto; $subject = "Course/Tour Booking"; $headers = "From: " . $_POST['name']; $headers .= "<" . $_POST['email'] . ">\r\n"; $headers .= "Reply To: " . $_POST['email'] . "\r\n"; $headers .= "Return-Path: " . $_POST['email']; //starts collecting the form vars. $type = $_POST['type']; $name = $_POST['name']; $email = $_POST['email']; $house = $_POST['house']; $street = $_POST['street']; $town = $_POST['town']; $postcode = $_POST['postcode']; $home = $_POST['home']; $mobile = $_POST['mobile']; $price = $_POST['price']; $day = $_POST['day']; $month = $_POST['month']; $year = $_POST['year']; $date = $day . "/" . $month . "/" . $year; $experience = $_POST['experience']; $health = $_POST['health']; //put form vars into one variable $booking = "\nName: " . $name . "\n"; $booking .= "E-Mail: " . $email . "\n"; $booking .= "House no/name: " . $house . "\n"; $booking .= "Street: " . $street . "\n"; $booking .= "Town: " . $town . "\n"; $booking .= "Postcode: " . $postcode . "\n"; $booking .= "Home No: " . $home . "\n"; $booking .= "Mobile: " . $mobile . "\n"; $booking .= "Tour: " . $tourn . "\n"; $booking .= "Prices: " . $price . "\n"; $booking .= "Date: " . $date . "\n"; $booking .= "Experience: " . $experience . "\n"; $booking .= "Health: " . $health . "\n"; //$body is whole email message sent to the user/owner $body = "There has been a new request for a booking:" . $booking; if (mail($sendto, $subject, $body, $headers)) { $sendto = $_POST['email']; $subject = "CycleYorkshire.co.uk E-Mail"; $headers = "From: Iain Johnson"; $headers .= "<iain@cycleyorkshire.co.uk>\r\n"; $headers .= "Reply To: iain@cycleyorkshire.co.uk\r\n"; $headers .= "Return-Path: iain@cycleyorkshire.co.uk"; $body = "Thank you for your booking. Here is a copy of the booking you have made: " . $booking; mail($sendto, $subject, $body, $headers); echo "Thank you for your booking. You will receive a copy of your booking shortly. Please do not forget to check you \'Junk\' folder as sometimes these emails can be thought of as spam."; } else { echo "I\'m sorry. There seems to be a problem. Please go <a href=\'/booking.php\'>back</a> and try again."; } } Quote Link to comment https://forums.phpfreaks.com/topic/64232-solved-help-with-if-statement-in-function/ Share on other sites More sharing options...
gurroa Posted August 10, 2007 Share Posted August 10, 2007 You are filling $tourn varibale but testing $tour variable. while($row = mysql_fetch_array($result,MYSQL_NUM)) { $tourn = $row[2]; //! } if (($type == 'course') && ($tourn == 'INTERMEDIATE')) { $sendto = "intermediatecourses@cycleyorkshire.co.uk"; } elseif (($type == 'course') && ($tourn == 'BEGGINNER')) { $sendto = "begginercourses@cycleyorkshire.co.uk"; } elseif ($type == 'tour') { $sendto = "tours@cycleyorkshire.co.uk"; } else { // Unknown tour type return false; } echo $sendto; Quote Link to comment https://forums.phpfreaks.com/topic/64232-solved-help-with-if-statement-in-function/#findComment-320213 Share on other sites More sharing options...
HuggieBear Posted August 10, 2007 Share Posted August 10, 2007 You should be able to see it inside the function, but not outside. If your if statement, and your echo statement are both inside the function, then yes it should be echoed. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/64232-solved-help-with-if-statement-in-function/#findComment-320214 Share on other sites More sharing options...
wrathican Posted August 10, 2007 Author Share Posted August 10, 2007 ahh, thank you gurroa. that solved my problem straight up. i think id been staring at it for too long and it needed a fresh pair of eyes Quote Link to comment https://forums.phpfreaks.com/topic/64232-solved-help-with-if-statement-in-function/#findComment-320222 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.