Pues mi duda es a ver si me podeis ayudar con el envio del formulario por email, que hay una parte que se me resiste.
Tengo un select multiple el cual los nombres que aparecen son a los que quiero enviar el formulario. Es decir que envie el formulario a todas las personas que tenga marcadas en el select multiple.Hasta ahora tengo esto:
Código PHP:
<?php
session_start();
require ('db_connect.php');
require ('functions.php');
//require ('email2.php');
//include ('config.php');
connectar_imc();
?>
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function seleccionar(distribuidores) {
if (distribuidores.checked){
for (i=0; ele = document.getElementById('distribuidores').options[i]; i++)
ele.selected = true;
}else{
for (i=0; ele = document.getElementById('distribuidores').options[i]; i++)
ele.selected = false;
}
}
</SCRIPT>
</head>
<title>Formulario</title>
<body>
<?
if (!$_POST){
?>
<form method = "post" action = "formulario2.php">
<table border="0">
<tr><td width="100" class="hover">Distribuidores:</td> <br>
<td width="120"><select multiple name="distribuidores[]" id="distribuidores">
<optgroup label="-Elija distribuidor-">
<?php
$query=mysql_query("SELECT d.id_distributor, distributor_name, report_email FROM distributor d, distributor_trademark WHERE deleted_distributor = '0'");
while($row=mysql_fetch_row($query)){
?>
<option value="<?php echo $row[2]; ?>"><?php echo $row[1]; ?></option>
<?php
}
?>
</select>
</select> </td>
<td width="200"><input type="checkbox" name="checkbox" id="checkbox" onClick="seleccionar(this)">Todos los distribuidores</td></tr>
<tr>
<td width="100">Asunto:</td>
<td width="120"><input type="text" name="asunto" MaxLength="20"></td>
</tr>
<tr>
<td width="100">Mensaje:</td>
<td width="120" height="50"><textarea name="mensaje" rows="10" cols="30"></textarea></td>
</tr>
<tr>
<td width="100"> </td>
<td width="120"><input id="boton" name="enviar" type="submit" value="Enviar"></td>
</tr>
</table>
</form>
<?
}else{
$dis=$_POST["distribuidores"];
for ($i=0;$i<count($dis);$i++) //recorremos el array de distribuidores
{
echo "<br> Distribuidor " . $i . ": " . $dis[$i]. "<br>";
}
}
?>
<?php
if(isset($_POST['enviar'])){
//recoger los valores por post
$asunto = $_POST['asunto'];
$mensaje = $_POST['mensaje'];
}
//Estoy recibiendo el formulario, compongo el cuerpo
$cuerpo = "Formulario enviado\n";
$cuerpo .= "Asunto: " . $_POST["asunto"] . "\n";
$cuerpo .= "Mensaje: " . $_POST["mensaje"] . "\n";
//mando el correo...
mail("[email protected]","Formulario recibido",$cuerpo);
//doy las gracias por el envío
echo "Gracias por rellenar el formulario. Se ha enviado correctamente.";
?>
</body>
</html>