Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Contacto
- {
- var $Nombre;
- var $Email;
- var $Web;
- var $Mensaje;
- var $MiCorreo = array("andrew@mokomonster.com", "crymore3@gmail.com"); // Correos a quienes se les enviara
- var $Opcion = array(0, 1, 2); // Las formas que deceemos que se guarden 0 = Archivo en el servidor, 1 = Por Correo, 2 = En una tabla de la BD
- var $Exito;
- var $BD = array("localhost", "root", "", "Contacto");
- public function SetDatos($nombre, $correo, $web, $mensaje)
- {
- $this->Nombre = limpiar($nombre);
- $this->Email = limpiar($correo);
- $this->Web = limpiar($web);
- $this->Mensaje = limpiar($mensaje);
- }
- public function Enviar()
- {
- if(!$this->ChecarDatos())
- {
- alerta("Alguno(s) de los campos estan vacios", "/");
- die();
- }
- $this->Exito = false;
- $Hoy = date("F j, Y, g:i a");
- // Guardando en un Archivo
- if(in_array(0, $this->Opcion))
- {
- $archivo = @fopen("Contacto.txt", "a+");
- @fprintf($archivo, "Fecha[%s]: %s\n%s\n%s\n%s \n\n\n", $Hoy, $this->Mensaje,"By".$this->Nombre,$this->Email,$this->Web);
- @fclose($archivo);
- $this->Exito = true;
- }
- // Enviando un mail a todos los administradores
- if(in_array(1, $this->Opcion))
- {
- foreach($this->MiCorreo as $corr)
- {
- if(@mail($this->MiCorreo, "Contacto [".$this->Nombre."]", $this->Mensaje."<br />By".$this->Nombre."<br />".$this->Email."<br />".$this->Web))
- {
- $this->Exito = true;
- }
- }
- }
- // Guardando la informacion en la BD
- $link = @mysql_connect($this->BD[0], $this->BD[1], $this->BD[2]);
- if($link)
- {
- if(@mysql_select_db($this->BD[3], $link))
- {
- /*
- Tabla [Contacto]
- idContacto INT AutoIncrementable
- Nombre varchar(45) NOT NULL
- Email varchar(45) NOT NULL
- Web varchar(45) NULL
- Mensaje varchar(500) NOT NULL
- Fecha varchar(50) NOT NULL
- */
- $sql = @mysql_query("INSERT INTO Contacto (Nombre, Email, Web, Mensaje, Fecha) VALUES ('".$this->Nombre."', '".$this->Email."', '".$this->Web."', '".$this->Mensaje."', '".$Hoy."')");
- if($sql)
- {
- $this->Exito = true;
- }
- }
- }
- if($this->Exito)
- {
- alerta("Mensaje Enviado, Te responderemos lo mas pronto posible!", "/");
- die();
- }else{
- alerta("Hubo un error al enviar el mensaje para contacto, intente de nuevo mas tarde porfavor!", "/");
- die();
- }
- }
- private function ChecarDatos()
- {
- if(empty($this->Nombre) || empty($this->Email) || empty($this->Mensaje))
- {
- return false;
- }
- return true;
- }
- private function limpiar($valor)
- {
- $check = $valor;
- $valor = mysql_real_escape_string(htmlspecialchars(strip_tags($valor)));
- return ($check != $valor) ? "" : $valor;
- }
- private function alerta($text, $url)
- {
- echo "<body bgcolor='#000000'><script>alert('$text');document.location = '$url'</script></body>";
- die("Javascript disabled");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement