La clase SMTPclass.php
<?
class SMTPClient{
function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body){
$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;
$this->PortSMTP = ($SmtpPort == "") ? 25 : $SmtpPort;
}
function SendMail (){
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP)) {
fputs ($SMTPIN, "EHLO " . $HTTP_HOST . "\n");
$talk["hello"] = fgets ( $SMTPIN, 1024 );
fputs($SMTPIN, "auth login\n");
$talk["res"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, $this->SmtpUser . "\n");
$talk["user"] = fgets($SMTPIN , 1024);
fputs($SMTPIN, $this->SmtpPass . "\n");
$talk["pass"] = fgets($SMTPIN, 256);
fputs ($SMTPIN, "MAIL FROM: <" . $this->from . ">\n");
$talk["From"] = fgets ($SMTPIN, 1024);
fputs ($SMTPIN, "RCPT TO: <" . $this->to . ">\n");
$talk["To"] = fgets ($SMTPIN, 1024);
fputs($SMTPIN, "DATA\n");
$talk["data"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "MIME-Version: 1.0\nContent-type: text/html; charset=iso-8859-1\nTo: <" . $this->to . ">\nFrom: <" . $this->from . ">\nSubject:" . $this->subject . "\n\n\n" . $this->body . "\n.\n");
$talk["send"] = fgets($SMTPIN, 256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUIT\n");
fclose($SMTPIN);
//
}
return $talk;
}
}
?>
El archivo de configuración config.php
// SMTP CONFIG $SmtpServer = "smtp.ultracavallsdelvent.com"; $SmtpPort = "25"; $SmtpUser = "xxxxx"; $SmtpPass = "xxxxx";
Ejemplo de uso:
function sustituir($html, $sustituto, $aguja){
$buscar = array();
$buscar[0] = "{{" . strtolower($aguja) . "}}";
$buscar[1] = "{{" . strtoupper($aguja) . "}}";
$html = preg_replace($buscar, $sustituto, $html);
return $html;
}
$asunto = "Aquest es l'assumpte";
$message = file_get_contents('email-templates/preinscripcion.html');
$message = sustituir($message, "molta experiencia", 'experiencia');
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, 'from@dominio.com', 'to@destino.com', $asunto, $message);
$SMTPChat = $SMTPMail->SendMail();

