Gamerz Posted August 29, 2009 Share Posted August 29, 2009 Hello, I currently have a file uploader which allows you to upload files, and it will generate url's to the file. I would like to construct a code where I am able to give my users the option to send there file URL's to multiple e-mails....I would like to use JavaScript, so the user has the option to click a link, and my script will show more input type's so the user can send more e-mails... Here's my form: <form action="url.php" method="post" enctype="multipart/form-data"> You can also send the uploaded file link to your e-mail:</p> <input type="email" name="email" id="email" size="40"> <input type="submit" name="submit" value="Send E-mail" /> <input type="hidden" name="url" value="<?php echo $fileurl ?>" /> <input type="hidden" name="delete" value="<?php echo $fileurldelete ?>" /> </form> Here is the processing script to send email: <?php $to = $_POST['email']; $delete = $_POST['delete']; $url = $_POST['url']; $subject = 'FILE URL'; $message = "Here is your file url\n--------------------------------------------------------\nGeneral viewing/downloading for your file: $url\n\nDeleting your File: $delete\n--------------------------------------------------------\n\n if(empty($to)) { echo "<h2><center>E-mail Not Sent Successfully!</h2>\n"; die ("<center>You have entered an invalid e-mail.<br>Please click back to re-enter your e-mail."); } mail($to, $subject, $message, $headers); } header("location: success.php"); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/172343-php-sending-multiple-e-mails-via-form/ Share on other sites More sharing options...
oni-kun Posted August 29, 2009 Share Posted August 29, 2009 What do you mean using JS?? You can make them enter something as this, which all the sites i've seen use.. "Enter e-mails you want to send to, separated by ';' ".. me@hotmail.com;jason@gmail.com;this@site.com -> $e-mails = explode(';', $_POST['e-mailfield']); And then there you go! You've got an array with each number, you could easily iterate through the array and use mail() with each address until the for loop ends. Quote Link to comment https://forums.phpfreaks.com/topic/172343-php-sending-multiple-e-mails-via-form/#findComment-908729 Share on other sites More sharing options...
Gamerz Posted August 29, 2009 Author Share Posted August 29, 2009 Where would I put this: $e-mails = explode(';', $_POST['e-mailfield']); And by JavaScript, I mean like something where when you click a link, and it will show more e-mail input type fields so the person can enter more e-mail's... Quote Link to comment https://forums.phpfreaks.com/topic/172343-php-sending-multiple-e-mails-via-form/#findComment-908735 Share on other sites More sharing options...
oni-kun Posted August 29, 2009 Share Posted August 29, 2009 My method is more simpler, separated by ';' as that is a standard of most e-mail clients.. $to = $_POST['email']; <---, if there is more than one when it it'd be exploded, then create a function to send e-mails to each one through a for loop, simple enough. explode simply makes.. 'me@hotmail.com;this@gmail.com' into an array.. $to[0], $to[1] or whatever. Quote Link to comment https://forums.phpfreaks.com/topic/172343-php-sending-multiple-e-mails-via-form/#findComment-908737 Share on other sites More sharing options...
Gamerz Posted August 29, 2009 Author Share Posted August 29, 2009 So I replace my current $to with $to = explode(';', $_POST['e-mail']);? And I want to make multiple <input type="text" name="email"> What else do I need to add on the processing script in order for me to add multiple e-mail fields so it will send to all the e-mail's. Quote Link to comment https://forums.phpfreaks.com/topic/172343-php-sending-multiple-e-mails-via-form/#findComment-908749 Share on other sites More sharing options...
oni-kun Posted August 29, 2009 Share Posted August 29, 2009 You don't need to add more e-mail fields, it's slow, unconventional and hard to write. The user only needs to add.. 'user1@example.com;user2@example.com'. e-mail or e-mails separated by semicolons, the explode function will separate them. This is what all websites do.. Quote Link to comment https://forums.phpfreaks.com/topic/172343-php-sending-multiple-e-mails-via-form/#findComment-908750 Share on other sites More sharing options...
Gamerz Posted August 29, 2009 Author Share Posted August 29, 2009 I think I rather prefer multiple e-mail fields... How would I go about constructing that? I know first step is to make the multiple fields...what's next? Quote Link to comment https://forums.phpfreaks.com/topic/172343-php-sending-multiple-e-mails-via-form/#findComment-908759 Share on other sites More sharing options...
oni-kun Posted August 29, 2009 Share Posted August 29, 2009 Well then you'd use JS to add a form, such as .. <a href="#" onClick="addForm()">Add form</a> Make sure your JS adds a new property.. such as value="mail2" or mail3 according to how many fields are being aded, so PHP can distinguish them and mail each address accordingly.. Quote Link to comment https://forums.phpfreaks.com/topic/172343-php-sending-multiple-e-mails-via-form/#findComment-908761 Share on other sites More sharing options...
Gamerz Posted August 29, 2009 Author Share Posted August 29, 2009 How would I add the values like mail2 and mail3, and what code do I add on the mail processing page Quote Link to comment https://forums.phpfreaks.com/topic/172343-php-sending-multiple-e-mails-via-form/#findComment-908828 Share on other sites More sharing options...
oni-kun Posted August 29, 2009 Share Posted August 29, 2009 Well look up some JS to add the form. in each for you need to have value = something different.. such as 'email1', 'email2', 'email3' and on your PHP side you can do.. if (isset($_POST['mail1'])) { mail(....) // mail to this address } if (isset($_POST['mail2'])) { mail(....) // mail to this second address } etc.. Quote Link to comment https://forums.phpfreaks.com/topic/172343-php-sending-multiple-e-mails-via-form/#findComment-908877 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.