Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /************************************************************************************************
- *Archivo : mailer.php *
- *Nombre logico de archivo: mailer.php *
- *Producto : Certificación *
- *Autor : Copyright (c) 2019. Desarollado por Güegüe Vásquez Compañia Limitada*
- *Propósito : *
- *Archivo de configuración para el envio de correos (Notificaciones)
- ************************************************************************************************/
- namespace app\helper;
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- class Mailer
- {
- static $pass;
- private $domain = "@gmail.com";
- private $server = array('127.0.0.1', '::1', 'localhost','192.168.1.116','192.168.1');
- /**
- * El array contiene las siguientes claves
- * Mailer constructor.
- * @param $email Correo de la persona a enviar el mensaje
- * @param $name Nombre de la persona a enviar mensaje
- * @param $asunto Asunto del mensaje
- * @param $contenido cuerpo del mensaje
- * @param $nameFile true o false indica si se va ha enviar archivo adjunto
- * @param string $dir si el archivo adjunto se encuentre en otros directorios dentro del dir principal medias
- */
- // $email, $name, $asunto, $contenido,$nameFile, $dir=''
- public function __construct($paramEmail = array()){
- $mail = new PHPMailer(true);
- // Passing 'true' enables exceptions
- try {
- //Server settings
- $mail->SMTPDebug = 0; // Enable verbose debug output
- $mail->isSMTP(); // Set mailer to use SMTP
- // Enable TLS encryption, `ssl` also accepted
- //Configuracion para conexion local
- if (in_array(substr(SERVIDOR, 0, 9), $this->server) OR SERVIDOR == "certificacion.guegue.com:9494" OR SERVIDOR == "certificacion.guegue.com:9696") {
- $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'rc819963' . $this->domain; // SMTP username
- $mail->Password = $this->password(); // SMTP password
- $mail->SMTPSecure = 'tls';
- //$mail->addStringAttachment()
- $mail->Port = 587;
- // TCP port to connect to
- /*Resolver Error de conexion al Servidor*/
- $mail->SMTPOptions = array(
- 'ssl' => array(
- 'verify_peer' => false,
- 'verify_peer_name' => false,
- 'allow_self_signed' => true
- )
- );
- } else {
- //Conexion Remota
- $mail->SMTPAuth = false;
- $mail->Host = SERVIDOR_EMAIL;
- $mail->Port = SERVIDOR_EMAIL_PORT; // TCP port to connect to
- $mail->SMTPSecure = false; // TCP port to connect to
- }
- $mail->CharSet = 'UTF-8';
- //Recipients
- $mail->setFrom('adalgarcia17@gmail.com', 'INATEC');
- $emailArray = array("email1@gmail.com", "email2@gmail.com", "email3@gmail.com");//NUEVA LINEA
- $totalEmails = count($emailArray); //NUEVA LINEA
- for ($i = 0; $i < $totalEmails; $i++) {
- $Email = $emailArray[$i];
- $mail->addAddress($Email, $paramEmail['name']); //MODIFICADA
- if ($paramEmail['adjuntarFile']) {
- $mail->addStringAttachment($paramEmail['archivo'], 'archivo.pdf', $encoding = 'base64', $type = 'application/pdf');
- }
- // Add attachments
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = $paramEmail['asunto'];
- $mail->Body = $paramEmail['contenido'];
- $mail->AltBody = 'Mensaje no soportado por su Navegador';
- $mail->send();
- //echo 'El mensaje se ha enviado <br>';
- //$paramEmail['adjuntarFile']==true?$pdf->eliminaPdf():'';
- $mail->ClearAddresses(); //NUEVA LINEA
- // return true;
- }
- }
- catch
- (\Exception $e) {
- echo 'Error:: al enviar mensaje. Mailer Error: ', $mail->ErrorInfo;
- //return false;
- }
- //echo $paramEmail['contenido'];
- }
- private function password()
- {
- self::$pass = "";
- $p = array(96, 5, 24, 16, 12, 15, 18, 1, 14, 4, 15);
- for ($i = 0; $i < count($p) - 1; $i++)
- self::$pass = self::$pass . chr($p[0] + $p[$i + 1]);
- return self::$pass . "4321";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement