php - Form with checkbox destinations

907

I have a problem. I did a form with i can choose who goes it with "checkbox"

The problem is the message is just going to the 2nd destiantion (2nd checkbox), and ignore the other checked.

Can anybody help? Thks

exemple of my code:

...(begining)...

<form action="<?$_SERVER['PHP_SELF']; ?>" method="post">

...(somewhere in the form)...

<input type="checkbox" name="emailto" id="emailto1" value="[email protected]">MV <input type="checkbox" name="emailto" id="emailto2" value="[email protected]">

...(before all form)...

<? if ($_POST['submit']){

$titulo = "** BRIEF **"; $sender = "BRIEF<[email protected]>"; $to = $_POST ['emailto']; $reply = "[email protected]";

$mensagem = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'> <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> </head> <body> test </body> </html>";

mail($to, $titulo, $mensagem,"From:$sender\r\nReply-to:$reply\r\nContent-type: text/html; charset=iso-8859-1"); echo "<b><font face='Verdana' color='#C10000' size='2' align='center'>Dados enviados com sucesso.</b></font>"; } ?>

...

`

417

Answer

Solution:

writename="emailto[]" and see the data

echo "<pre>";
print_r($_POST['emailto']);

it's an array of email

359

Answer

Solution:

As for as I have understood your problem you should work with array. Changed the names of your checkboxes with array like this.

<input type="checkbox" name="emailto[]" id="emailto1" value="[email protected]">
<span class="font_bold_01">PG + MV    
<input type="checkbox" name="emailto[]" id="emailto2" value="[email protected]">
PG + MV + VC    

On other hand use loop to get all checked values. Hope it is the answer

People are also looking for solutions to the problem: php - display user entered data in the form before submitting to database

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.