PHPMailer Erro - ENCRYPTION_STARTTLS

0 respostas
php
Fabio_Queiroz

Olá, executei o código, mas aparece o seguinte erro: Undefined class constant ‘ENCRYPTION_STARTTLS’

Segue meu código:

<?php
require ./bibliotecas/PHPMailer/Exception.php;

require ./bibliotecas/PHPMailer/OAuth.php;

require ./bibliotecas/PHPMailer/PHPMailer.php;

require ./bibliotecas/PHPMailer/POP3.php;

require ./bibliotecas/PHPMailer/SMTP.php;
use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\SMTP;

use PHPMailer\PHPMailer\Exception;

//print_r($_POST);

class Mensagem {

private $para = null;

private $assunto = null;

private $mensagem = null;
public function __get($atributo) {
    return $this->$atributo;
}

public function __set($atributo, $valor) {
    $this->$atributo = $valor;
}

public function mensagemValida() {
    if(empty($this->para) || empty($this->assunto) || empty($this->mensagem)){
        return false;
    }
    return true;
}

}

$mensagem = new Mensagem();

$mensagem->__set(para, $_POST[para]);

$mensagem->__set(assunto, $_POST[assunto]);

$mensagem->__set(mensagem, $_POST[mensagem]);

//print_r($mensagem);

if(!$mensagem->mensagemValida()) {

echo Mensagem não é válida;

die();

}

$mail = new PHPMailer(true);

try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = ‘smtp1.example.com’; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ‘[email removido]’; // SMTP username
$mail->Password = ‘secret’; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; PHPMailer::ENCRYPTION_SMTPS encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for PHPMailer::ENCRYPTION_SMTPS above

//Recipients
$mail->setFrom('[email removido]', 'Mailer');
$mail->addAddress('[email removido]', 'Joe User');     // Add a recipient
$mail->addAddress('[email removido]');               // Name is optional
$mail->addReplyTo('[email removido]', 'Information');
$mail->addCC('[email removido]');
$mail->addBCC('[email removido]');

// Attachments
$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

// 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 “Não foi possível enviar este e-mail!!”;

echo 'Detalhes do erro:  . $mail->ErrorInfo;

}
Criado 27 de maio de 2020
Respostas 0
Participantes 1