Jump to content

form multi select post


sanchez77

Recommended Posts

So I have a an HTML form with a list box that allows mulitple selections. How do I mail all the selections?

 

My form:

                        <select name="Services" size="4" multiple id="Services">
                          <option value="option1">option1</option>
                          <option value="option2">option2</option>
                          <option value="option3">option3</option>
                          <option value="option4">option4</option>
                  </select>

 

 

PHP Code


$post_Services = $_POST["Services"];

$body .= "Services: ".$post_Services."\n";

  mail( "[email protected]", "Form, $body, $message, "From: [email protected]>");
?>


 

Thanks for the help.

 

Link to comment
https://forums.phpfreaks.com/topic/179106-form-multi-select-post/
Share on other sites

i believe that a select element with multiple option selections will return an array. in that case, if you want to send an individual e-mail for each address, you'll need to loop through $_POST['Services'] with a foreach() loop.

 

if you want to send one bulk e-mail with a length header To: or CC: field, you can either construct that list using a foreach() loop or the implode function.

handling arrays is actually a rather basic concept, and one that would be good to familiarize yourself with. here's a good section in the PHP manual on how to deal with arrays in PHP:

 

http://us2.php.net/manual/en/language.types.array.php

 

have a read-through of that, play around, and come back if you run into any problems implementing the code. this is really the sort of thing you're best off tinkering with yourself.

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.