Advertisement
Guest User

Untitled

a guest
Mar 8th, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.18 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 = '@Acesspublic0';                           // 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. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement