Advertisement
csojunior1996

Untitled

Dec 16th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.81 KB | None | 0 0
  1. // Código do loadLibrary
  2. public function loadLibrary($lib){
  3.             if(file_exists('libs/' . $lib . '.php')){
  4.                 include 'libs/' . $lib . '.php';
  5.             }
  6.         }
  7.  
  8. //Código do Autoload
  9.  
  10. <?php
  11.  
  12.     session_start();
  13.  
  14.     require 'config.php';
  15.  
  16.     spl_autoload_register(function ($class){
  17.         if(strpos($class, 'Controller') > -1){
  18.             if(file_exists('controllers/' . $class . '.php')){
  19.                 require_once 'controllers/' . $class . '.php';
  20.             }
  21.         }else if(file_exists('models/' . $class . '.php')){
  22.             require_once 'models/' . $class . '.php';
  23.         }else{
  24.             require_once 'core/' . $class . '.php';
  25.         }
  26.     });
  27.  
  28.     $core = new Core();
  29.     $core->run();
  30.  
  31. ?>
  32.  
  33. // Código do controller em que preciso usar o phpMailer
  34.  
  35. <?php
  36.  
  37. class contatoController extends controller
  38. {
  39.     public function faleConosco(){
  40.  
  41.         if(isset($_POST['nome']) && !empty($_POST['nome']) &&
  42.             isset($_POST['email']) && !empty($_POST['email']) &&
  43.             isset($_POST['assunto']) && !empty($_POST['assunto']) &&
  44.             isset($_POST['mensagem']) && !empty($_POST['mensagem'])
  45.         ){
  46.             $nome = addslashes($_POST['nome']);
  47.             $email = addslashes($_POST['email']);
  48.             $assunto = addslashes($_POST['assunto']);
  49.             $mensagem = addslashes($_POST['mensagem']);
  50.  
  51.  
  52.             $this->loadLibrary('phpmailer/PHPMailerAutoload');
  53.             $mail = new PHPMailer();
  54.             $mail->isSMTP();
  55.             $mail->Host = 'aqui vai o servidor';  // Specify main and backup SMTP servers
  56.             $mail->SMTPAuth = true;                               // Enable SMTP authentication
  57.             $mail->Username = 'aqui vai o email';                 // SMTP username
  58.             $mail->Password = 'aqui vai a senha';                           // SMTP password
  59.             $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
  60.             $mail->Port = aqui vai a porta;                                    // TCP port to connect to
  61.  
  62.             $mail->setFrom($email, 'Usuário Plataforma EAD');
  63.             $mail->addAddress('contato@claudiojunior.tk');               // Name is optional
  64.             $mail->isHTML(false);                                  // Set email format to HTML
  65.  
  66.             $mail->Subject = $assunto;
  67.             $mail->Body    = $mensagem;
  68.             $mail->AltBody = $mensagem;
  69.  
  70.             if(!$mail->send()) {
  71.                 echo "<script>alert('Message could not be sent')</script>";
  72.                 echo "<script>alert('Mailer Error: " . $mail->ErrorInfo . "')</script>";
  73.             } else {
  74.                 echo "<script>alert('Message has been sent')</script>";
  75.             }
  76.         }
  77.     }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement