mail = new PHPMailer(true); $this->mail->CharSet = "UTF-8"; } /** Envia o e-mail a partir do seu tipo informado */ public function sendMail(string $host, string $username, string $password, int $port, string $fromEmail, string $fromName, string $destinyEmail, string $destinyName, string $subject, string $body) { /** Parametros de entrada */ $this->host = $host; $this->username = $username; $this->password = $password; $this->port = $port; $this->fromEmail = $fromEmail; $this->fromName = $fromName; $this->destinyEmail = $destinyEmail; $this->destinyName = $destinyName; $this->subject = $subject; $this->body = $body; try { //Server settings //$this->mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output $this->mail->isSMTP(); //Send using SMTP $this->mail->Host = $this->host; //Set the SMTP server to send through $this->mail->SMTPAuth = true; //Enable SMTP authentication $this->mail->Username = $this->username; //SMTP username $this->mail->Password = $this->password; //SMTP password $this->mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption $this->mail->Port = $this->port; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` /** Destinatário */ $this->mail->setFrom($this->fromEmail, $this->fromName); $this->mail->addAddress($this->destinyEmail, $this->destinyName); /** Conteúdo a ser enviado */ $this->mail->isHTML(true); # Habilita o envio da mensagem no formato HTML $this->mail->Subject = $this->subject; # Assunto da mensagem enviada $this->mail->Body = $this->body; # Corpo da mensagem enviada /** Desativa a verificação de certificado */ $this->mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); /** Envio da mensagem */ $this->mail->send(); } catch (\Exception $e) { /** Informo */ throw new \InvalidArgumentException("Message could not be sent. Mailer Error: {$this->mail->ErrorInfo}", 0); } } /** Finaliza a classe instanciada */ function __destruct(){} }