variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

variables

Post 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 ..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
}
?>
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post 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 ..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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;
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Post Reply