Skip to content

Instantly share code, notes, and snippets.

@pedroribeirodev
Created July 30, 2018 02:08
Show Gist options
  • Save pedroribeirodev/92a248a2125ff845a3adfb1fea37d910 to your computer and use it in GitHub Desktop.
Save pedroribeirodev/92a248a2125ff845a3adfb1fea37d910 to your computer and use it in GitHub Desktop.
<?php
if (!session_id()) {
session_start();
}
define('__ROOT__', dirname(__FILE__));
require_once __ROOT__."/vendor/phpmailer/phpmailer/PHPMailerAutoload.php";
$email = explode(";", $_POST["email"]);
if (!function_exists('email')) {
/**
* @param array|string $email
* @param string $assunto
* @param string $corpo
* @param string @replyTo
* @return boolean
*/
function email($email = null, $assunto = '(Sem Assunto)', $corpo = null, $replyTo = "retorno@exemplo.com")
{
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
try{
$mail->SMTPDebug = 2;
$mail->IsSMTP();
$mail->Host = "mail.MEUDOMINIO.com.br";
$mail->SMTPAuth = true;
$mail->Username = "pedro.ribeiro@MEUDOMINIO.com.br";
$mail->Password = 'MINHASENHA';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
/*$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
); */
$mail->Priority = 3;
$mail->Encoding = 'base64';
$mail->addCustomHeader('Content-Transfer-Encoding', 'base64');
$mail->addCustomHeader('MIME-Version', '1.0');
$mail->SetFrom("naoresponda@exemplo.com", "Meu Nome");
$mail->AddReplyTo($replyTo, $replyTo);
$mail->isHTML(true);
$mail->CharSet = 'utf-8';
$mail->Subject = stripslashes($assunto);
$mail->Body = stripslashes($corpo);
$mail->AltBody = strip_tags(stripslashes($corpo));
if (is_array($email)) {
foreach($email as $addr)
{
$mail->addAddress($addr);
}
}
else {
$mail->addAddress($email);
}
$mail->Send();
return true;
}
catch (PHPMailer\PHPMailer\Exception $e) {
echo 'Mensagem não enviada. Erro: ', $mail->ErrorInfo;
return false;
}
}
}
header("Location: bilhetes.php");
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment