Jump to content

Sending an email depending on drop down


KittyLou

Recommended Posts

I'm fairly new to PHP so bear with me if I'm asking something really stupid.

 

I'm trying to create a form with two drop down menus, (both populated from mysql databases).

 

One of the databases has user names in it.

The other has managers in it + their email addresses.

 

The idea is that the user chooses their name and the name of the manager they will be working for and it then sends an email to the relevant manager telling them that the user's name and what time they have logged on.

 

I've worked out how to populate the drop down menus from the database, and how to send the time and name via email. Unfortunately I haven't worked out how to tie them together or how to send to the different email addresses.

 

I've been staring at the code so long it now looks like gibberish. Can anyone help me make sense of it?

 

 

This is the code I'm using for my drop down menus (well, for the one with emails attached)

 

<?php

$hostname = "localhost"; 
$db_user = "db_user"; 
$db_password = "db_password"; 

$connect = mysql_connect($hostname, $db_user, $db_password) or
die ("Could not connect to database.");

mysql_select_db("projectmanager");

$query = mysql_query(
"SELECT `pm_name`
FROM `projectmanager`"
) or die (mysql_error());

echo "<select name='projectmanager'>\n";

while ($data1 = mysql_fetch_array($query, MYSQL_ASSOC))
{
echo " <option value='{$data1['pm_name']}'>
{$data1['pm_name']}</option>\n";
}

echo "</select>\n";

?>

 

And this is the code I was using for the email, (obviously I need to change the $to option somehow) though it's currently not sending the PM name in the email.

 

<?
if($Submit){

$to="example@example.co.uk";

$subject="$pm_name - $Submit";

$time=date('F j, Y, H:i:s');


$message="$pm_name - $Submit - $time";

mail($to,$subject,$message,$mail_from);
echo "<center><br /><br /><b>Your contact information has been sent</b></center>";
}else{

// Do following codes if not found "Submit" value.(Not submitted) 
?>

 

Any advice anyone?

 

Edited to add: I did search for help with this (google etc) but could only find separate tutorials on populating drop downs and on sending to multiple addresses. And it seems I'm not quite clever enough to connect them

Link to comment
Share on other sites

Don't worry to ask questions if you're willing to learn(:

Ok, let's get started. I assume you have already got the drop down menu and sending mails to different email address working.

You can try to use the switch statement.

 

I'm probably missing something really obvious, but I can't actually make sense of that page (I'm very glad I start a web design course on the 1st, things might make more sense then)

 

I can't quite figure out how it'd relate to my drop down or my database.

 

I get the feeling I'm going to be apologising for my lack of knowledge a lot on here  :-[

 

pikemsu28> I've changed those bits of my code but I'm not receiving any emails, not getting any error messages either though

Link to comment
Share on other sites

No, sorry, I lie, it's working now. No idea why it didn't work earlier.

 

The only problem I have now is that the email is arriving saying " - Log On - September 19, 2007, 15:48:55"

 

When it's meant to say "User 1 - Log On - September 19, 2007, 15:48:55"

 

The code for that bit is..

<?php

$hostname = "localhost"; 
$db_user = "user"; 
$db_password = "password"; 
$db_table = "logon"; 

$connect = mysql_connect($hostname, $db_user, $db_password) or
die ("Could not connect to database.");

mysql_select_db("logon");

$query = mysql_query(
"SELECT `user_name`
FROM `logon`"
) or die (mysql_error());

echo "<select name='logon'>\n";

while ($name = mysql_fetch_array($query, MYSQL_ASSOC))
{
echo " <option value='{$name['user_name']}'>
{$name['user_name']}</option>\n";
}

echo "</select>\n";

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.