Help with PHPMailler

0

Hi, I have the following code, what I want to do is walk an email with the class PHPMailer but I get an error:

  

Fatal error: Uncaught Error: Class 'SMTP' not found in C: \ xampp \ htdocs \ project \ clients \ phpmailer \ class.phpmailer.php: 1466 Stack trace: # 0 C: \ xampp \ htdocs \ project \ clients \ phpmailer \ class.phpmailer.php (1549): PHPMailer-> getSMTPInstance () # 1 C: \ xampp \ htdocs \ project \ clients \ phpmailer \ class.phpmailer.php (1486): PHPMailer-> smtpConnect ( Array) # 2 C: \ xampp \ htdocs \ project \ clients \ phpmailer \ class.phpmailer.php (1323): PHPMailer-> smtpSend ('Date: Fri, 10 M ...', 'This is a multi. .. ') # 3 C: \ xampp \ htdocs \ project \ clients \ phpmailer \ class.phpmailer.php (1203): PHPMailer-> postSend () # 4 C: \ xampp \ htdocs \ project \ clients \ federal \ administrator \ mail.php (22): PHPMailer-> send () # 5 {main} thrown in C: \ xampp \ htdocs \ project \ clients \ phpmailer \ class.phpmailer.php on line 1466

and my code is as follows:

<?php
require("../../phpmailer/class.phpmailer.php");
$mail = new  PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "localhost";

// SMTP a utilizar. Por ej. smtp.elserver.com
$mail->Username = "root"; // Correo completo a utilizar
$mail->Password = ""; // Contraseña
$mail->Port = 25; // Puerto a utilizar
$mail->From = "[email protected]"; // Desde donde enviamos (Para mostrar)
$mail->FromName = "ELSERVER.COM";
$mail->AddAddress("correo"); // Esta es la dirección a donde enviamos
$mail->AddCC("[email protected]"); // Copia
$mail->AddBCC("[email protected]"); // Copia oculta
$mail->IsHTML(true); // El correo se envía como HTML
$mail->Subject = "Titulo"; // Este es el titulo del email.

$body = 'Hola mundo. Esta es la primer línea<br />';
$body .= "Acá continuo el<strong>mensaje</strong>";
$mail->Body = $body; // Mensaje a enviar
$mail->AltBody = "Hola mundo. Esta es la primer línean Acá continuo el mensaje"; // Texto sin html
$mail->AddAttachment("imagenes/imagen.jpg", "imagen.jpg");
$exito = $mail->Send(); // Envía el correo.

if($exito){
  echo "El correo fue enviado correctamente.";
} else {
  echo "Hubo un inconveniente. Contacta a un administrador.";
}
?>
    
asked by Jose Luis GP 10.03.2017 в 19:54
source

4 answers

0

You are missing the file class.smtp.php

Example:

<?php
require("../../phpmailer/class.phpmailer.php");
require("../../phpmailer/class.smtp.php");
    
answered by 10.03.2017 / 20:05
source
0

The issue is that you should not load the class directly if not the self-loading.

delete this line.

require("../../phpmailer/class.phpmailer.php");

You must put this

require '../PHPMailerAutoload.php';

luck

    
answered by 10.03.2017 в 20:06
0

Now I have this error

2017-03-10 19:25:56 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP r50sm4618141otd.20 - gsmtp 2017-03-10 19:25:56   CLIENT -> SERVER: EHLO localhost 2017-03-10 19:25:56    SERVER -> CLIENT: 250-smtp.gmail.com at your service, [201.122.207.46] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 2017-03-10 19:25:56    CLIENT -> SERVER: AUTH LOGIN 2017-03-10 19:25:56    SERVER -> CLIENT: 334 VXNlcm5hbWU6 2017-03-10 19:25:56  CLIENT -> SERVER: cHJheGVkZXMxMzE0QGdtYWlsLmNvbQ== 2017-03-10 19:25:56  SERVER -> CLIENT: 334 UGFzc3dvcmQ6 2017-03-10 19:25:56  CLIENT -> SERVER: X3ByYXhlZGVzMTIz 2017-03-10 19:25:56  SERVER -> CLIENT: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 r50sm4618141otd.20 - gsmtp 2017-03-10 19:25:56  SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 r50sm4618141otd.20 - gsmtp 2017-03-10 19:25:56   SMTP Error: Could not authenticate. 2017-03-10 19:25:56 CLIENT -> SERVER: QUIT 2017-03-10 19:25:56  SERVER -> CLIENT: 221 2.0.0 closing connection r50sm4618141otd.20 - gsmtp 2017-03-10 19:25:56   SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Error al enviar: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

but I just realized that gmail blocked access to someone knows how to allow access

    
answered by 10.03.2017 в 20:33
-1

Check that you have the smtp mailer library loaded, the error is that you can not find the library.

    
answered by 10.03.2017 в 20:03