Foros del Web » Programando para Internet » PHP »

Form guarda datos en excel y envia mail

Estas en el tema de Form guarda datos en excel y envia mail en el foro de PHP en Foros del Web. Estimados Expertos, Principiantes, Amateurs y bebes de pecho como yo en PHP Tengo la siguiente duda. Estoy con un proyecto de un especie de formulario ...
  #1 (permalink)  
Antiguo 25/06/2009, 21:47
 
Fecha de Ingreso: junio-2008
Mensajes: 6
Antigüedad: 15 años, 10 meses
Puntos: 0
Form guarda datos en excel y envia mail

Estimados Expertos, Principiantes, Amateurs y bebes de pecho como yo en PHP

Tengo la siguiente duda. Estoy con un proyecto de un especie de formulario de contacto que graba los datos en un excel en vez de una base, hasta ahi vamos bien ya que encontre en la web un script que lo hace solita. Ahora mi duda es la siguiente, por lo poco, y digo realmente poco, que entiendo de php, este formulario crea un array con los datos del form y los postea en excel, mi duda es si a ese script hay alguna manera de agregarle tambien la funcionalidad de que me lo envie por mail a una direccion tal como un formulario de contacto. Pego el script



// Change this to the page you want the user to be redirected to after form is submitted (i.e. success.html and error.html)
$success = "";
$error = "";

// Change this to the character(s) you want to be placed instead of line breaks(new line, enter, etc)
$lbChar = " "; // default is a space, you may change it to whatever you want

// Don't change anything below this line

// Determine if the form was sent through the GET methog or the POST method.
if($_POST){
$array = $_POST;
} else if($_GET){
$array = $_GET;
} else {
die("You must Access this file through a form."); // If someone accesses the file directly, it wont work :)
}

//Check if the filename was sent through the form or not
if(!$array['filename']){
// if the filename wasnt sent through the form, it will become form.xls, you can change the default if you want.
$array['filename'] = "form.xls"; //Set the file to save the information in

} else {
if(!(stristr($array['filename'],".xls"))){
$array['filename'] = $array['filename'] . ".xls";
}
}

// Define the tab and carriage return characters:
$tab = "\t"; //chr(9);
$cr = "\n"; //chr(13);

if($array){
// Make The Top row for the excel file and store it in the $header variable
$keys = array_keys($array);
foreach($keys as $key){
if(strtolower($key) != 'filename' && strtolower($key) != 'title'){
$header .= $key . $tab;
}
}
$header .= $cr;

//Make the line with the contents to write to the excel file.
foreach($keys as $key){
if(strtolower($key) != 'filename' && strtolower($key) != 'title'){

$array[$key] = str_replace("\n",$lbChar,$array[$key]);
$array[$key] = preg_replace('/([\r\n])/e',"ord('$1')==10?'':''",$array[$key]);
$array[$key] = str_replace("\\","",$array[$key]);
$array[$key] = str_replace($tab, " ", $array[$key]);
$data .= $array[$key] . $tab ;
}
}
$data .= $cr;

if (file_exists($array['filename'])) {
$final_data = $data; // If the file does exist, then only write the information the user sent
} else {
$final_data = $header . $data; // If file does not exist, write the header(first line in excel with titles) to the file
}
// open the file and write to it

$fp = fopen($array['filename'],"a"); // $fp is now the file pointer to file $array['filename']

if($fp){

fwrite($fp,$final_data); //Write information to the file
fclose($fp); // Close the file
// Success
header("Location: $success");
} else {
// Error
header("Location: $error");
}
}



Yo se que es un inchadero de huevos lo que pregunto pero la verdad que hace rato que quiero aprender php y por tiempo solo logro agarrar codigos y scripts y tratar de entenderlo de a poco es que no encontre nada para esto especificamente. Gracias gente ayuden o no.

P.D: Seguramente muchos me daran soluciones alternativas pero antes que eso prefiero si alguno puede aportarme si se puede o no hacer lo que digo, independientemente de si es dificil o no
  #2 (permalink)  
Antiguo 30/06/2009, 11:19
Avatar de lair  
Fecha de Ingreso: enero-2009
Ubicación: header('Location: Morelia");
Mensajes: 1.052
Antigüedad: 15 años, 3 meses
Puntos: 46
Respuesta: Form guarda datos en excel y envia mail

claro que lo hay, php tiene la funcion mail() y ademas existe una clase que se llama phpmailer (esta esta rondando por internet, no se excactamente donde descargarla), esta te ayuda con el envio de mail ya un poco mas complejos.

suerte
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:56.