Foros del Web » Programando para Internet » PHP »

Almacenar archivo XML recibido por Email

Estas en el tema de Almacenar archivo XML recibido por Email en el foro de PHP en Foros del Web. Estoy recibiendo por Email archivos XML, los cuales debo almacenar en una tabla de mySQL Lo que ahora hago es descargar el archivo del Email ...
  #1 (permalink)  
Antiguo 17/05/2015, 18:51
 
Fecha de Ingreso: enero-2002
Mensajes: 1.174
Antigüedad: 22 años, 2 meses
Puntos: 21
Almacenar archivo XML recibido por Email

Estoy recibiendo por Email archivos XML, los cuales debo almacenar en una tabla de mySQL

Lo que ahora hago es descargar el archivo del Email a mi disco duro y luego lo subo con PHP a mySQL. La cuenta de Email y la tabla mySQL se encuentran en el mismo servidor.

¿Alguna forma para que al recibir el Email lo mande almacenas a mySQL?

Gracias
  #2 (permalink)  
Antiguo 17/05/2015, 22:19
Avatar de enlinea777  
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 10 meses
Puntos: 127
Respuesta: Almacenar archivo XML recibido por Email

donde esta el codigo que envia el e-mail?
suponiendo que en otro servidor al cual no tienes acceso
podrias averiguar sobre imap con php eso podria ayudarte
  #3 (permalink)  
Antiguo 17/05/2015, 23:21
 
Fecha de Ingreso: enero-2002
Mensajes: 1.174
Antigüedad: 22 años, 2 meses
Puntos: 21
Respuesta: Almacenar archivo XML recibido por Email

Cita:
Iniciado por enlinea777 Ver Mensaje
donde esta el codigo que envia el e-mail?
suponiendo que en otro servidor al cual no tienes acceso
podrias averiguar sobre imap con php eso podria ayudarte
Los Emails los recibo de muy diversos servidores.
Todos los emails os recibo en mi servidor Cpanel, y ahí mismo tengo mySQL

Creo es con PIPE... ¿será?
  #4 (permalink)  
Antiguo 17/05/2015, 23:41
 
Fecha de Ingreso: enero-2002
Mensajes: 1.174
Antigüedad: 22 años, 2 meses
Puntos: 21
Respuesta: Almacenar archivo XML recibido por Email

Tienes razón... IMAP puede ser...
Pero debo abrir los adjuntos que recibo, y eso será un poco dificil.

Acceder a los Email por Imap veo no es nada complicado.
  #5 (permalink)  
Antiguo 18/05/2015, 09:43
Avatar de enlinea777  
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 10 meses
Puntos: 127
Respuesta: Almacenar archivo XML recibido por Email

abrir achivos es mas facil que imap en php.
  #6 (permalink)  
Antiguo 23/08/2015, 20:41
 
Fecha de Ingreso: agosto-2015
Ubicación: Santiago
Mensajes: 5
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: Almacenar archivo XML recibido por Email

Aquí tienen la solución para obtener los adjuntos de un email.

Código PHP:
Ver original
  1. <?php
  2. #
  3. $hostname = '{mail.cocacola.cl:993/imap/ssl/novalidate-cert}INBOX';
  4. $username = '[email protected]';
  5. $password = 'suclavedelcorreo';
  6. $bandeja_entrada="xml/";
  7.  
  8. /* try to connect */
  9. $inbox = imap_open($hostname,$username,$password) or die('ERROR' . imap_last_error());
  10.  
  11. /* grab emails */
  12. $emails = imap_search($inbox, '');
  13.  
  14.  
  15.  
  16. /* if emails are returned, cycle through each... */
  17. if($emails) {
  18.  
  19.   /* begin output var */
  20.   $output = '';
  21.  
  22.   /* put the newest emails on top */
  23.   rsort($emails);
  24.  
  25.  
  26.  
  27.  
  28.     foreach($emails as $email_number) {
  29.  
  30.     /* get information specific to this email */
  31.     $overview = imap_fetc_overview($inbox,$email_number,0);
  32.     $message = imap_fetcbody($inbox,$email_number,2);
  33.     $structure = imap_fethstructure($inbox,$email_number);
  34.  
  35.  
  36.     //pre($overview);
  37.  
  38.  
  39.      $attachments = array();
  40.        if(isset($structure->parts) && count($structure->parts)) {
  41.          for($i = 0; $i < count($structure->parts); $i++) {
  42.            $attachments[$i] = array(
  43.               'is_attachment' => false,
  44.               'filename' => '',
  45.               'name' => '',
  46.               'attachment' => '');
  47.  
  48.            if($structure->parts[$i]->ifdparameters) {
  49.              foreach($structure->parts[$i]->dparameters as $object) {
  50.                if(strtolower($object->attribute) == 'filename') {
  51.                  $attachments[$i]['is_attachment'] = true;
  52.                  $attachments[$i]['filename'] = $object->value;
  53.                }
  54.              }
  55.            }
  56.  
  57.            if($structure->parts[$i]->ifparameters) {
  58.              foreach($structure->parts[$i]->parameters as $object) {
  59.                if(strtolower($object->attribute) == 'name') {
  60.                  $attachments[$i]['is_attachment'] = true;
  61.                  $attachments[$i]['name'] = $object->value;
  62.                }
  63.              }
  64.            }
  65.  
  66.            if($attachments[$i]['is_attachment']) {
  67.              $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1);
  68.              if($structure->parts[$i]->encoding == 3) { // 3 = BASE64
  69.                $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
  70.              }
  71.              elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
  72.                $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
  73.              }
  74.            }            
  75.          } // for($i = 0; $i < count($structure->parts); $i++)
  76.        } // if(isset($structure->parts) && count($structure->parts))
  77.  
  78.  
  79.  
  80.  
  81.     if(count($atachments)!=0){
  82.  
  83.  
  84.         foreach($attachments as $at){
  85.  
  86.             if($at[is_attachment]==1){
  87.                 #-------------------------------------------------------------------------- guardar adjuntos
  88.                file_put_contents($bandeja_entrada.$at[filename], $at[attachment]);
  89.  
  90.                 }
  91.             }
  92.  
  93.         }
  94.  
  95.   }
  96.  
  97.  // echo $output;
  98. }
  99.  
  100. /* close the connection */
  101. imap_close($inbox);
  102.  
  103. ?>
  #7 (permalink)  
Antiguo 23/08/2015, 20:48
 
Fecha de Ingreso: enero-2002
Mensajes: 1.174
Antigüedad: 22 años, 2 meses
Puntos: 21
Respuesta: Almacenar archivo XML recibido por Email

Gracias sharedcode
Lo probaremos

Etiquetas: almacenar, email, mysql, tabla, xml
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 02:30.