All pastes #764683 Raw Edit

Mariano

public text v1 · immutable
·published 2007-11-07 13:59 UTC
rendered paste body
<?php


class Email
{
	var $_error;
	var $desde;
	var $para;
	var $nombre;
	var $motivoConsulta;
	var $email;
	var $comentario;

	function setError($error)
	{
		$this -> _error = $error;
	}

	function setDesde ($desde)
 	{
 		$this->desde = $desde;
 	}

 	function getDesde ()
 	{
 		return $this->desde;
 	}

 	function setPara ($para)
 	{
 		$this->para = $para;
 	}

 	function getPara ()
 	{
 		return $this->para;
 	}

 	function setNombre ($nombre)
 	{
 		$this->nombre = $nombre;
 	}

 	function getNombre ()
 	{
 		return $this->nombre;
 	}

 	function setMotivoConsulta ($motivoConsulta)
 	{
 		$this->motivoConsulta = $motivoConsulta;
 	}

 	function getMotivoConsulta ()
 	{
 		return $this->motivoConsulta;
 	}

	function setComentario ($comentario)
 	{
 		$this->comentario = $comentario;
 	}

 	function getComentario ()
 	{
 		return $this->comentario;
 	}

	function enviarEmail()
	{
		//Encabezados
		$header="From:".$this -> desde."\nReply-To:".$this -> desde."\n";
		$header=$header."X-Mailer:PHP/".phpversion()."\n";
		$header=$header."Mime-Version: 1.0\n";
		$header=$header."Content-Type: text/html";

		$txtema="Contacto: ".$this -> motivoConsulta;
		$cab="<html><head><title>Comentario de coinn.com.ar</title><meta http-equiv=''";
		$cab=$cab."content='text/html; charset=iso-8859-1'></head><body>";

		//El Mensaje
		$mensaje="<strong>Datos del formulario de contacto</strong><br>"."\n";
		$mensaje=$mensaje."<hr>";
		$mensaje=$mensaje."<strong>Nombre</strong>: ".$this -> nombre."<br>";
		$mensaje=$mensaje."<strong>Motivo de la Consulta</strong>: ".$this -> motivoConsulta."<br>";
		$mensaje=$mensaje."<strong>Email</strong>: ".$this -> para."<br>";
		$mensaje=$mensaje."<strong>Comentarios</strong>: ".$this -> comentario."<br><br>";

		$mensaje_a_mostrar=nl2br($mensaje);
		$fin="</body></html>";
		$txdetalle=$cab.$mensaje_a_mostrar.$fin;

		@mail($this -> para,$txtema,$txdetalle,$header);
		return true;
	}

	function validarEmail($email)
	{

		//return true;
		$nonascii = "\x80-\xff"; # Non-ASCII-Chars are not allowed

		$nqtext = "[^\\\\$nonascii\015\012\"]";
		$qchar = "\\\\[^$nonascii]";

		$protocol = '(?:mailto:)';

		$normuser = '[a-zA-Z0-9][a-zA-Z0-9_.-]*';
		$quotedstring = "\"(?:$nqtext|$qchar)+\"";
		$user_part = "(?:$normuser|$quotedstring)";

		$dom_mainpart = '[a-zA-Z0-9][a-zA-Z0-9._-]*\\.';
		$dom_subpart = '(?:[a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*';
		$dom_tldpart = '[a-zA-Z]{2,5}';
		$domain_part = "$dom_subpart$dom_mainpart$dom_tldpart";

		$regex = "$protocol?$user_part\@$domain_part";
		// RegEx end

		return preg_match("/^$regex$/",$email);
	}
}
?>