Robert Mailloux
Robert Mailloux

Reputation: 397

PHP, EMAIL, Multiple Select drop down

Im having an issue with my first ever multiple select form. Ive read a lot of posts but cant figure out how to break the array out so that I can email the results of a multiple select form Here is what I have.

<select name="serv" id="serv" multiple>
 <option value = "Business Advocacy">Business Advocacy</option>
 <option value = "Business Planning & Advice">Business Planning & Advice</option>
 <option value = "Economic Development">Economic Development</option>
 <option value = "Export Assistance">Export Assistance</option>

In my php page I have the following:

function sendMail()   
{
 $org= $_POST['org'];
 $street= $_POST['street'];
 $city=  $_POST['city'];
 $state= $_POST['state'];
 $zip=  $_POST['zip'];
 $phone= $_POST['phone'];
 $ext= $_POST['ext'];
 $web=  $_POST['web'];
 $serv= $_POST['serv'];
 $description= $_POST['description'];
 $first= $_POST['first'];      
 $last=  $_POST['last'];
 $email= $_POST['email'];
 $position=  $_POST['position'];


 $to= '[email protected]';
 $message = '<html><body>';
 $message .= '<h1>Organizational Request To Be Added To Website</h1>';
 $message .= 'Org:' . $org . '<br />';
 $message .= 'Street:' . $street . '<br />';
 $message .= 'City:' . $city . '<br />';
 $message .= 'State:' . $state . '<br />';
 $message .= 'Zip:' . $zip . '<br />';
 $message .= 'Phone:' . $phone . '<br />';
 $message .= 'Ext.:' . $ext . '<br />';
 $message .= 'Web:' . $web . '<br />';
 $message .= 'Serv:' . $serv . '<br />';
 $message .= 'Desc:' . $description . '<br />';
 $message .= 'First:' . $first . '<br />';
 $message .= 'Last:' . $last . '<br />';
 $message .= 'Email:' . $email . '<br />';
 $message .= 'Position:' . $position . '<br />';
 $message .='</body></html>';
 $subject = "Website Request";
 $message = $message;
 $headers = "From:" . $email . "\r\n";
 mail($to, $subject, $message, $headers);
}

Problem I am having is figuring out how to email the $serv array contents. I tried using a for loop figuring that would be the easiest but I only get one of the contents mailed. Can someone take a look? I pulled out the forloop I had in there because it didnt work so I thought itd be easier to read with it removed.

Upvotes: 1

Views: 1734

Answers (1)

Quentin
Quentin

Reputation: 944009

PHP's form data parser is a little … odd. It will only support multiple values for elements of a given name if that name ends in [].

Change your HTML to:

<select name="serv[]" id="serv" multiple>

Then $_POST['serv'] will be an arry that you can loop over.

Upvotes: 1

Related Questions