setLanguage('es','PHPMailer/language'); $this->isSMTP(); //Utiliza los datos de conexion que se le pasan por parametros, si no tiene se usan los datos del archivo de configuracion. if (!empty($server)) { $this->Host = $server['host']; $this->Port = $server['port']; } else { //Recogemos los datos del servidor de SMTP $conf = ConfigFramework::getConfig(); $smtpConf = $conf->getSMTPServer(); $this->Host = $smtpConf['host']; $this->Port = $smtpConf['port']; } $this->SMTPAuth = false; $this->SMTPSecure = false; $this->SMTPOptions = array ( 'ssl' => array ( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); } /** * Prepara un correo sin ficheros anexados * @param string $from Direccion de correo del remitente * @param string $nombre Nombre del remitente * @param array $to Array clave/valor con los destinatarios. La clave es el correo y el valor el nombre. * @param string $subject Asunto del mensaje. * @param string $body Cuerpo (texto) del mensaje. * @param array $cc Array clave/valor con los destinatarios. La clave es el correo y el valor el nombre.[Opcional] * @param boolean $html Define si el el cuerpo del mensaje es HTML o no. [Opcional] Por defecto false. */ public function sinAnexo($from,$nombre,$to,$subject,$body,$cc='',$html=false) { try { $this->setFrom($from,$nombre); foreach ($to as $destinatario => $nombreDest) { if(is_numeric($destinatario)) { $this->addAddress($nombreDest); } else { $this->addAddress($destinatario,$nombre); } } if(!empty($cc)) { foreach ($cc as $destinatario => $nombreDest){ if(is_numeric($destinatario)) { $this->addCC($nombreDest); } else { $this->addCC($destinatario,$nombre); } } } $this->Subject = $subject; $this->isHTML($html); if($html) { $this->Body = $this->msgHTML($body); } else { $this->Body = $body; } } catch (Exception $e) { error_log('Error al preparar el correo: '.$this->ErrorInfo); return -1; } } /** * Prepara un correo con un fichero anexado * @param string $from Direccion de correo del remitente * @param string $nombre Nombre del remitente * @param array $to Array clave/valor con los destinatarios. La clave es el correo y el valor el nombre. * @param string $subject Asunto del mensaje. * @param string $body Cuerpo (texto) del mensaje. * @param string $path_fich Ruta donde se encuentra el fichero * @param string $nom_fich Nombre con el que se mandara el fichero [Opcional] * @param array $cc Array clave/valor con los destinatarios. La clave es el correo y el valor el nombre.[Opcional] * @param boolean $html Define si el el cuerpo del mensaje es HTML o no. [Opcional] Por defecto false. */ public function conAnexo($from,$nombre,$to,$subject,$body,$path_fich,$nom_fich = '',$cc='',$html=false) { try{ $this->sinAnexo($from, $nombre, $to, $subject,$body,$cc,$html); $this->addAttachment($path_fich,$nom_fich); } catch (Exception $e) { error_log('Error al preparar el correo: '.$this->ErrorInfo); return -1; } } /** * Prepara un correo con un fichero binario anexado * @param string $from Direccion de correo del remitente * @param string $nombre Nombre del remitente * @param array $to Array clave/valor con los destinatarios. La clave es el correo y el valor el nombre. * @param string $subject Asunto del mensaje. * @param string $body Cuerpo (texto) del mensaje. * @param string $path_fich Fichero que se quiere enviar como anexo * @param string $nom_fich Nombre con el que se mandara el fichero [Opcional] * @param array $cc Array clave/valor con los destinatarios. La clave es el correo y el valor el nombre.[Opcional] * @param boolean $html Define si el el cuerpo del mensaje es HTML o no. [Opcional] Por defecto false. */ public function conAnexoBin($from,$nombre,$to,$subject,$msg,$fichero,$nom_fich,$cc='',$html=false) { try{ $this->sinAnexo($from, $nombre, $to, $subject,$body,$cc,$html); $this->addStringAttachment($fichero, $nom_fich); } catch (Exception $e) { error_log('Error al preparar el correo: '.$this->ErrorInfo); return -1; } } /** * Envia el correo previamente definido. * */ public function enviar() { try{ $result = $this->send(); if ($result){ return $result; } } catch (Exception $e) { error_log('Error al preparar el correo: '.$this->ErrorInfo); return -1; } } }