Skip to main content
Inspiring
September 8, 2008
Question

URGENT PHP HELP

  • September 8, 2008
  • 12 replies
  • 575 views
I am working on a mail form that is linked to my payroll system. It is working great but there has been a request that I add a mail to all recipients feature. However I am not to sure how I would go about doing this, I am hoping someone can help me atler my current code. Right now the recipient selction is a drop down menu that is populated from a mySQL table within my payroll system.

I would like the first option when dropped down to be "All Recipents" so when it is sent the mail is sent to everyone's email not just the slected individual email.

Below is the current code I have where only one recipent can be selected.

Thanks in advance!

This topic has been closed for replies.

12 replies

bcountsAuthor
Inspiring
September 8, 2008
I am still a bit confused:

The main question is how do I tell the script if the "All Recipients" option is selected to pull all the emails "user_email" from the user_info table in mySQL and send it to all of those people.
Inspiring
September 8, 2008
Does your e-mail system support Distribution Lists? If so, the easiest way
would be to add the appropriate one to your Dropdown list.

If not, then the only other way I see to do this is to check whether "All
Recipients" is selected. If it is, loop through all of the addresses and
build up the BCC: string (it's considered a bad practice to put huge lists
in the TO: field). If not, then use your current code.

HTH

Steve


"bcounts" <webforumsuser@macromedia.com> wrote in message
news:ga26qe$j16$1@forums.macromedia.com...
>I am working on a mail form that is linked to my payroll system. It is
>working
> great but there has been a request that I add a mail to all recipients
> feature.
> However I am not to sure how I would go about doing this, I am hoping
> someone
> can help me atler my current code. Right now the recipient selction is a
> drop
> down menu that is populated from a mySQL table within my payroll system.
>
> I would like the first option when dropped down to be "All Recipents" so
> when
> it is sent the mail is sent to everyone's email not just the slected
> individual
> email.
>
> Below is the current code I have where only one recipent can be selected.
>
> Thanks in advance!
>
>
>
> ******* HTML CODE *********
> <?
> include('auth.php');
> $user_id = $_GET['user_id'];
> $result = mysql_query("select * from user_info where user_id = $user_id");
> $row = mysql_fetch_array($result);
> ?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns=" http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
> <title>Untitled Document</title>
> </head>
> <body>
> <input type="hidden" name="user_id" value="<?=$user_id?>" />
> <form method="post" action="send_mail.php">
> <table bgcolor=#ffffcc align=center>
> <tr><td><font color=red>*</font> Name:</td><td><input name="Name"
> value="<?=$row['fname']?> <?=$row['lname']?>" size=25></td></tr>
> <tr><td><font color=red>*</font> Email:</td><td><input name="Email"
> value="<?=$row['user_email']?>" size=25></td></tr>
> <tr>
> <td><font color=red>*</font> Recipient:</td>
> <td align="left"><select name="sendto">
> <option value="">Select Recipient . . .</option>
> <?php $sql = mysql_query("SELECT * FROM user_info ORDER BY lname ASC");
> while
> ($row1 = mysql_fetch_array($sql)) { ?>
> <option value="<?php echo $row1['user_email']; ?>"><?php echo
> $row1['fname'];
> ?> <?php echo $row1['lname']; ?></option>
> <?php } ?>
> </select></td></tr>
> <tr>
> <td><font color=red>*</font> Subject:</td>
> <td><input size=25 name="Subject"></td></tr>
> <tr><td colspan=2>Message:</td></tr>
> <tr><td colspan=2 align=center><textarea name="Message" rows=5
> cols=35></textarea></td></tr>
> <tr><td colspan=2 align=center><input type=submit name="send" value="Send
> Mail"></td></tr>
> <tr>
> <td colspan=2 align=center><small><font color=red>*</font> Indicates
> Required
> Field</small></td>
> </tr>
> </table>
> </form>
> </body>
> </html>
>
> ******* PHP CODE *********
>
> <?php
> $to = $_REQUEST['sendto'];
> $from = $_REQUEST['Email'];
> $name = $_REQUEST['Name'];
> $headers = "From: $from";
> $subject = $_REQUEST['Subject'];
>
> $fields = array();
> $fields{"Message"} = "Message";
>
> $body = ""; foreach($fields as $a => $b){ $body .= sprintf("%20
> %s\n\n",$b,$_REQUEST[$a]);}
>
> if($from == '') {print "You have not entered an email, please go back and
> try
> again";}
> else {
> if($subject == '') {print "You have not entered a subject, please go back
> and
> try again";}
> else {
> $send = mail($to, $subject, $body, $headers);
> if($send)
> {header( "Location: index.php" );}
> else
> {print "You did not choose a recipient or the recipent you have chosen did
> not
> have an email on file.";}
> }
> }
> ?>
>