Skip to content

Instantly share code, notes, and snippets.

@aleduca
Created August 9, 2022 01:47
Show Gist options
  • Save aleduca/784334b82112efdc2473f193067e046c to your computer and use it in GitHub Desktop.
Save aleduca/784334b82112efdc2473f193067e046c to your computer and use it in GitHub Desktop.
<?php
use PHPMailer\PHPMailer\SMTP;
function send(array $data)
{
$email = new PHPMailer\PHPMailer\PHPMailer;
try {
$email->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$email->CharSet = 'UTF-8';
$email->SMTPSecure = 'plain';
$email->isSMTP();
$email->Host = 'smtp.mailtrap.io';
$email->Port = 465;
$email->SMTPAuth = true;
$email->Username = '62a10a41445609';
$email->Password = 'b31431694ea877';
$email->isHTML(true);
$email->setFrom($data['quem']);
$email->addAddress($data['para']);
// $email->FromName = $data['quem'];
// $email->addAddress = $data['para'];
$email->Body = $data['mensagem'];
$email->Subject = $data['assunto'];
$email->AltBody = 'This is the body in plain text for non-HTML mail clients';
$email->MsgHTML($data['mensagem']);
return $email->send();
} catch (\Throwable $th) {
echo "Message could not be sent. Mailer Error: {$email->ErrorInfo}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment