Jump to content


Photo

Sending an email using a dropdown box


  • Please log in to reply
12 replies to this topic

#1 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 07 October 2006 - 04:51 PM

I have a form that gets completed and then I want to email the results of the form to different people.  The person completing the form will choose who they want to send the results to.  I have a dropdown box, where the list of names used is obtained from the database.

Is there a way, that when a person hilites multiple names that the email can be sent to these people.

Here is what I have for the dropdown box.
<div>
                                        <center><B>Send this form to:</B><BR>
                                        <select name='tech' multiple>

                                        <?php

    $result = mysql_query("SELECT * FROM employees") or die(mysql_error());
    while ($row = mysql_fetch_assoc($result)) {
        echo "<option>$row[name]</option>";
    }

Once you have selected who the email goes to, and completed the form, I want to create a query that will send the email to these people when you press the submit button for the rest of the form.  The data is being saved in a database, but I don't have it set up to save the names of the people receiving an email (although I could if necessary.)

Thanks for any help as this has me totally stumped.

Ken

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 07 October 2006 - 05:21 PM

The name of the select needs to be an array ... fully explained with example code at http://onlinetools.o...iple_select.php
Legend has it that reading the manual never killed anyone.
My site

#3 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 07 October 2006 - 05:42 PM

If I use an array and do this, I will end up with something like this..........
<div>
                                        <center><B>Send this form to:</B><BR>
                                        <select name='emailname[]' multiple="multiple">

                                        <?php

    $result = mysql_query("SELECT * FROM employees") or die(mysql_error());
    while ($row = mysql_fetch_assoc($result)) {
        echo "<option>$row[name]</option>";
    }
$emailname=$_POST['emailname'];
	if ($emailname){
	 foreach ($emailname as $ename);	}

    ?></select></center>

Would I then be able to do something like this to get the email addresses into the TO field of the email script:

SELECT email from employees where $ename=name;

email is the column name in the DB table and name is the column title where the name is found.

Thanks,

Ken

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 07 October 2006 - 05:47 PM

i dont get it do you mean this select the members emails withn a pualldown list then be able to use the email of the user?

example
<div>
                                        <center><B>Send this form to:</B><BR>
                                        <select name='emailname[]' multiple="multiple">

                                        <?php

    $result = mysql_query("SELECT email FROM employees") or die(mysql_error());
    while ($row = mysql_fetch_assoc($result)) {
        echo "<option>$row[email]</option>";
    }

?></select></center>

might be wrong here only guessing.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 07 October 2006 - 05:53 PM

The dropdown box has a list of names (not email addresses) that it has gotten from the employee table of the database.  Once you select which names you want to send an email to, I need to get the email addresses from the employee table, to actually send the email.

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 07 October 2006 - 05:59 PM

so dont you just say

$row['name']=$row['email'];

then the email code

<div>
                                        <center><B>Send this form to:</B><BR>
                                        <select name='emailname[]' multiple="multiple">

                                        <?php

    $result = mysql_query("SELECT * FROM employees") or die(mysql_error());
    while ($row = mysql_fetch_assoc($result)) {
        echo "<option>$row[name]</option>";
        $row['name']=$row['email'];
}
 ?></select></center>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 07 October 2006 - 06:02 PM

I will try that.  I have no idea how to do this, as I am new at all of this.  I have never used the mail function, and this is the first DB project I have ever worked on.



#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 07 October 2006 - 06:06 PM

i thort that you select the users name then you do another selct email from users were username is ='$name'

then the email code sure of it.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 07 October 2006 - 06:07 PM

I am sorry, but I am not following what you have just said.

Ken

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 07 October 2006 - 06:15 PM

some think like this i am sure that when you select a name you then convert the name intot the users email address then send the email via the user name as it is there email address.
example only
<div>
<center><B>Send this form to:</B><BR>
<select name='emailname[]' multiple="multiple">

<?php

$result = mysql_query("SELECT * FROM employees") or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo "<option>$row[name]</option>";
    }
foreach ($emailname as $ename);	

$ename=$row['email'];

</select></center>

$to      = $ename;

$subject = 'the subject';

$message = 'hello';

$headers = 'From: webmaster@example.com' . "\r\n" .
   
'Reply-To: webmaster@example.com' . "\r\n" .
   
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#11 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 07 October 2006 - 06:17 PM

Ok, I see what you are saying.  Thanks a bunch for the help.  It is starting to make sense now.  I appreciate your help.

Ken

#12 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 07 October 2006 - 06:21 PM

this should defently work
<div>
<center><B>Send this form to:</B><BR>
<select name='emailname[]' multiple="multiple">

<?php

$result = mysql_query("SELECT * FROM employees") or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo "<option>$row[name]</option>";
    }
foreach($emailname as $ename);	


$result2 = mysql_query("SELECT email FROM employees where ename='$ename'") or die(mysql_error());

while ($a = mysql_fetch_assoc($result2)) {

$email=$a['email'];

</select></center>

$to      = $email;

$subject = 'the subject';

$message = 'hello';

$headers = 'From: webmaster@example.com' . "\r\n" .
   
'Reply-To: webmaster@example.com' . "\r\n" .
   
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#13 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 08 October 2006 - 01:00 AM

I have tried using the last script supplied, but for some reason it isn't sending an email.  I have also added the line
echo 'Email has been sent to'.$_POST[$ename];
to see what it shows and it prints out the Email has been sent to, but there is no names in there.

Am I missing a step as far as setting the email address of something for it to use it?  I am not really sure what I would need to change to make this actually send the email.  the rest of the form is being saved to the Db, so it is making a connection and not generating any errors.

Any ideas or suggestions would be appreciated.  Would I need to save the names to a db table before it could send the email?

Thanks,

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users