Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. <?php
  2.  
  3. /************************************************************************************************
  4. *Archivo : mailer.php *
  5. *Nombre logico de archivo: mailer.php *
  6. *Producto : Certificación *
  7. *Autor : Copyright (c) 2019. Desarollado por Güegüe Vásquez Compañia Limitada*
  8. *Propósito : *
  9. *Archivo de configuración para el envio de correos (Notificaciones)
  10. ************************************************************************************************/
  11. namespace app\helper;
  12.  
  13. use PHPMailer\PHPMailer\PHPMailer;
  14. use PHPMailer\PHPMailer\Exception;
  15.  
  16.  
  17. class Mailer
  18. {
  19.  
  20. static $pass;
  21. private $domain = "@gmail.com";
  22.  
  23. private $server = array('127.0.0.1', '::1', 'localhost','192.168.1.116','192.168.1');
  24.  
  25.  
  26. /**
  27. * El array contiene las siguientes claves
  28. * Mailer constructor.
  29. * @param $email Correo de la persona a enviar el mensaje
  30. * @param $name Nombre de la persona a enviar mensaje
  31. * @param $asunto Asunto del mensaje
  32. * @param $contenido cuerpo del mensaje
  33. * @param $nameFile true o false indica si se va ha enviar archivo adjunto
  34. * @param string $dir si el archivo adjunto se encuentre en otros directorios dentro del dir principal medias
  35. */
  36. // $email, $name, $asunto, $contenido,$nameFile, $dir=''
  37. public function __construct($paramEmail = array()){
  38.  
  39. $mail = new PHPMailer(true);
  40.  
  41. // Passing 'true' enables exceptions
  42. try {
  43. //Server settings
  44. $mail->SMTPDebug = 0; // Enable verbose debug output
  45. $mail->isSMTP(); // Set mailer to use SMTP
  46. // Enable TLS encryption, `ssl` also accepted
  47.  
  48. //Configuracion para conexion local
  49. if (in_array(substr(SERVIDOR, 0, 9), $this->server) OR SERVIDOR == "certificacion.guegue.com:9494" OR SERVIDOR == "certificacion.guegue.com:9696") {
  50. $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
  51. $mail->SMTPAuth = true; // Enable SMTP authentication
  52. $mail->Username = 'rc819963' . $this->domain; // SMTP username
  53. $mail->Password = $this->password(); // SMTP password
  54. $mail->SMTPSecure = 'tls';
  55. //$mail->addStringAttachment()
  56.  
  57. $mail->Port = 587;
  58. // TCP port to connect to
  59.  
  60. /*Resolver Error de conexion al Servidor*/
  61.  
  62. $mail->SMTPOptions = array(
  63. 'ssl' => array(
  64. 'verify_peer' => false,
  65. 'verify_peer_name' => false,
  66. 'allow_self_signed' => true
  67. )
  68. );
  69. } else {
  70. //Conexion Remota
  71. $mail->SMTPAuth = false;
  72. $mail->Host = SERVIDOR_EMAIL;
  73. $mail->Port = SERVIDOR_EMAIL_PORT; // TCP port to connect to
  74. $mail->SMTPSecure = false; // TCP port to connect to
  75. }
  76.  
  77.  
  78. $mail->CharSet = 'UTF-8';
  79. //Recipients
  80. $mail->setFrom('adalgarcia17@gmail.com', 'INATEC');
  81.  
  82. $emailArray = array("email1@gmail.com", "email2@gmail.com", "email3@gmail.com");//NUEVA LINEA
  83. $totalEmails = count($emailArray); //NUEVA LINEA
  84.  
  85. for ($i = 0; $i < $totalEmails; $i++) {
  86.  
  87. $Email = $emailArray[$i];
  88. $mail->addAddress($Email, $paramEmail['name']); //MODIFICADA
  89.  
  90. if ($paramEmail['adjuntarFile']) {
  91.  
  92. $mail->addStringAttachment($paramEmail['archivo'], 'archivo.pdf', $encoding = 'base64', $type = 'application/pdf');
  93. }
  94.  
  95. // Add attachments
  96.  
  97. $mail->isHTML(true); // Set email format to HTML
  98. $mail->Subject = $paramEmail['asunto'];
  99. $mail->Body = $paramEmail['contenido'];
  100. $mail->AltBody = 'Mensaje no soportado por su Navegador';
  101.  
  102. $mail->send();
  103. //echo 'El mensaje se ha enviado <br>';
  104.  
  105. //$paramEmail['adjuntarFile']==true?$pdf->eliminaPdf():'';
  106.  
  107. $mail->ClearAddresses(); //NUEVA LINEA
  108.  
  109. // return true;
  110. }
  111.  
  112. }
  113. catch
  114. (\Exception $e) {
  115. echo 'Error:: al enviar mensaje. Mailer Error: ', $mail->ErrorInfo;
  116. //return false;
  117. }
  118.  
  119. //echo $paramEmail['contenido'];
  120.  
  121. }
  122.  
  123.  
  124. private function password()
  125. {
  126. self::$pass = "";
  127. $p = array(96, 5, 24, 16, 12, 15, 18, 1, 14, 4, 15);
  128.  
  129. for ($i = 0; $i < count($p) - 1; $i++)
  130. self::$pass = self::$pass . chr($p[0] + $p[$i + 1]);
  131.  
  132. return self::$pass . "4321";
  133. }
  134.  
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement