Skip to content

Instantly share code, notes, and snippets.

@GeorgeHPD
Last active September 10, 2019 23:07
Show Gist options
  • Save GeorgeHPD/53ccd0fca3ab5dd53e2ed04c3be30bc5 to your computer and use it in GitHub Desktop.
Save GeorgeHPD/53ccd0fca3ab5dd53e2ed04c3be30bc5 to your computer and use it in GitHub Desktop.
PHPMail
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require("vendor/autoload.php");
define('SMTP_USER', '****');
define('SMTP_PASS', '****');
define('SMTP_HOST', ****);
define('SMTP_PORT', 587);
class Mail{
function send($para, $de, $de_nome, $assunto, $corpo) {
$mail = new PHPMailer();
$mail->IsSMTP(); // Ativar SMTP
$mail->SMTPDebug = 0; // Debug: 1 = erros e mensagens, 2 = mensagens apenas
$mail->SMTPAuth = true; // Autenticação
$mail->SMTPSecure = 'tsl'; // SSL Ou TSL
$mail->Host = SMTP_HOST; // Servidor SMTP utilizado
$mail->Port = SMTP_PORT; // A porta habilitada no servidor
$mail->Username = SMTP_USER;
$mail->Password = SMTP_PASS;
//Variáveis da mensagem, remetente, assunto, mensagem e destinatário.
$mail->SetFrom($de, $de_nome);
$mail->Subject = $assunto;
$mail->Body = $corpo;
$mail->AddAddress($para);
if(!$mail->Send()) {
return ['status' => false, 'message' => 'Mensagem não enviada: '.$mail->ErrorInfo];
} else {
return ['status' => true, 'message' => 'Mensagem enviada com sucesso!'];
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment