Jump to content

Recommended Posts

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();
?>

Link to comment
https://forums.phpfreaks.com/topic/172343-php-sending-multiple-e-mails-via-form/
Share on other sites

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.

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.

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.

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..

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..

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..

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.