Page 1 of 1

variables

Posted: Wed Mar 23, 2005 8:37 pm
by Jim_Bo
Hi,

I am trying to setup a mail() form .. so the person can choose from a list of people of whom they want to contact .. I have used a list menu below to choose from:

Code: Select all

<select name="person" size="2">
   <option value="bla@blabla.com">Jim_bo</option>
   <option value="blabla@bla.com">Jack</option>
</select>
Then grab the variable using $person = $_POST['person']; which works fine .. it emails the correct person from their choice .. But in the "from" part of the email it displays the email address, How can I set it so in the "from" it displays the name of the person from the select box?

Thanks ..

Posted: Wed Mar 23, 2005 8:44 pm
by John Cartwright
try something like this maybe?

Code: Select all

<select name="person" size="2">   
<option value="bla@blabla.com|Jim_bo">Jim_bo</option>   
<option value="blabla@bla.com|Jack">Jack</option>
</select>

<?

if (!empty($_GET['person']))
{
     $info = explode('|',$_POST['person']);

     //$info[0] is now his email
     //$info[1] is now his name
}
?>

Posted: Wed Mar 23, 2005 8:51 pm
by Jim_Bo
Hi,

Hmmz I dont fully understand the logic to the code you posted .. Tried to incorperate it .. but no go so far ..

Thanks ..

Posted: Wed Mar 23, 2005 9:37 pm
by feyd

Code: Select all

&lt;select name=&quote;person&quote; size=&quote;2&quote;&gt;   
&lt;option value=&quote;bla@blabla.com|Jim_bo&quote;&gt;Jim_bo&lt;/option&gt;   
&lt;option value=&quote;blabla@bla.com|Jack&quote;&gt;Jack&lt;/option&gt;
&lt;/select&gt;
&lt;?
 
if (!empty($_POST&#1111;'person']))
{
     $info = explode('|',$_POST&#1111;'person']);
 
     //$info&#1111;0] is now his email
     //$info&#1111;1] is now his name

     $fromHeader = $info&#1111;1] . ' &lt;' . $info&#1111;0] . '&gt;';
     mail($to, $subject, $message, $fromHeader);
}
?&gt;

Posted: Thu Mar 24, 2005 9:07 am
by s.dot
alternatively you could use an additional form field for the person to input their name, and add it to the header for mail();

Check if there is a name present, and if not provide an error message.