Advertisement
Guest User

Untitled

a guest
Mar 8th, 2019
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.83 KB | None | 0 0
  1. <?php
  2.  
  3.     require "./lib/PHPMailer/Exception.php";
  4.     require "./lib/PHPMailer/OAuth.php";
  5.     require "./lib/PHPMailer/PHPMailer.php";
  6.     require "./lib/PHPMailer/POP3.php";
  7.     require "./lib/PHPMailer/SMTP.php";
  8.  
  9.     use PHPMailer\PHPMailer\PHPMailer;
  10.     use PHPMailer\PHPMailer\Exception;
  11.  
  12.     class Mensagem {
  13.         private $nome = null;
  14.         private $email = null;
  15.         private $assunto = null;
  16.         private $mensagem = null;
  17.         public $status = array('codigo_status' => null, 'descricao_status' => '');
  18.  
  19.         public function __get($atributo) {
  20.             return $this-> $atributo;
  21.         }
  22.  
  23.         public function __set($atributo, $valor) {
  24.             $this->$atributo = $valor;
  25.         }
  26.  
  27.         public function mensagemValida() {
  28.             if(empty($this->nome) || empty($this->email) || empty($this->assunto) || empty($this->mensagem)) {
  29.                 return false;
  30.             }
  31.             return true;
  32.         }
  33.     }
  34.  
  35.     $mensagem = new Mensagem();
  36.  
  37.     $mensagem->__set('nome', $_POST['nome']);
  38.     $mensagem->__set('email', $_POST['email']);
  39.     $mensagem->__set('assunto', $_POST['assunto']);
  40.     $mensagem->__set('mensagem', $_POST['mensagem']);
  41.    
  42.  
  43.     if(!$mensagem->mensagemValida()) {
  44.         echo 'Mensagem não é valida';
  45.         header('Location: index.php');
  46.     }
  47.  
  48.     $mail = new PHPMailer(true);
  49. try {
  50.     //Server settings
  51.     $mail->CharSet = 'UTF-8';
  52.     $mail->SMTPDebug = false;                                 // Enable verbose debug output
  53.     $mail->isSMTP();                                      // Set mailer to use SMTP
  54.     $mail->Host = 'smtp.zoho.com';  // Specify main and backup SMTP servers
  55.     $mail->SMTPAuth = true;                               // Enable SMTP authentication
  56.     $mail->Username = 'publico@ferreiralab.com';                 // SMTP username
  57.     $mail->Password = 'aquieasenha';                           // SMTP password
  58.     $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
  59.     $mail->Port = 587;                                    // TCP port to connect to
  60.  
  61.     //Recipients
  62.     $mail->setFrom('publico@ferreiralab.com', 'Mensagem Enviada - FerreiraLab.com');
  63.     $mail->AddAddress('contato@ferreiralab.com', 'Contato - Ferreiralab.com');     // Add a recipient
  64.     //$mail->addReplyTo('info@example.com', 'Information');
  65.     //$mail->addCC('cc@example.com');
  66.     //$mail->addBCC('bcc@example.com');
  67.  
  68.     //Attachments
  69.     //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
  70.     //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
  71.  
  72.     //Content
  73.     $mail->isHTML(true);                                  // Set email format to HTML
  74.     $mail->Subject  = $_POST['assunto']; // Assunto da mensagem
  75.     $mail->Body .= " Nome: ".$_POST['nome']."<br>"; // Texto da mensagem
  76.     $mail->Body .= " E-mail: ".$_POST['email']."<br>"; // Texto da mensagem
  77.     $mail->Body .= " Assunto: ".$_POST['assunto']."<br>"; // Texto da mensagem
  78.     $mail->Body .= " Mensagem: ".nl2br($_POST['mensagem'])."<br>"; // Texto da mensagem
  79.    
  80.  
  81.     $mail->send();
  82.  
  83. } catch (Exception $e) {
  84.  
  85. }
  86.  
  87. ?>
  88.  
  89. <html>
  90.     <head>
  91.  
  92.     <meta charset="utf-8" />
  93.         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  94.         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  95.     <style>
  96.     p {
  97.         color:White;
  98.     }
  99.     </style>
  100.     </head>
  101.  
  102.     <body background="bg2.png">
  103.             <div class="py-3 text-center">
  104.                 <img class="d-block mx-auto mb-2" src="logo2.png" alt="" width="128" height="128">
  105.                 <h1 style="color: white;">Send Mail</h2>
  106.                 <p style="color: white;" class="lead">Seu app de envio de e-mails particular!</p>
  107.             </div>
  108.  
  109.     <div class="row">
  110.         <div class="col-md-12">
  111.  
  112.             <? if($mensagem->status['codigo_status'] == 1) { ?>
  113.                
  114.                 <div class="container">
  115.                 <h1 class="display-4 text-success">Sucesso !</h1>
  116.                     <p><?= $mensagem->status['descricao_status'] ?></p>
  117.                     <a href="index.php" class="btn btn-success btn-lg mt-5 text-white">Voltar</a>
  118.                 </div>
  119.  
  120.             <? } ?>
  121.  
  122.             <? if($mensagem->status['codigo_status'] == 2) { ?>
  123.                
  124.                 <div class="container">
  125.                 <h1 class="display-4 text-danger">Ops !</h1>
  126.                     <p><?= $mensagem->status['descricao_status'] ?></p>
  127.                     <a href="index.php" class="btn btn-success btn-lg mt-5 text-white">Voltar</a>
  128.                 </div>
  129.  
  130.             <? } ?>
  131.            
  132.         </div>
  133.     </div>
  134.    
  135.    
  136.  
  137.     </body>
  138.  
  139.     </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement