Foros del Web » Programando para Internet » PHP »

mail + registro en excel

Estas en el tema de mail + registro en excel en el foro de PHP en Foros del Web. Buenas gente, como estan? Estoy realizando un proyecto en el cual el cliente necesita que los datos de un formulario puedan enviarse por mail (cosa ...
  #1 (permalink)  
Antiguo 25/10/2012, 09:57
 
Fecha de Ingreso: octubre-2007
Mensajes: 26
Antigüedad: 16 años, 5 meses
Puntos: 1
Pregunta mail + registro en excel

Buenas gente, como estan?

Estoy realizando un proyecto en el cual el cliente necesita que los datos de un formulario puedan enviarse por mail (cosa que esta resuelta perfectamente) y que a su vez esos datos me los registre en un archivo excel (el cual tambien esta resuelto). Estas 2 cosas ya las tengo resultas pero por separado, lo que yo quiero es unir estos en un solo archivo php

He intentado unirlos pero me da un error:
Cita:
Warning: Cannot modify header information - headers already sent by (output started at /home/content/29/9570629/html/html/apgform.php:3) in /home/content/29/9570629/html/html/apgform.php on line 143
el codigo que tengo es este:

Código PHP:
<html>
<head><title>
<?php 

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

    
$nombre_eq $_POST['nombre'];
$modalidad $_POST['modalidad'];
$int1=$_POST['integrante1'];
$int1ci=$_POST['integrante1ci'];
$int1tel=$_POST['integrante1telefono'];
$int1cel=$_POST['integrante1celular'];
$int1email=$_POST['integrante1email'];
$int1rem=$_POST['integrante1remera'];
$int2=$_POST['integrante2'];
$int2ci=$_POST['integrante2ci'];
$int2tel=$_POST['integrante2telefono'];
$int2cel=$_POST['integrante2celular'];
$int2email=$_POST['integrante2email'];
$int2rem=$_POST['integrante2remera'];

$header 'From: ' $int1email " \r\n";
$header .= "X-Mailer: PHP/" phpversion() . " \r\n";
$header .= "Mime-Version: 1.0 \r\n";
$header .= "Content-type: text/html\r\n";

$mensaje "Este mensaje fue enviado por desde el formulario de pre-inscripción.<br />";
$mensaje .= "Estos son los datos enviados: <br /><br />";
$mensaje .= "<b>Nombre del Equipo: </b>".$nombre_eq."<br />";
$mensaje .= "<b>Modalidad: </b>".$modalidad."<br />";
$mensaje .= "-----------------------------------------------------<br />";
$mensaje .= "<b>Nombre integrante 1: </b>".$int1."<br />";
$mensaje .= "<b>Cédula Nº: </b>".$int1ci."<br />";
$mensaje .= "<b>Teléfono: </b>".$int1tel."<br />";
$mensaje .= "<b>Celular: </b>".$int1cel."<br />";
$mensaje .= "<b>Email: </b>".$int1email."<br />";
$mensaje .= "<b>Tamaño de remera: </b>".$int1rem."<br />";
$mensaje .= "-----------------------------------------------------<br />";
$mensaje .= "<b>Nombre integrante 2: </b>".$int2."<br />";
$mensaje .= "<b>Cédula Nº: </b>".$int2ci."<br />";
$mensaje .= "<b>Teléfono: </b>".$int2tel."<br />";
$mensaje .= "<b>Celular: </b>".$int2cel."<br />";
$mensaje .= "<b>Email: </b>".$int2email."<br />";
$mensaje .= "<b>Tamaño de remera: </b>".$int2rem."<br />";

$mensaje .= "Enviado el " date('d/m/Y'time());

$para '[email protected]';
$asunto 'Pre-inscripciones Mandu´ara Light '.date("Y");

mail($para$asuntoutf8_decode($mensaje), $header);

if(!
$array['title']){
        
// if the title wasnt sent through the form, it will become whatever you set it equal to in the next line
        
$array['title'] = "apgForm";    //Set default title to be displayed
}
echo 
$array['title'] .'</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>'
;
    
    
//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";
        }
    }
    
    
    
// Change this to whatever you want the users to see after the form is processed
    
$continue ' Here is a the Comment form your info was just sent to <a href="test.xls">Click
      Here</a> to see the excel file.<br> <a href = "index.php">Click Here</a> To Return to apgForm  '
;
    
    
// 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
    
    
    //-------------------------------------------------------------------------------------
    //----------------You do not need to change anything below this line-------------------
    //-------------------------------------------------------------------------------------


    // 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
                
echo "Form Received Successfully! <br> " $continue;
            } else {
                echo 
"Error receiving form! <br>" $continue;
            }
    }
    
//Copyright © 2004 apg88. All Rights Reserved 

header("Location: gracias.html");
?>

</body>
</html>
Me podrian ayudar, estoy casi seguro que el error es en:
Cita:
mail($para, $asunto, utf8_decode($mensaje), $header);
Necesito de vuestra preciada ayuda, muchas gracias!!!
  #2 (permalink)  
Antiguo 25/10/2012, 11:45
Avatar de flashmax  
Fecha de Ingreso: julio-2012
Ubicación: Bs.As. Argentina
Mensajes: 507
Antigüedad: 11 años, 8 meses
Puntos: 86
Respuesta: mail + registro en excel

hola tu problema no esta en mail($para, $asunto, utf8_decode($mensaje), $header);
si no que esta relacionado con etas lineas
echo "Form Received Successfully! <br> " . $continue;
header("Location: gracias.html");
si muestras el codigo de tu form podremos darte una mano.
__________________
Saludos!
----------------------------------------------------------
  #3 (permalink)  
Antiguo 25/10/2012, 11:53
 
Fecha de Ingreso: octubre-2007
Mensajes: 26
Antigüedad: 16 años, 5 meses
Puntos: 1
Respuesta: mail + registro en excel

este es el codigo de mi form:

Código HTML:
<form name="id" enctype="multipart/form-data" action="apgform.php" method="post">
<input type="hidden" name="id" value="mlight2010">
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField1" name="nombre" size="33" maxlength="33" style="width: 260px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField14" name="modalidad" size="33" maxlength="33" style="width: 260px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField2" name="integrante1" size="30" maxlength="30" style="width: 236px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField4" name="integrante1ci" size="30" maxlength="30" style="width: 236px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField5" name="integrante1telefono" size="30" maxlength="30" style="width: 236px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField6" name="integrante1celular" size="30" maxlength="30" style="width: 236px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField7" name="integrante1email" size="30" maxlength="30" style="width: 236px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField8" name="integrante1remera" size="30" maxlength="30" style="width: 236px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField3" name="integrante2" size="32" maxlength="32" style="width: 252px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField9" name="integrante2ci" size="32" maxlength="32" style="width: 252px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField10" name="integrante2telefono" size="32" maxlength="32" style="width: 252px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField11" name="integrante2celular" size="32" maxlength="32" style="width: 252px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField12" name="integrante2email" size="32" maxlength="32" style="width: 252px; white-space: pre;"></p>
<p style="margin-bottom: 0px;"><input type="text" id="FormsEditField13" name="integrante2remera" size="32" maxlength="32" style="width: 252px; white-space: pre;"></p>
<input type="submit" id="FormsButton1" name="Enviar" value="Enviar" style="height: 24px; width: 63px;">
</form> 
Gracias por responder!
  #4 (permalink)  
Antiguo 25/10/2012, 12:08
Avatar de flashmax  
Fecha de Ingreso: julio-2012
Ubicación: Bs.As. Argentina
Mensajes: 507
Antigüedad: 11 años, 8 meses
Puntos: 86
Respuesta: mail + registro en excel

hola luego de enviar los datos que quieres hacer :
que retorne a index.php
que quede en Form Received Successfully!
o que se redireccione a gracias.html
porque por lo que veo ahi esta tu error en el header
__________________
Saludos!
----------------------------------------------------------
  #5 (permalink)  
Antiguo 25/10/2012, 14:14
 
Fecha de Ingreso: octubre-2007
Mensajes: 26
Antigüedad: 16 años, 5 meses
Puntos: 1
Respuesta: mail + registro en excel

Cita:
Iniciado por flashmax Ver Mensaje
hola luego de enviar los datos que quieres hacer :
que retorne a index.php
que quede en Form Received Successfully!
o que se redireccione a gracias.html
porque por lo que veo ahi esta tu error en el header
Eso de index.php y Form Received Successfully! era parte del codigo y lo deje para prueba, lo que realmente quiero es que vaya a gracias.html
  #6 (permalink)  
Antiguo 25/10/2012, 17:56
Avatar de flashmax  
Fecha de Ingreso: julio-2012
Ubicación: Bs.As. Argentina
Mensajes: 507
Antigüedad: 11 años, 8 meses
Puntos: 86
Respuesta: mail + registro en excel

hola prueba y nos cuenta como anduvo

Código PHP:
<html> 
<head><title> 
<?php  

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

    
$nombre_eq $_POST['nombre']; 
$modalidad $_POST['modalidad']; 
$int1=$_POST['integrante1']; 
$int1ci=$_POST['integrante1ci']; 
$int1tel=$_POST['integrante1telefono']; 
$int1cel=$_POST['integrante1celular']; 
$int1email=$_POST['integrante1email']; 
$int1rem=$_POST['integrante1remera']; 
$int2=$_POST['integrante2']; 
$int2ci=$_POST['integrante2ci']; 
$int2tel=$_POST['integrante2telefono']; 
$int2cel=$_POST['integrante2celular']; 
$int2email=$_POST['integrante2email']; 
$int2rem=$_POST['integrante2remera']; 

$header 'From: ' $int1email " \r\n"
$header .= "X-Mailer: PHP/" phpversion() . " \r\n"
$header .= "Mime-Version: 1.0 \r\n"
$header .= "Content-type: text/html\r\n"

$mensaje "Este mensaje fue enviado por desde el formulario de pre-inscripción.<br />"
$mensaje .= "Estos son los datos enviados: <br /><br />"
$mensaje .= "<b>Nombre del Equipo: </b>".$nombre_eq."<br />"
$mensaje .= "<b>Modalidad: </b>".$modalidad."<br />"
$mensaje .= "-----------------------------------------------------<br />"
$mensaje .= "<b>Nombre integrante 1: </b>".$int1."<br />"
$mensaje .= "<b>Cédula Nº: </b>".$int1ci."<br />"
$mensaje .= "<b>Teléfono: </b>".$int1tel."<br />"
$mensaje .= "<b>Celular: </b>".$int1cel."<br />"
$mensaje .= "<b>Email: </b>".$int1email."<br />"
$mensaje .= "<b>Tamaño de remera: </b>".$int1rem."<br />"
$mensaje .= "-----------------------------------------------------<br />"
$mensaje .= "<b>Nombre integrante 2: </b>".$int2."<br />"
$mensaje .= "<b>Cédula Nº: </b>".$int2ci."<br />"
$mensaje .= "<b>Teléfono: </b>".$int2tel."<br />"
$mensaje .= "<b>Celular: </b>".$int2cel."<br />"
$mensaje .= "<b>Email: </b>".$int2email."<br />"
$mensaje .= "<b>Tamaño de remera: </b>".$int2rem."<br />"

$mensaje .= "Enviado el " date('d/m/Y'time()); 

$para '[email protected]'
$asunto 'Pre-inscripciones Mandu´ara Light '.date("Y"); 

mail($para$asuntoutf8_decode($mensaje), $header); 

if(!
$array['title']){ 
        
// if the title wasnt sent through the form, it will become whatever you set it equal to in the next line 
        
$array['title'] = "apgForm";    //Set default title to be displayed 

echo 
$array['title'] .'</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'

     
    
//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"
        } 
    } 
     
     
    
// Change this to whatever you want the users to see after the form is processed 
    
$continue ' Here is a the Comment form your info was just sent to <a href="test.xls">Click 
      Here</a> to see the excel file.<br> <a href = "index.php">Click Here</a> To Return to apgForm  '

     
    
// 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 
     
     
    //------------------------------------------------------------------------------------- 
    //----------------You do not need to change anything below this line------------------- 
    //------------------------------------------------------------------------------------- 


    // 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 
                
echo "<script language=Javascript> location.href=\"gracias.html\"; </script>"
            } else { 
                echo 
"</header><body>";
                echo 
"Error al recibir los datos!" ;
            }
    }
?> 

</body> 
</html>
__________________
Saludos!
----------------------------------------------------------
  #7 (permalink)  
Antiguo 25/10/2012, 20:27
 
Fecha de Ingreso: octubre-2007
Mensajes: 26
Antigüedad: 16 años, 5 meses
Puntos: 1
Respuesta: mail + registro en excel

muchisimas gracias flashmax!!!! con eso ya funciona de maravillas, para entender que estaba pasando me podrias explicar el cambio?? gracias!! muchisimas gracias en serio!

Etiquetas: excel, formulario, mail
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 17:19.