I have the follow problem/issue. Would like to have it a bit nicer:

The vars $gender, $shoe_size, $clothing_size and $growth are an array(?).

And I like to have, instead each line with $gender[0] something dynamic...

My problem I have, how I do it exactly, that I get each line as I have at the moment.

Here is my code:

<?php
    error_reporting(E_ALL);
    require('../includes/class.phpmailer.php');
    require('../includes/class.smtp.php');
    require('../includes/class.pop3.php');
    require('../includes/configdb.php');
    //var_dump($_REQUEST);
    $lang               = $_REQUEST["lang"]; //]=> string(2) "en" 
    $type               = $_REQUEST["type"]; //=> string(7) "courses" 
    $firstname          = $_REQUEST["firstname"]; //=> string(5) "Simon" 
    $secondname         = $_REQUEST["secondname"]; //=> string(8) "Vetterli" 
    $hotel              = $_REQUEST["hotel"]; //=> string(14) "Hotel on Samui" 
    $email              = $_REQUEST["email"]; //=> string(21) "myemail" 
    $facebook           = $_REQUEST["facebook"]; //=> string(16) "Facebook account" 
    $gender             = $_REQUEST["gender"]; //=> array(2) { [0]=> string(4) "male" [1]=> string(4) "male" } 
    $shoe_size          = $_REQUEST["shoe_size"]; //=> array(2) { [0]=> string(5) "34-35" [1]=> string(5) "40-41" } 
    $clothing_size      = $_REQUEST["clothing_size"]; //=> array(2) { [0]=> string(2) "XS" [1]=> string(0) "" } 
    $growth             = $_REQUEST["growth"]; //=> array(2) { [0]=> string(6) "Height" [1]=> string(0) "" } 
    $course             = $_REQUEST["course"]; //=> string(1) "5" 
    $learning_discount  = $_REQUEST["learning_discount"]; //=> string(3) "yes" 
    $course_option      = $_REQUEST["course_option"]; //=> string(8) "11:16000" 
    $dates              = $_REQUEST["dates"]; //=> string(10) "2014-12-20" 
    $room_type          = $_REQUEST["room_type"]; //=> string(0) "" 
    $room_count         = $_REQUEST["room_count"]; //=> string(1) "1" } 
    $room_nights        = $_REQUEST["room_nights"]; //=> string(1) "1" 
    $comment            = $_REQUEST["comment"]; //=> string(0) ""
    $summary            = $_REQUEST["summary"]; //=> string(605) "
    $from_name  = $firstname.' '.$secondname;
    $femail     = $email;   
    $to = "receipt_email";
    $date = date('Y-m-d');
    $subject = 'Booking '.$type.'-'.$date.' from '.$from_name;
    // $toCC        = "myemail";
    // Mail verschicken
    $header  = "MIME-Version: 1.0\r\n";
    $header .= "Content-type: text/html; charset=utf-8\r\n";
    $header .= "From: $from_name <$femail>\r\n";
    $header .= "Reply-To: $femail\r\n";
    $header .= "X-Mailer: PHP ". phpversion();
    $pinformation = "
    You got the follow enquiry:<br />
    <br />
    Booking Date: $date<br />
    Name: $from_name<br />
    Hotel/Resort: $hotel<br />
    Email: $email<br />
    FB: $facebook<br />
    Language: $lang<br />
    <br />";
    $students = "
    Student #1: Gender: $gender[0]    / Shoe-Size: $shoe_size[0] / Clothing Size: $clothing_size[0] / Heigth: $growth[0]<br />
    Student #2: Gender: $gender[1]    / Shoe-Size: $shoe_size[1] / Clothing Size: $clothing_size[1] / Heigth: $growth[1]<br />
    Student #3: Gender: $gender[2]    / Shoe-Size: $shoe_size[2] / Clothing Size: $clothing_size[2] / Heigth: $growth[2]<br />
    Student #4: Gender: $gender[3]    / Shoe-Size: $shoe_size[3] / Clothing Size: $clothing_size[3] / Heigth: $growth[3]<br />
    Student #5: Gender: $gender[4]    / Shoe-Size: $shoe_size[4] / Clothing Size: $clothing_size[4] / Heigth: $growth[4]<br />
    Student #6: Gender: $gender[5]    / Shoe-Size: $shoe_size[5] / Clothing Size: $clothing_size[5] / Heigth: $growth[5]<br />
    Student #7: Gender: $gender[6]    / Shoe-Size: $shoe_size[6] / Clothing Size: $clothing_size[6] / Heigth: $growth[6]<br />
    Student #8: Gender: $gender[7]    / Shoe-Size: $shoe_size[7] / Clothing Size: $clothing_size[7] / Heigth: $growth[7]<br />
    Student #9: Gender: $gender[8]    / Shoe-Size: $shoe_size[8] / Clothing Size: $clothing_size[8] / Heigth: $growth[8]<br />
    Student #10: Gender: $gender[9]   / Shoe-Size: $shoe_size[9] / Clothing Size: $clothing_size[9] / Heigth: $growth[9]<br />
    <br />";
    $ainformation = "
    Dates to start the course: $dates<br />
    Learning Discount: $learning_discount<br />
    Comment: $comment<br />
    <br />";
    $acomondation = "
    Room Type: $room_type<br />
    Nr Rooms: $room_count<br />
    Nr Nights: $room_nights<br />
    <br />";
    $message = $pinformation.$students.$ainformation.$acomondation.$summary;
    $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/'; 
    // Run the preg_match() function on regex against the email address
    if (preg_match($regex, $femail))
        {
          //Instanz von PHPMailer bilden
          $mail = new PHPMailer();
                          $mail->From = $femail;
                          //Name des Abenders setzen
                          $mail->FromName = $from_name;
                          //Empfängeradresse setzen
                          $mail->AddAddress($to);
                          //$mail->AddCC($toCC);
                          $mail->AddBCC("myemail");
                          //Betreff der Email setzen
                          $mail->Subject = $subject;
                          $mail->IsHTML(true); //Versand im HTML-Format festlegen
                          //Text der EMail setzen
                          $mail->Body = $message;
                          //EMail senden und überprüfen ob sie versandt wurde
                          if(!$mail->Send()){
                            echo "There was an error sending your reservation." . $mail->ErrorInfo;
                            exit;
                        }
                        header('Location:/'.$lang.'/thankyou');
                        exit;
        }
    ?>

Recommended Answers

All 5 Replies

It seems all these arrays will have the same size, so you can loop them together, for example:

# read size of one of these arrays
$count = count($_REQUEST['gender']);

# loop
for($i = 0, $e = 1; $i < $count; $i++, $e++)
{
    echo "Student #{$e}: Gender: $gender[$i]    / Shoe-Size: $shoe_size[$i] / Clothing Size: $clothing_size[$i] / Heigth: $growth[$i]<br />";
}

Thank You it worked for me like this.
I changed my code a bit to the follow code:

# read size of one of these arrays
$count = count($_REQUEST['gender']);
# loop
for($i = 0, $e = 1; $i < $count; $i++, $e++)
{
    $studens.= "Student #{$e}: Gender: $gender[$i]    / Shoe-Size: $shoe_size[$i] / Clothing Size: $clothing_size[$i] / Heigth: $growth[$i]<br />";
}

Hi Cereal

I am maybe blind or so... just got nearly the same problem as before. I not get the values of the selectfields. I got 0 - 8 instead of some strings.

Here is the url: http://web159.login-142.hoststar.ch/memberd/de/prices/

Here is my code I use to get it:

# read size of one of these arrays
$count = count($_REQUEST['BX_NAME']);
# loop
for($i = 0, $e = 1; $i < $count; $i++, $e++)
{
$divers.= "Diver/PAX #{$e}: Name: $BX_NAME[$i] / Shoe-Size: $BX_shoesize[$i] / Weight: $BX_weight[$i] / Heigth: $BX_height[$i]<br />";
}

I did a postdump and this works, I mean I get and see what I should get.

Hi!

Each field name of the form must be an array, so for example, change:

<select id="field-BX_height" name="BX_height">

To:

<select id="field-BX_height" name="BX_height[]">

As you are already doing with BX_NAME[], apply the same concept to height and weight and then it should work fine.

It worked out...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.