Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php # ver video : https://youtu.be/EP-QLGHuL1c
- array_map('unlink', glob("/var/www/html/oracle_dropbox/files/*"));
- require "PHPMailer-master/PHPMailerAutoload.php";
- try {
- $conn = oci_connect('xxx', 'xxxx', '192.168.102.33/xxxx') or die('ERROR de conexion');
- } catch (Exception $e) {
- echo ' -> Excepción capturada: ', $e->getMessage(), "\n";
- echo date("Y-m-d H:i:s") . " -> Excepción capturada: " . $e->getMessage() . PHP_EOL;
- }
- #$sql = "select * from fou_correos_electrncos, FOU_DESTIN_NOTCCNES where fou_correos_electrncos = FOU_CORREOS_ELECTRNCOS_ID and ESTADO = '395' order by ID desc";
- $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";
- $stmt = oci_parse($conn, $sql);
- oci_execute($stmt, OCI_DEFAULT);
- while (oci_fetch($stmt)) {
- $asunto = oci_result($stmt, "ASUNTO");
- $cuerpo = oci_result($stmt, "CUERPO");
- $id = oci_result($stmt, "ID");
- #$id_old = oci_result($stmt, "ID_OLD");
- #$fecha_creacion = oci_result($stmt, "FECHA_CREACION");
- #$fecha_envio = oci_result($stmt, "FECHA_ENVIO");
- $DIRIGIDO_A_EL = oci_result($stmt, "DIRIGIDO_A_EL");
- $CORREO_QUE_USE = oci_result($stmt, "CORREO_QUE_USE");
- $filename = "/var/www/html/oracle_dropbox/files/" . $id;
- /*
- ERROR 397
- NUEVO 398
- PENDIENTE 395
- PROCESAdo 396
- */
- if ($cuerpo->export($filename)) {
- $result = file_get_contents($filename);
- $gestor = fopen($filename, 'r');
- $contenido = stream_get_contents($gestor);
- fclose($gestor);
- unlink($filename);
- $arr[$id]['id'] = $id;
- $arr[$id]['asunto'] = $asunto;
- $arr[$id]['contenido'] = $contenido;
- if ($DIRIGIDO_A_EL == 'S') {
- $arr[$id]['correoprincipal'] = $CORREO_QUE_USE;
- $arr[$id]['envio'] = 's';
- } else {
- $arr[$id]['correo_copia'][] = $CORREO_QUE_USE;
- }
- } else {
- #echo "error en el export" . PHP_EOL;
- }
- }
- oci_free_statement($stmt);
- ########################################################################################
- $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";
- $stmt = oci_parse($conn, $sql);
- oci_execute($stmt, OCI_DEFAULT);
- while (oci_fetch($stmt)) {
- $id = oci_result($stmt, "ID");
- $ARCHIVO = oci_result($stmt, "ARCHIVO");
- $NOMBRE = oci_result($stmt, "NOMBRE");
- $filename = "/var/www/html/oracle_dropbox/files/" . $NOMBRE;
- /*
- ERROR 397
- NUEVO 398
- PENDIENTE 395
- PROCESAdo 396
- */
- if ($ARCHIVO->export($filename)) {
- $result = file_get_contents($filename);
- $arr[$id]['archivo'][] = $filename;
- $arr[$id]['archivo_is_array'] = 's';
- } else {
- #echo "error en el export" . PHP_EOL;
- }
- }
- oci_free_statement($stmt);
- #################################################################
- foreach ($arr as $key => $value) {
- if (@$value['envio'] == 's') {
- echo "Asunto : ".@$value['asunto'] . PHP_EOL;
- echo "Contenido : ".@$value['contenido'] . PHP_EOL;
- echo "Email : ".@$value['correoprincipal'] . PHP_EOL;
- if (@!is_null($value['correo_copia'])) {
- foreach ($value['correo_copia'] as $key3 => $value3) {
- echo "BCC : ".$value3 . PHP_EOL;
- }
- }
- if (@$value['archivo_is_array'] == 's') {
- $dat1 = $value['archivo'];
- foreach ($dat1 as $key2 => $value2) {
- echo "Adjunto : ".$value2 . PHP_EOL;
- }
- }
- echo "---------------" . PHP_EOL;
- $mensaje = utf8_decode($value['contenido']);
- $mail = new PHPMailer();
- $mail->IsSMTP();
- $mail->SMTPDebug = 0;
- $mail->SMTPAuth = true;
- $mail->SMTPSecure = "tls";
- $mail->Host = "smtp.gmail.com";
- $mail->Port = 587;
- $mail->SMTPSecure;
- $mail->Username = "xxxxxxxx@gmail.com";
- $mail->Password = "xxxxxxxxxx";
- $mail->From = "xxxxxxxxxxxxxxx@gmail.com";
- $mail->FromName = "xxxxxxxxxxxxx";
- $mail->AddAddress($value['correoprincipal']);
- if (@!is_null($value['correo_copia'])) {
- foreach ($value['correo_copia'] as $key3 => $value3) {
- $mail->addCC($value3);
- }
- }
- $mail->Subject = $value['asunto'];
- if (@$value['archivo_is_array'] == 's') {
- $dat1 = $value['archivo'];
- foreach ($dat1 as $key2 => $value2) {
- $mail->addAttachment($value2);
- }
- }
- $mail->IsHTML(TRUE);
- $mail->Body = $mensaje;
- if ($mail->Send() == true) {
- $ID = $value['id'];
- $sql = "update fou_correos_electrncos set ESTADO = '396' where ID = $ID";
- $stmt = oci_parse($conn, $sql);
- oci_execute($stmt, OCI_COMMIT_ON_SUCCESS);
- echo "\n\t El envío de email fue satisfactorio \n";
- } else {
- $ID = $value['id'];
- $sql = "update fou_correos_electrncos set ESTADO = '397' where ID = $ID";
- $stmt = oci_parse($conn, $sql);
- oci_execute($stmt, OCI_COMMIT_ON_SUCCESS);
- echo "\n\t Error de email : " . $mail->ErrorInfo . "\n";
- }
- }
- }
- oci_close($conn);
- array_map('unlink', glob("/var/www/html/oracle_dropbox/files/*"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement