Advertisement
CPV

Correos masivos con oci php oracle

CPV
Jun 12th, 2016
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.99 KB | None | 0 0
  1. <?php # ver video : https://youtu.be/EP-QLGHuL1c
  2. array_map('unlink', glob("/var/www/html/oracle_dropbox/files/*"));
  3.  
  4. require "PHPMailer-master/PHPMailerAutoload.php";
  5. try {
  6.     $conn = oci_connect('xxx', 'xxxx', '192.168.102.33/xxxx') or die('ERROR de conexion');
  7. } catch (Exception $e) {
  8.     echo '    -> Excepción capturada: ', $e->getMessage(), "\n";
  9.     echo date("Y-m-d H:i:s") . " -> Excepción capturada: " . $e->getMessage() . PHP_EOL;
  10. }
  11. #$sql = "select * from fou_correos_electrncos, FOU_DESTIN_NOTCCNES  where fou_correos_electrncos = FOU_CORREOS_ELECTRNCOS_ID and   ESTADO = '395'  order by ID desc";
  12. $sql = "select   fou_correos_electrncos.ID,fou_correos_electrncos.asunto, fou_correos_electrncos.cuerpo, FOU_DESTIN_NOTCCNES.DIRIGIDO_A_EL, FOU_DESTIN_NOTCCNES.CORREO_QUE_USE from fou_correos_electrncos, FOU_DESTIN_NOTCCNES  where fou_correos_electrncos.ID = FOU_DESTIN_NOTCCNES.FOU_CORREOS_ELECTRNCOS_ID and   ESTADO = '395'   order by ID desc";
  13. $stmt = oci_parse($conn, $sql);
  14. oci_execute($stmt, OCI_DEFAULT);
  15.  
  16. while (oci_fetch($stmt)) {
  17.  
  18.     $asunto = oci_result($stmt, "ASUNTO");
  19.     $cuerpo = oci_result($stmt, "CUERPO");
  20.     $id = oci_result($stmt, "ID");
  21.     #$id_old = oci_result($stmt, "ID_OLD");
  22.    #$fecha_creacion = oci_result($stmt, "FECHA_CREACION");
  23.    #$fecha_envio = oci_result($stmt, "FECHA_ENVIO");
  24.    $DIRIGIDO_A_EL = oci_result($stmt, "DIRIGIDO_A_EL");
  25.     $CORREO_QUE_USE = oci_result($stmt, "CORREO_QUE_USE");
  26.  
  27.     $filename = "/var/www/html/oracle_dropbox/files/" . $id;
  28.  
  29.     /*
  30.       ERROR  397
  31.       NUEVO  398
  32.       PENDIENTE 395
  33.       PROCESAdo  396
  34.      */
  35.     if ($cuerpo->export($filename)) {
  36.         $result = file_get_contents($filename);
  37.         $gestor = fopen($filename, 'r');
  38.         $contenido = stream_get_contents($gestor);
  39.         fclose($gestor);
  40.         unlink($filename);
  41.  
  42.  
  43.         $arr[$id]['id'] = $id;
  44.         $arr[$id]['asunto'] = $asunto;
  45.         $arr[$id]['contenido'] = $contenido;
  46.  
  47.         if ($DIRIGIDO_A_EL == 'S') {
  48.  
  49.             $arr[$id]['correoprincipal'] = $CORREO_QUE_USE;
  50.             $arr[$id]['envio'] = 's';
  51.         } else {
  52.             $arr[$id]['correo_copia'][] = $CORREO_QUE_USE;
  53.         }
  54.     } else {
  55.         #echo "error en el export" . PHP_EOL;
  56.    }
  57. }
  58.  
  59. oci_free_statement($stmt);
  60. ########################################################################################
  61.  
  62. $sql = "select fou_adjntos.ARCHIVO, fou_adjntos.NOMBRE,  fou_correos_electrncos.ID from fou_adjntos, fou_correos_electrncos  where fou_adjntos.CORREO_ELECTRONICO_ID = fou_correos_electrncos.ID   and   ESTADO = '395'   order by ID desc";
  63. $stmt = oci_parse($conn, $sql);
  64. oci_execute($stmt, OCI_DEFAULT);
  65.  
  66. while (oci_fetch($stmt)) {
  67.  
  68.  
  69.     $id = oci_result($stmt, "ID");
  70.     $ARCHIVO = oci_result($stmt, "ARCHIVO");
  71.     $NOMBRE = oci_result($stmt, "NOMBRE");
  72.  
  73.     $filename = "/var/www/html/oracle_dropbox/files/" . $NOMBRE;
  74.  
  75.     /*
  76.       ERROR  397
  77.       NUEVO  398
  78.       PENDIENTE 395
  79.       PROCESAdo  396
  80.      */
  81.     if ($ARCHIVO->export($filename)) {
  82.         $result = file_get_contents($filename);
  83.  
  84.         $arr[$id]['archivo'][] = $filename;
  85.  
  86.         $arr[$id]['archivo_is_array'] = 's';
  87.     } else {
  88.         #echo "error en el export" . PHP_EOL;
  89.    }
  90. }
  91. oci_free_statement($stmt);
  92.  
  93.  
  94. #################################################################
  95.  
  96. foreach ($arr as $key => $value) {
  97.  
  98.     if (@$value['envio'] == 's') {
  99.  
  100.         echo "Asunto : ".@$value['asunto'] . PHP_EOL;
  101.         echo "Contenido : ".@$value['contenido'] . PHP_EOL;
  102.         echo "Email : ".@$value['correoprincipal'] . PHP_EOL;
  103.  
  104.         if (@!is_null($value['correo_copia'])) {
  105.             foreach ($value['correo_copia'] as $key3 => $value3) {
  106.                 echo "BCC : ".$value3 . PHP_EOL;
  107.             }
  108.         }
  109.  
  110.         if (@$value['archivo_is_array'] == 's') {
  111.             $dat1 = $value['archivo'];
  112.             foreach ($dat1 as $key2 => $value2) {
  113.                 echo "Adjunto : ".$value2 . PHP_EOL;
  114.             }
  115.         }
  116.  
  117.         echo "---------------" . PHP_EOL;
  118.        
  119.        
  120.        
  121.        
  122.    
  123.         $mensaje = utf8_decode($value['contenido']);
  124.  
  125.         $mail = new PHPMailer();
  126.         $mail->IsSMTP();
  127.         $mail->SMTPDebug = 0;
  128.  
  129.         $mail->SMTPAuth = true;
  130.         $mail->SMTPSecure = "tls";
  131.         $mail->Host = "smtp.gmail.com";
  132.         $mail->Port = 587;
  133.         $mail->SMTPSecure;
  134.  
  135.  
  136.         $mail->Username = "xxxxxxxx@gmail.com";
  137.         $mail->Password = "xxxxxxxxxx";
  138.  
  139.         $mail->From = "xxxxxxxxxxxxxxx@gmail.com";
  140.         $mail->FromName = "xxxxxxxxxxxxx";
  141.         $mail->AddAddress($value['correoprincipal']);
  142.  
  143.         if (@!is_null($value['correo_copia'])) {
  144.             foreach ($value['correo_copia'] as $key3 => $value3) {
  145.                 $mail->addCC($value3);
  146.             }
  147.         }
  148.  
  149.         $mail->Subject = $value['asunto'];
  150.  
  151.         if (@$value['archivo_is_array'] == 's') {
  152.             $dat1 = $value['archivo'];
  153.             foreach ($dat1 as $key2 => $value2) {
  154.  
  155.  
  156.                 $mail->addAttachment($value2);
  157.             }
  158.         }
  159.  
  160.  
  161.  
  162.         $mail->IsHTML(TRUE);
  163.         $mail->Body = $mensaje;
  164.  
  165.         if ($mail->Send() == true) {
  166.                     $ID = $value['id'];
  167.                     $sql = "update fou_correos_electrncos set ESTADO = '396' where ID = $ID";
  168.                     $stmt = oci_parse($conn, $sql);
  169.                     oci_execute($stmt, OCI_COMMIT_ON_SUCCESS);
  170.                    
  171.             echo "\n\t El envío de email fue satisfactorio \n";
  172.         } else {
  173.  
  174.                     $ID = $value['id'];
  175.                     $sql = "update fou_correos_electrncos set ESTADO = '397' where ID = $ID";
  176.                     $stmt = oci_parse($conn, $sql);
  177.                     oci_execute($stmt, OCI_COMMIT_ON_SUCCESS);
  178.  
  179.             echo "\n\t Error de email : " . $mail->ErrorInfo . "\n";
  180.         }
  181.        
  182.  
  183.        
  184.  
  185.        
  186.        
  187.     }
  188. }
  189.  
  190.  
  191. oci_close($conn);
  192. array_map('unlink', glob("/var/www/html/oracle_dropbox/files/*"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement