Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/01/2010, 14:20
dariones123
 
Fecha de Ingreso: enero-2010
Mensajes: 22
Antigüedad: 14 años, 4 meses
Puntos: 0
Error al enviar EMAIL mediante PHP

Hola a todos....

Necesito que cuando el usuario decida enviar un email mediante mi web, indique mediante un select a qué "departamento" quiere enviarlo (ej: administracion, finanzas, webmaster,etc).

Tengo un formulario con autentificación.
Código HTML:
<html>
<head>
<SCRIPT> 
function validateForm(_f) {
	var _b="Aquí están los datos que has ingresado:";
	var _l="¿Quieres enviar estos datos?";
	var _n="\n";
	var _t="\t";
    var _s="";
	
    for(var _obj = _f.firstChild; _obj ; _obj=_obj.nextSibling)
	{
	  if(_obj.name!=undefined)
	  {
	    /*
		 * Pick up the title if it exists - otherwise use the name of the object.
		 */
		if(!_obj.header)_obj.header=_obj.name;
		
		/*
		 * Deal with Text and Hidden and TextArea
		 */
		if(_obj.type=="text" || _obj.type=="hidden" || _obj.type=="textarea")
		  _s+=_obj.header+_t+_obj.value+_n;
        /*
		 * Deal with Radio Buttons, and Checkboxes
		 */
		if((_obj.type=="radio"||_obj.type=="checkbox")&&_obj.checked)
		{
		  _s+=_obj.header+_t+_obj.value+_n;
		}
		/*
		 * Deal with Select Boxes
		 */
		var _regExp=/select/i;
		if(_obj.type.match(_regExp))
		  _s+=_obj.header+_t+_obj.value+_n;
	  }
	}
	
    return confirm(_b+_n+_n+_s+_n+_l);
} 
</SCRIPT> 
<script>
		function LP_data(evt){
		var key = evt.which || event.keyCode; // Código de tecla. 
		if ((key < 48 || key > 57) && key != 8){ // Si no es número o retroceso
		if (evt.preventDefault) {
			evt.preventDefault();
		} else {
			event.returnValue = false;
		}
		}
		}
	</script>

</head>

<body bgcolor="#FFFCD5" background="../informe_azul.PNG">
<FORM name=f1 onsubmit="return validateForm(document.f1)" method="post" action="contact.php">
<input type="text" name="Nombre:" size="2" value="JUANITO PEREZ" readonly="readonly">
<input type="text" name="Mes: " size="2" value="-- MES --" maxlength="15">
<input type="text" name="Libros:" size="2" onkeypress="LP_data(event)" value="0" maxlength="3">&nbsp;</p>
<input type="text" name="Folletos:" size="2" onkeypress="LP_data(event)"  value="0" maxlength="3">
<select name="Departamento:" id="Departamento:"  size="1">
<option selected>-- Departamento --</option>
<option value="Webmaster" header="[email protected]">Webmasterr</option>
<option value="Finanzas" header="[email protected]">Finanzas</option>
<option value="Administración" header="[email protected]">Administración</option>
</select></p>
</p>

<INPUT type=submit value="Enviar Informe"></p>
</form>
</body>

</html> 
Y el archivo PHP:
Código PHP:
<?php
// Website Contact Form Generator 
// http://www.tele-pro.co.uk/scripts/contact_form/ 
// This script is free to use as long as you  
// retain the credit link  

// get posted data into local variables
$EmailFrom "[email protected]";
$EmailTo Trim(stripslashes($_POST['Departamento:'])); 
$Subject "Envio de Informe";
$Nombre Trim(stripslashes($_POST['Nombre:'])); 
$Mes Trim(stripslashes($_POST['Mes: '])); 
$Libros Trim(stripslashes($_POST['Libros:'])); 
$Folletos Trim(stripslashes($_POST['Folletos:'])); 


// prepare email body text
$Body "";
$Body .= "Nombre:";
$Body .= $Nombre;
$Body .= "\n";
$Body .= "Mes: ";
$Body .= $Mes;
$Body .= "\n";
$Body .= "Libros:";
$Body .= $Libros;
$Body .= "\n";
$Body .= "Folletos:";
$Body .= $Folletos;
$Body .= "\n";


// send email 
$success mail($EmailTo$Subject$Body"From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print 
"<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
  print 
"<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
El problema es el siguiente: para validar el form, aparece una "alerta" con los datos ingresados, y en "Departamento", obviamente no puede aparecer el email del departamento, por eso el email lo coloco en un "header", y el nombre del departamento como valor ('value') predeterminado. Todo bien hasta aquí, pero al enviar, el PHP no me reconoce el destinatario, pues el email no se encuentra en la etiqueta 'value' sino en 'header'.

Este el código especifico del HTML con el que tengo el problema:

Código HTML:
<select name="Departamento:" id="Departamento:" >
<option selected>-- Departamento --</option>
<option value="Webmaster" header="[email protected]">Webmasterr</option>
<option value="Finanzas" header="[email protected]">Finanzas</option>
<option value="Administración" header="[email protected]">Administración</option>
</select></p> 

Espero que me hallan entendido, y muchas gracias de antemano!!


DE AQUÍ SAQUÉ EL JAVASCRIPT PARA CONFIRMAR LOS DATOS INGRESADOS:
[URL="http://javascripts.astalaweb.com/Formularios%20III/Formulario/Confirma%20todos%20los%20datos.htm"][/URL]

Última edición por dariones123; 15/01/2010 a las 17:44 Razón: Mejorar posteo