Sending e-mail to multiple recipients

0

I'm using sendmail, the problem and the following. I use checkbox to mark the recipients. How do I checkboxes when I checkboxes fill a variable with each recipient, comma, and 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 doing the validation and filled the body. Send:

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

    
asked by anonymous 13.07.2016 / 21:21

2 answers

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><inputtype="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">
    
13.07.2016 / 22:23
1

Using PHP's mail function () you can send to multiple recipients by making use of the first parameter like this:

mail('[email protected], [email protected], ...', ...);

Just divide the emails within the string of the first parameter using a comma (,).

    
13.07.2016 / 22:14