Skip to main content
2 de 2
se añadieron 2225 caracteres en el cuerpo

enviar correo con archivo adjunto PHPMAILER

tengo este codigo pero no se que hago mal que no puedo enviar correo con archivo adjunto

$mail->CharSet    = 'UTF-8';
            $mail->SMTPDebug = 3;                      //Enable verbose debug output
            $mail->isSMTP(true);                                            //Send using SMTP
            $mail->Host       = 'smtp.gmail.com';                     //Set the SMTP server to send through
            $mail->SMTPAuth   = true;                                   //Enable SMTP authentication           
            //$mail->Mailer     = 'smtp';
            $mail->Username   = '[email protected]';                     //SMTP username
            $mail->Password   = '2022coope';                               //SMTP password
            $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;//PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption           
            $mail->Port       = 587;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

        

//Recipients
            $mail->setFrom('[email protected]', 'Coop'); //[email protected]
            $mail->addAddress('[email protected]', 'cliente');     //Add a recipient
            
            //Attachments
            $mail->addAttachment($dato1);         //Add attachments
            $mail->addAttachment($dato2);    //Optional name

            //Content
            $mail->isHTML(true);                                  //Set email format to HTML
            $mail->Subject = 'Documentos';
            $mail->Body    = 'Señor le Enviamossus datos';
                
            $mail->send();

no se que puedo estar haciendo mal ya que segun lei desde mayo no se puede utilizar google para hacer este tipo de envios, por favor ayuda.

Este es el mensaje que resibo:

2022-12-01 03:06:55 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
2022-12-01 03:06:55 Connection: opened
2022-12-01 03:06:56 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP b19-20020a9d6b93000000b0066c34486aa7sm1608909otq.73 - gsmtp
2022-12-01 03:06:56 CLIENT -> SERVER: EHLO 190.180.62.136
2022-12-01 03:06:56 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [177.222.44.34]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2022-12-01 03:06:56 CLIENT -> SERVER: STARTTLS
2022-12-01 03:06:56 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2022-12-01 03:06:56 CLIENT -> SERVER: EHLO 190.180.62.136
2022-12-01 03:06:56 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [177.222.44.34]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2022-12-01 03:06:56 CLIENT -> SERVER: AUTH LOGIN
2022-12-01 03:06:57 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2022-12-01 03:06:57 CLIENT -> SERVER: [credentials hidden]
2022-12-01 03:06:57 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2022-12-01 03:06:57 CLIENT -> SERVER: [credentials hidden]
2022-12-01 03:07:20 SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/?p=BadCredentials b19-20020a9d6b93000000b0066c34486aa7sm1608909otq.73 - gsmtp
2022-12-01 03:07:20 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/?p=BadCredentials b19-20020a9d6b93000000b0066c34486aa7sm1608909otq.73 - gsmtp
SMTP Error: Could not authenticate.
2022-12-01 03:07:20 CLIENT -> SERVER: QUIT
2022-12-01 03:07:20 SERVER -> CLIENT: 221 2.0.0 closing connection b19-20020a9d6b93000000b0066c34486aa7sm1608909otq.73 - gsmtp
2022-12-01 03:07:20 Connection: closed
SMTP Error: Could not authenticate.
Ocurrio un Error el Enviar: SMTP Error: Could not authenticate. 

este mensaje reviso y es evidente que algo anda mal... espero que me puedan ayudar