Sending email to multiple recipients

Asked

Viewed 114 times

1

I’m using sendmail, the problem and the following. Use checkbox to mark recipients. How do I make it so that when I check the checkbox it fills a variable with each recipient, the comma and the next recipient?

input type="checkbox" name="todos" class="todos" onclick="marcardesmarcar()" /> Todos<br/>
<input type="checkbox" class="marcar" name="email1"  value="[email protected]" /> email1 ([email protected])<br/>
<input type="checkbox" class="marcar" name="email2"  value="[email protected]" /> email2 ([email protected])<br/>
<input type="checkbox" class="marcar" name="email3"  value="[email protected]" /> email3 ([email protected])<br>

Variable you will receive in php:

$email = $_POST["email"];

After the validation has been done and filled in the body. Send:

mail($email,$assunto,$mensagem, $headers, "-r".$email_from);

2 answers

1

  • I will use the mail function with the variable inside the string. More I need to send to multiples by filling the variable.

1


You can solve your problem like this:

        var inputs = $('input[name="email[]"]');
        inputs.on('change', function () {
            var str = [];
            var control = 0;
            inputs.each(function () {
                if (this.checked) {
                    str.push(this.value);
                  control++;
                }
            });
            $('input[name="emails"]').val(str.join(', '));
        });
#out{width:600px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="checkbox" name="email[]" value="[email protected]">[email protected]<br>
    <input type="checkbox" name="email[]" value="[email protected]">[email protected]<br>
    <input type="checkbox" name="email[]" value="[email protected]">[email protected]
    <br>
    <input type="text" name="emails" value="" id="out">

  • Because the id out?

  • To not show the input text I will assign a Hidden on it. I will do a test later. Thanks for the help.

  • It’s just Willian naming. You can put the id that fits your context. If on your system this field is not visible you can hide it too. Everything goes from your needs.

  • And what do I say. Do you need to have it with the size of 600px? I didn’t understand it there. Okay. I even had a solution for this case. The more the code gets big with a lot if Else. Kkkk I am weak with ajax. More from what I saw there goes to the vein.

  • You don’t have to have 600px exactly. You can leave 100% in your container or something like that. I only put 600px to make visible the 3 emails.

  • To call the ajax does not need Function right? Never used it with Javascript together. These checkbox has some functions to enable them and mark them.

  • I strongly recommend doing a function and calling in the event you want.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.