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 = "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.";
}
}

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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