Jump to content

[SOLVED] help with if statement in function


wrathican

Recommended Posts

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 = "[email protected]";
} elseif (($type == 'course') && ($tour == 'BEGGINNER')) {
    $sendto = "[email protected]";
}elseif ($type == 'tour') {
    $sendto = "[email protected]";
}
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 .= "<[email protected]>\r\n";
  $headers .= "Reply To: [email protected]\r\n";
  $headers .= "Return-Path: [email protected]";
  $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.";
}
}

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 = "[email protected]";
} elseif (($type == 'course') && ($tourn == 'BEGGINNER')) {
    $sendto = "[email protected]";
} elseif ($type == 'tour') {
    $sendto = "[email protected]";
} else {
    // Unknown tour type
    return false;
}
echo $sendto;

 

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.