Advertisement
Guest User

enviaemail

a guest
Jul 5th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.58 KB | None | 0 0
  1. <?php
  2.  
  3. require 'vendor/phpmailer/class.phpmailer.php';
  4. require 'vendor/phpmailer/class.phpmaileroauth.php';
  5. require 'vendor/phpmailer/class.phpmaileroauthgoogle.php';
  6. require 'vendor/phpmailer/class.smtp.php';
  7. require 'vendor/phpmailer/class.pop3.php';
  8.  
  9. Class Sender {
  10.  
  11.     static public function __runtest() {
  12.         $host = new smtpModel();
  13.         $mail = new PHPMailer();
  14.  
  15.         $data = array(
  16.             'destinatario' => 'orlando@phpstaff.com.br',
  17.             'assunto' => 'ASSUNTO TESTE',
  18.             'mensagem' => 'MENSAGEM TESTE',
  19.             'responder' => ''
  20.         );
  21.         self::mail($data);
  22.     }
  23.  
  24.     static public function mail($data) {
  25.         //$data['destinatario' => 'fulado@gmail.com', 'assunto' => 'teste', 'mensagem' => 'mensagem teste', 'copia' => '', 'responder' => ''];
  26.         $host = new smtpModel();
  27.         $mail = new PHPMailer();
  28.         $mail->isSMTP();
  29. //        $mail->SMTPSecure = 'tls';
  30.         $mail->SMTPDebug = 0;
  31.         $mail->SMTPAuth = true;
  32.         $mail->Host = $host->__get('host');
  33.         $mail->Port = $host->__get('port');
  34.         $mail->Username = $host->__get('email');
  35.         $mail->Password = $host->__get('pass');
  36.         $mail->setFrom($host->__get('email'), utf8_decode($host->__get('nome')));
  37.  
  38.  
  39.         if (isset($data['responder']) && !empty($data['responder'])) {
  40.             $mail->addReplyTo($data['responder']);
  41.         }
  42.         if (isset($data['copia']) && is_array($data['copia'])) {
  43.             foreach ($data['copia'] as $copia) {
  44.                 $mail->addBCC("$copia");
  45.             }
  46.         }
  47.         $mail->addAddress($data['destinatario']);
  48.         $mail->Subject = utf8_decode($data['assunto']);
  49.         //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  50.         $mail->msgHTML(utf8_decode($data['mensagem']));
  51.         $mail->AltBody = '';
  52.         //$mail->addAttachment('images/phpmailer_mini.png');
  53.         if (!$mail->send()) {
  54.             echo "Mailer Error: " . $mail->ErrorInfo;
  55.         } else {
  56.            return true;
  57.         }
  58.     }
  59.  
  60.  
  61.     static public function multiple_mail($data) {
  62.         //$data['destinatario' => 'fulado@gmail.com', 'assunto' => 'teste', 'mensagem' => 'mensagem teste', 'copia' => '', 'responder' => ''];
  63.         $host = new smtpModel();
  64.         $mail = new PHPMailer();
  65.         $mail->isSMTP();
  66. //        $mail->SMTPSecure = 'tls';
  67.         $mail->SMTPDebug = 0;
  68.         $mail->SMTPAuth = true;
  69.         $mail->Host = $host->__get('host');
  70.         $mail->Port = $host->__get('port');
  71.         $mail->Username = $host->__get('email');
  72.         $mail->Password = $host->__get('pass');
  73.         $mail->setFrom($host->__get('email'), utf8_decode($host->__get('nome')));
  74.  
  75.  
  76.         if (isset($data['responder']) && !empty($data['responder'])) {
  77.             $mail->addReplyTo($data['responder']);
  78.         }
  79.         if (isset($data['copia']) && is_array($data['copia'])) {
  80.             foreach ($data['copia'] as $copia) {
  81.                 $mail->addBCC("$copia");
  82.             }
  83.         }
  84.  
  85.         foreach ($data['destinatario'] as $destinatario) {
  86.             $mail->addAddress($destinatario->usuario_email);
  87.         }
  88.         $mail->Subject = utf8_decode($data['assunto']);
  89.         //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  90.         $mail->msgHTML(utf8_decode($data['mensagem']));
  91.         $mail->AltBody = '';
  92.         //$mail->addAttachment('images/phpmailer_mini.png');
  93.         if (!$mail->send()) {
  94.             echo "Mailer Error: " . $mail->ErrorInfo;
  95.         } else {
  96.             return true;
  97.         }
  98.     }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement