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
<select name="e;person"e; size="e;2"e;>
<option value="e;bla@blabla.com|Jim_bo"e;>Jim_bo</option>
<option value="e;blabla@bla.com|Jack"e;>Jack</option>
</select>
<?
if (!empty($_POSTї'person']))
{
$info = explode('|',$_POSTї'person']);
//$infoї0] is now his email
//$infoї1] is now his name
$fromHeader = $infoї1] . ' <' . $infoї0] . '>';
mail($to, $subject, $message, $fromHeader);
}
?>
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.