How to send more than one checkbox option by email?

Asked

Viewed 367 times

1

I’m trying to send more of a checkbox marked by email, with Phpmail, I can only send the last item marked, I tried to do an if with foreach more did not help, maybe I still can not do, as I can 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 reply of more than one check in the body of the email, as I do it?

<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>
  • In your checkbox field form you must have the name followed by square brackets: name="produtos[]"

  • There is more than one $_POST['name'] ?

  • Already had, I edited to put the form.

  • I can give an echo, and it appears to me, but in the email I do not know how to send.

1 answer

2


Use the implode() to transform the sent checkbox array into a string by a delimiter, made concate this result to its message:

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

$mail->Body = 'Mensagem..... '. $seleciondos;
  • It’s perfect, thank you very much.

Browser other questions tagged

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