Posted in

Clase emailing y su uso

Para enviar un email podemos usar la siguiente clase:

class emailing {

var $para;
var $asunto;
var $de;
var $cc;
var $bcc;
var $reply;

function CMail(){
$this->para = "";
$this->asunto = "";
$this->de = "";
$this->cc = "";
$this->bcc = "";
$this->reply = "";

}

function setAsunto($a){
$this->asunto = $a;ction setDe($d,$nombre=""){
if($nombre != ""){
$this->de = $nombre." <".$d.">";$d;
}
}

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

function setBcc($b){
if($this->bcc==""){
$this->bcc = $b;
}else{
$this->bcc.=",".$b;
}
}

function setCc($c){
if($this->cc==""){
$this->cc = $c;
}else{
$this->cc.=",".$c;
}
}

function setReply($r){
$this->reply = $r;
}

function enviar($mensaje){
$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
//dirección del remitente 
$headers .= "From: ".$this->de."\r\n"; 

if($this->reply != ""){
//dirección de respuesta, si queremos que sea distinta que la del remitente 
$headers .= "Reply-To: ".$this->reply."\r\n"; 
}
if($this->cc != ""){
//direcciones que recibirán copia 
$headers .= "Cc: ".$this->cc."\r\n"; 
}
if($this->bcc != ""){
//direcciones que recibirán copia oculta 
$headers .= "Bcc: ".$this->bcc."\r\n"; 
}
mail($this->para, $this->asunto, $mensaje, $headers); 
}

}

Y cómo usarlo:

require_once("../_CLASS/emailing.class.php");
$emailing = new emailing($mysql);

$email = "Email de destino";
$asunto = "Asunto";

$emailing->setDe("remitente@dominio.es", "Email Test");
$emailing->setPara($email);
$emailing->setAsunto($asunto);g->enviar($html);

Deixa un comentari

L'adreça electrònica no es publicarà. Els camps necessaris estan marcats amb *


The reCAPTCHA verification period has expired. Please reload the page.