473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

drop down to e-mail

142 100+
Hi

I want to make a php from where you got your normal fields and a drop down.

However in the drop list i want to have like departments, sales, info, comment, ect.

If I select sales from the drop down list and press submit then it must go to sale@mydomain.com and if info is seleted it must go to info@mydomain.com

How I do this?

Kind Regards
Louwrens
Nov 2 '06 #1
14 3233
ronverdonk
4,258 Expert 4TB
If the variable of your drop down list selection is 'to_name' then something like. I use a switch statement because I don't know how many different adressees you have.
[php]
$sel = strip_tags(trim($_POST['to_name']));
switch ($sel) {
case 'sales' : $to = 'sale@mydomain.com';
break;
case 'info' : $to = 'info@mydomain.com';
break;
default : echo 'You have an error';
break;
}
// you use it in your mail statement as follows:
mail($to, $subject, $message, $headers);
[/php]

Ronald :cool:
Nov 2 '06 #2
webandwe
142 100+
Hi Ronald

I have gotten hold of just a normal php file which I can use wihtout the html page.

Can you help me with this one, I inserted the code and try to make it work but now I get errors and I don't know what I am doing wrong.

The orginal script before i started is below the line after my script.

File name = list.php

<html>
<body><?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;

mail($to, $subject, $message, $headers);
$sel = strip_tags(trim($_POST['to_name']));

switch ($sel) {
case 'louwrens' : $to = 'louwrens@mydomain.com';
break;
case 'support' : $to = 'support@mydomain.com';
break;
default : echo 'You have an error';
break;
echo "Your message has ben sent!";
}
//if "email" is not filled out, display the form
{
echo "<form method='post' action='list.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />

<textarea name='message' rows='15' cols='40'>
</textarea><br />

<input type='submit' />
</form>";
}
?></body>
</html>


---------------------------------------------------------------------------------------------------------------

File name = w3.php (original before I tried top inserted the script)

<html>
<body><?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( "my@email.com", "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='w3.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?></body>
</html>
Nov 3 '06 #3
ronverdonk
4,258 Expert 4TB
Before you post read the Posting Guidelines at the top of the forum page!! Especially the part about showing code within code, php or html tags.

I hope you don't expect me to read this unstructured display of code lines?

Ronald :cool:
Nov 3 '06 #4
webandwe
142 100+
Hi Ronald

Sorry I tought it auto formated, Well I inserted the tags, hope they work if they still wrong i'll do them again...But then you will have to give me some time cause I need to go for a while


File name = list.php

[PHP]<html>
<body><?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;

mail($to, $subject, $message, $headers);
$sel = strip_tags(trim($_POST['to_name']));

switch ($sel) {
case 'louwrens' : $to = 'louwrens@mydomain.com';
break;
case 'support' : $to = 'support@mydomain.com';
break;
default : echo 'You have an error';
break;
echo "Your message has ben sent!";
}
//if "email" is not filled out, display the form
{
echo "<form method='post' action='list.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />

<textarea name='message' rows='15' cols='40'>
</textarea><br />

<input type='submit' />
</form>";
}
?></body>
</html>[/PHP]

---------------------------------------------------------------------------------------------------------------

File name = w3.php (original before I tried top inserted the script)

<html>
<body>[PHP]<<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( "my@email.com", "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='w3.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>[/PHP]<</body>
</html>
Nov 3 '06 #5
ronverdonk
4,258 Expert 4TB
You mixed up the logic, issuing the sent message before the send and some more errors, like formgetting to fill the $headers var. I cleaned it up and gave some structure to it. It works.
[php]<html>
<body>
<?php
// initialize vars
$error = '';
$to = '';
// -------------------------------------
// if "email" is filled out, send email
// -------------------------------------
if (isset($_POST['email'])) {

// cleanse and assign to-email address
$email = strip_tags(trim($_POST['email']));
// cleanse and assign subject
$subject = strip_tags(trim($_POST['subject']));
// cleanse and assign message text
$message = strip_tags(trim($_POST['message']));
// set the address where it comes from
$headers = 'MyUser@MySite.com';

switch ($email) {
case 'louwrens' : $to = 'louwrens@mydomain.com';
break;
case 'support' : $to = 'support@mydomain.com';
default : break;
} // End switch

if ($to != '') {
if (mail($to, $subject, $message, $headers)) {
echo "Your email message has been sent!";
exit;
}
else
echo "Email could not be send.";
} // End if ($to ..
else
$error = '<p>Invalid email address specified!</p>';
} // End isset

// ------------------------------------------------------
// if "email" is not set or filled out, display the form
// ------------------------------------------------------
if ($error)
echo "<span style='color:red'>$error</span>";
echo "<form method='post' action='a.php'>
Email:
<input name='email' type='text' value='$email' /><br />
Subject:
<input name='subject' type='text' value='$subject' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>$message</textarea><br />
<input type='submit' value='Send email' />
</form>";
?>
</body></html>
[/php]

Ronald :cool:
Nov 3 '06 #6
webandwe
142 100+
Hi Ronald

Can you please tell me what I am doing wrong with the drop down select. Cause I cannot get it to work if you like select a option to send it to a email for that option.

I inserted it but for some reason I cannot get the thing to work. I removed all the stuff i tried and just left it as you gave it to me but with a drop down.

[PHP]
<html>
<body>
<?php
// initialize vars
$error = '';
$to = '';
// -------------------------------------
// if "email" is filled out, send email
// -------------------------------------
if (isset($_POST['email'])) {

// cleanse and assign to-email address
$email = strip_tags(trim($_POST['email']));
// cleanse and assign subject
$subject = strip_tags(trim($_POST['subject']));
// cleanse and assign message text
$message = strip_tags(trim($_POST['message']));
// set the address where it comes from
$headers = 'MyUser@MySite.com';

switch ($email) {
case 'louwrens' : $to = 'louwrens@greypebbles.com';
break;
case 'support' : $to = 'support@greypebbles.com';
default : break;
} // End switch

if ($to != '') {
if (mail($to, $subject, $message, $headers)) {
echo "Your email message has been sent!";
exit;
}
else
echo "Email could not be send.";
} // End if ($to ..
else
$error = '<p>Invalid email address specified!</p>';
} // End isset

// ------------------------------------------------------
// if "email" is not set or filled out, display the form
// ------------------------------------------------------
if ($error)
echo "<span style='color:red'>$error</span>";
echo "<form method='post' action='a.php'>
Email:
<select name="email" id="email">
<option value="$louwrens">louwrens</option>
<option value="$support">support</option>
</select>
Subject:
<input name='subject' type='text' value='$subject' /><br />
Message:<br />

<textarea name='message' rows='15' cols='40'>$message</textarea><br />
<input type='submit' value='Send email' />
</form>";
?>
</body></html>
[/php]
Nov 6 '06 #7
webandwe
142 100+
Hi Ronald

I got it working!!!! Thank you very much for your help.

later.
Nov 6 '06 #8
glady
23
Hi Ronald

I got it working!!!! Thank you very much for your help.

later.
Hi could you tell me if i select a drop down box value and press submit button it should go to two different mail boxes, is it possible, and if so, how to make it?
here is the code...
<td width="24%"><div align="right">Select Area:</div></td>
<td width="19%">
<select name="recipient" class="loginSelect">
<option value=""></option>
<option value="gotocentral@mydomain.com">Central </option>
<option value="gotowest@mydomain.com">West</option>
<option value="gotoeast@mydomain.com">East</option>
</select>
</td>
--------------------------------
My question is, if i select West, it should send the mail to both west as well as central. Just like if i choose east, it should send mail to both east and central. So how can i set both values in single option value.
Something like
<option value="gotowest@mydomain.com";"gotocentral@mydomai n.com">West</option>
Thanks
glady
Nov 8 '06 #9
ronverdonk
4,258 Expert 4TB
If you always send it to Central why bother to ask? Then your code could be:
[php]
switch ($email) {
case 'West' : $to = 'west@mydomain.com';
break;
case 'East' : $to = 'east@mydomain.com';
default : break;
} // End switch
// AND always to Central. MIND the comma!!
$to .= ", central@mydomain.com";
[/php]
Ronald :cool:
Nov 8 '06 #10
glady
23
If you always send it to Central why bother to ask? Then your code could be:
[php]
switch ($email) {
case 'West' : $to = 'west@mydomain.com';
break;
case 'East' : $to = 'east@mydomain.com';
default : break;
} // End switch
// AND always to Central. MIND the comma!!
$to .= ", central@mydomain.com";
[/php]
Ronald :cool:
Actually i am using FormMail.pl in php-nuke, so i dont need to get any email address from the person who submits the form by choosing the area and filling other form details.
The form contains some information need to be filled by choosing the area, and then submit.If the person choose central it should go to central@mydomain.com,
if the person chooses east, and click submit button, it should me mailed to east as well as central.
east@mydomain.com,central@mydomain.com
likewise if the user selects west and submit the form, the mail should be sent to
west@mydomain.com,central@mydomain.com
I have coding like,
<td width="24%"><div align="right">Select Area:</div></td>
<td width="19%">
<select name="recipient" class="loginSelect">
<option value=""></option>
<option value="central@mydomain.com">Central </option>
<option value="west@mydomain.com">West</option>
<option value="east@mydomain.com">East</option>
</select>
</td>

Do i need to change the option value for west and east like
<option value="central@mydomain.com">Central</option>
<option value="$West">West</option>
<option value="$East">East</option>
</select>
switch(what needs to be given){
case 'West' : $to='west@mydomain.com';
break;
case 'East' : $to='east@mydomain.com';
break;
default :break;
}
$to .=",central@mydomain.com";
Thanks
Nov 8 '06 #11
ronverdonk
4,258 Expert 4TB
I have told you before to enclose your code within code, php or html tags. If you keep persisting on NOT DOING that I will exclude your questions/replies!

Ronald :cool:
Nov 8 '06 #12
glady
23
I have told you before to enclose your code within code, php or html tags. If you keep persisting on NOT DOING that I will exclude your questions/replies!

Ronald :cool:
Sorry and i will keep that in mind and post questions accordings,
Thanks.
Nov 8 '06 #13
glady
23
Sorry and i will keep that in mind and post questions accordings,
Thanks.
Again i will post in acorrect format
Actually i am using FormMail.pl in php-nuke, so i dont need to get any email address from the person who submits the form by choosing the area and filling other form details.
The form contains some information need to be filled by choosing the area, and then submit.If the person choose central it should go to central@mydomain.com,
if the person chooses east, and click submit button, it should me mailed to east as well as central.
east@mydomain.com,central@mydomain.com
likewise if the user selects west and submit the form, the mail should be sent to
west@mydomain.com,central@mydomain.com
I have coding like,
Expand|Select|Wrap|Line Numbers
  1. [HTML]
  2. <td width="24%"><div align="right">Select Area:</div></td>
  3. <td width="19%">
  4. <select name="recipient" class="loginSelect">
  5. <option value=""></option>
  6. <option value="central@mydomain.com">Central </option>
  7. <option value="west@mydomain.com">West</option>
  8. <option value="east@mydomain.com">East</option>
  9. </select>
  10. </td>
  11. [/HTML]
  12.  
Do i need to change the option value for west and east like
Expand|Select|Wrap|Line Numbers
  1. [HTML]
  2. <option value="central@mydomain.com">Central</option>
  3. <option value="$West">West</option>
  4. <option value="$East">East</option>
  5. </select>
  6. switch(what needs to be given){
  7. case 'West' : $to='west@mydomain.com';
  8. break;
  9. case 'East' : $to='east@mydomain.com';
  10. break;
  11. default :break;
  12. }
  13. $to .=",central@mydomain.com";
  14. [/HTML]
  15.  
is that ok/?
Thanks
Nov 8 '06 #14
ronverdonk
4,258 Expert 4TB
The following looks the easiest solution to this. Since you always send to central, you can fill in that address. If one chooses another destination: just concatenate it to the existing address in $to. As follows:
[php]<option value="Central">Central</option>
<option value="West">West</option>
<option value="East">East</option>
</select>
.....
// assign the variables from the POST or GET array
......
$to = 'central@mydomain.com';
switch(what needs to be given)
{
case 'West' : $to .= ', west@mydomain.com';
break;
case 'East' : $to .= ', east@mydomain.com';
break;
default : break;
}[/php]
Don't forget you have to assign the values from the drop-down box to the 'what needs to be given' variable from the $_POST or $_GET array!

Ronald :cool:
Nov 8 '06 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: PT | last post by:
I got a form with many text boxes, checkboxes and 3 drop downs. From that 3, 2 are dependant. I can choose one drop down, and the next drop down should display the dependant values of the first...
2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
1
by: Dan | last post by:
This is one that has me stumped and I need an expert's input. Any ideas why the values from the second script-generated drop down list isn't recognized by the script to add time values to the...
3
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
1
by: pmelanso | last post by:
Hello, I have a drop down list which is dynatically loaded from a database and I have a second drop down list that is also dynatically loaded depending on what is selected in the first drop down...
7
by: callawayglfr | last post by:
I am building a database in access where I have a drop down box that relates to a text box, that part I have working but when someone selects information from the first drop down I need it to limit...
8
by: Ed Dror | last post by:
Hi there ASP.NET 2.0 VB & SQL Express Lest take Northwind Categories Products as example I create a table that hold these two together and I create a stored procedure like select ProductID,...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.