Created
July 30, 2018 02:35
-
-
Save apertaoxis/da2823aacd29d2bcbb8f29bad4eec29d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if (!session_id()) { | |
| session_start(); | |
| } | |
| define('__ROOT__', dirname(__FILE__)); | |
| // Importar a classe do PHPMailer | |
| use PHPMailer\PHPMailer\PHPMailer; | |
| use PHPMailer\PHPMailer\Exception; | |
| // Carrega o autoload do composer | |
| require_once __ROOT__.'vendor/autoload.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(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; | |
| } | |
| } | |
| } | |
| // ENVIAR EMAIL - TESTAR | |
| $enviar = email($email, "Assunto teste", "corpo aqui"); | |
| var_dump($enviar); | |
| header("Location: bilhetes.php"); | |
| die(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment