TeroLost Posted June 28, 2010 Share Posted June 28, 2010 Hey all, I'm having issues with a bit of code--obviously or I wouldn't be asking for help, huh? Anyways, it works fine with a single or multiple simultaneous recipients, but I wanted to set it up so that visitors to my site can select who exactly they want to send the email to--rather that it either going straight to me, or to everyone all at once. I want to allow for a drop down selection on who they want to send it to, and I want to be able to add as many options as I please with one more more emails attached to each option. I've been looking around and trying to figure it out on my own, and I decided that one of the more efficient ways should be to do it through editing the recipient array, here's what I've come up with, both my form and my php file. <form method="post" action="email.php" class="contact"> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> Your Name: <br /> <input type="text" name="visitor" size="35" /> <br /> Your Email:<br /> <input type="text" name="visitormail" size="35" /> <br /> Select Recipient:<br /> <select name="recipient" size="1"> <option value=" recipient_1 "> Thingie 1 </option> <option value=" recipient_2 " selected="selected"> Thingie 2 </option> </select> <br /><br /> Mail Message: <br /> <textarea name="notes" rows="4" cols="40"></textarea> <br /> <input type="submit" value="Send Mail" /> <br /> </form> <?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $visitor = $_POST['visitor']; $visitormail = $_POST['visitormail']; $notes = $_POST['notes']; if (eregi('http:', $notes)) { die ("Bad Monkey! ! "); } if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) { echo "<h2>Use Back - Enter valid e-mail</h2>\n"; $badinput = "<h2>Feedback was NOT submitted</h2>\n"; echo $badinput; die ("Go back! ! "); } if(empty($visitor) || empty($visitormail) || empty($notes )) { echo "<h2>Use Back - fill in all fields</h2>\n"; die ("Use back! ! "); } $todayis = date("l, F j, Y, g:i a") ; $subject = 'Enquiries'; $notes = stripcslashes($notes); $message = " $todayis [EST] \n Message: $notes \n From: $visitor ($visitormail)\n Additional Info : IP = $ip \n Browser Info: $httpagent \n Referral : $httpref \n "; $from = "From: $visitormail\r\n"; $recipients = array( 'recipient_1' => '[email protected]', 'recipient_2' => '[email protected]', ); $my_email = $recipients[$_REQUEST['recipient']]; ?> <p align="center"> Date: <?php echo $todayis ?> <br /> Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> ) <br /> Message:<br /> <?php $notesout = str_replace("\r", "<br/>", $notes); echo $notesout; ?> <br /> <?php echo $ip ?> <br /><br /> <a href="http://www.site.com/contactpage.php"> Return to Previous Page </a> </p> Any tips or tricks to make it better...or better yet, make it work?? I'm pretty new to php, basically been teaching myself from scratch so I'm sure this looks horribly ill conceived to you all. Link to comment https://forums.phpfreaks.com/topic/206100-multiple-recipeint-e-mail-from/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.