Jump to content

Sending an email using a dropdown box


kenwvs

Recommended Posts

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.
[CODE]<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>";
    }[/CODE]

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
Link to comment
Share on other sites

If I use an array and do this, I will end up with something like this..........
[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>";
    }
$emailname=$_POST['emailname'];
if ($emailname){
foreach ($emailname as $ename); }

    ?></select></center>[/code]

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
Link to comment
Share on other sites

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
[code]
<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>
[/code]

might be wrong here only guessing.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

so dont you just say

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

then the email code

[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>
[/code]
Link to comment
Share on other sites

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
[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>";
    }
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);

?>
[/code]
Link to comment
Share on other sites

this should defently work
[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>";
   }
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);

}
?>
[/code]
Link to comment
Share on other sites

I have tried using the last script supplied, but for some reason it isn't sending an email.  I have also added the line [code=php:0]echo 'Email has been sent to'.$_POST[$ename];[/code] 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
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.