problem with phpMailer

0

very good afternoon community first of all it is the first time I work with phpMailer and noticed that it has several changes in its new version and I am having problems to send an email if they can help me I can be grateful

 /******Adicionando Cabecera******/
        $mail= new PHPMailer\PHPMailer\PHPMailer();
        //estableiendo la cabecera
        $mail->isSMTP(); //Indicar que se usará SMTP
        $mail->CharSe ='UTF-8';//permitir envío de caracteres especiales (tildes y ñ)
        /*CONFIGURACIÓN DE DEBUG (DEPURACIÓN)*/
        $mail->SMTPDebug = 0; //Mensajes de debug; 0 = no mostrar (en producción), 1 = de cliente, 2 = de cliente y servidor
        $mail->Debugoutput ='html'; //Mostrar mensajes (resultados) de depuración(debug) en html
        /*CONFIGURACIÓN DE PROVEEDOR DE CORREO QUE USARÁ EL EMISOR(GMAIL)*/
        $mail->Host = 'smtp.gmail.com'; //Nombre de host
        $mail->Port = 465; //Puerto SMTP, 587 para autenticado TLS
        $mail->SMTPSecure = 'tls'; //Sistema de encriptación - ssl (obsoleto) o tls
        $mail->SMTPAuth = true;//Usar autenticación SMTP
        $mail->SMTPOptions = array(
            'ssl' => array('verify_peer' => false,'verify_peer_name' => false,'allow_self_signed' => true)
        );//opciones para "saltarse" comprobación de certificados (hace posible del envío desde localhost)
        /*CONFIGURACIÓN DEL EMISOR*/
        $mail->Username = "[email protected]";
        $mail->Password = "*********";
        $mail->setFrom('[email protected]', 'prueba');
        //CONFIGURACIÓN DEL MENSAJE, EL CUERPO DEL MENSAJE SERA UNA PLANTILLA HTML QUE INCLUYE IMAGEN Y CSS
        $mail->Subject=$this->encabezado_email; //asunto del mensaje
        //incrustar imagen para cuerpo de mensaje(no confundir con Adjuntar)
        $mail->AddEmbeddedImage($this->ruta.basename($this->file_img_email['name']),'imagen'); //ruta de archivo de imagen
        //cargar archivo css para cuerpo de mensaje
        $rcss = "../css/correo.css";//ruta de archivo css
        $fcss = fopen ($rcss, "r");//abrir archivo css
        $scss = fread ($fcss, filesize ($rcss));//leer contenido de css
        fclose ($fcss);//cerrar archivo css
         //Cargar archivo html   
        $shtml = file_get_contents('../Views/mensaje.html');
        $incss  = str_replace('<style id="estilo"></style>',"<style>$scss</style>",$shtml);
        $cuerpo = str_replace('<p id="mensaje"></p>',$this->mensaje_email,$incss);
        $mail->Body = $cuerpo; //cuerpo del mensaje
        $mail->AltBody = '---';//Mensaje de sólo texto si el receptor no acepta HTML
        //CONFIGURACIÓN DE ARCHIVOS ADJUNTOS 
        $mail->addAttachment($this->ruta.basename($this->file_pdf_email['name']));
        //CONFIGURACIÓN DE RECEPTORES
        foreach ( $this->correos_email as $i => $sDest){
            $mail->addAddress(trim($sDest), "Destinatario ".$i+1);
        }
    //ENVIAR MENSAJE
    if (!$mail->send()) {
        echo "Error al enviar: " . $mail->ErrorInfo;
    } else {
        echo "Mensaje enviado correctamente";
        //eliminar archivos temporales de carpeta subidas
        unlink($this->ruta.basename($this->file_img_email['name']));
        unlink($this->ruta.basename($this->file_pdf_email['name']));
    }

I have changed the code above for this one that I saw on the network now it is sent, but the truth is that I do not get any mail to the inbox that I am doing wrong please.

  $mail = new PHPMailer\PHPMailer\PHPMailer(); 
    try {
        //Server settings
        $mail->SMTPDebug =0;                                 // Enable verbose debug output
        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = '********@gmail.com';                 // SMTP username
        $mail->Password = '****';                           // SMTP password
        $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, 'ssl' also accepted
        $mail->Port = 587;                                    // TCP port to connect to

        //Recipients
        $mail->setFrom('*****@gmail.com', 'Mailer');
        $mail->addAddress('*****@hotmail.com', 'Joe User');     // Add a recipient
        $mail->addAddress('*****@hotmail.com');               // Name is optional
        $mail->addReplyTo('******@hotmail.com', 'Information');
        $mail->addCC('***********@gmail.com');
        $mail->addBCC('********@gmail.com');

        //Attachments
        $mail->addAttachment('../data/filePdf/1.jpg'); 

        //Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'Here is the subject';
        $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

        $mail->send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
    }
    
asked by HB-DACO 06.12.2018 в 00:35
source

0 answers