How to send more than one checkbox option by email?

1

I'm trying to send more than one checkbox marked by email, with PHPMail, I can only send the last item marked, I tried to do an if with foreach but it did not work, maybe I still can not do it, how can I put this function in this checkbox below:

<?php
if(!empty($_POST['checkbox'])) {
foreach($_POST['checkbox'] as $check) {
       echo $check . "<br>";
}}


$Nome = $_REQUEST['Nome'];
$Tel = $_REQUEST['Tel'];
$Email = $_REQUEST['Email'];
$Mensagem = $_REQUEST['Mensagem'];

$mail->WordWrap = 50; 
$mail->IsHTML(true);     
$mail->Subject  =  "Contato do site Webwork"; // Assundo
$mail->Body     =   " Nome:</strong> $Nome \n<br />". // Usuario
                    " Tel.:</strong> $Tel \n<br />".
                    " Email:</strong> $Email \n<br /><br />".    // Email
                    " Mensagem:</strong> $Mensagem \n<br />"; // Mensagem

I wanted to print the response from more than one check in the body of the email, how do I do that?

<form action="executa.php" method="post" name="form1">
<input type="checkbox" name="checkbox[]" value="Primeiro" />
<input type="checkbox" name="checkbox[]" value="Segundo" />
<input type="checkbox" name="checkbox[]" value="Terceiro" />
<input type="checkbox" name="checkbox[]" value="Quarta" />
<button type="submit" value="Enviar">Enviar</button>
</form>
    
asked by anonymous 17.08.2017 / 21:53

1 answer

2

Use implode() to transform the sent checkbox array into a string by seperating the items by a delimiter, done concate this result to your message:

$selecionados = !empty($_POST['checkbox']) ? implode(', ', $_POST['checkbox']) : '';

$mail->Body = 'Mensagem..... '. $seleciondos;
    
17.08.2017 / 22:08