Ir para conteúdo
Fórum Script Brasil
  • 0

Como Chamar A Classe


mestre fyoda

Pergunta

como eu faço para chamar e funcionar o codigo ?

<?php

#################################

# #

# SmtpMailer v1.0 #

# Developed by: rEd nEcK * #

# #

#################################

class SmtpMailer{

var $sock, $host, $port, $error;

var $isAuth, $user, $pass;

function SmtpMailer($host,$port=25,$isAuth=true){

$this->host = $host;

$this->port = $port;

$this->isAuth = $isAuth;

$this->sock = fsockopen($host, $port, $errno, $errstr, 30);

if( $this->Get() <> 220 ) $error = "Falha ao tentar se conectar ao servidor";

$this->Put("EHLO $host");

if( $this->Get() <> 250 ) $error = "Falha ao tentar enviar o comando EHLO";

}

function Auth(){

$this->Put("AUTH LOGIN");

if( $this->Get() <> 250 ) $error = "Falha ao tentar enviar o comando AUTH PLAIN";

$this->Put(base64_encode($this->user));

if( $this->Get() <> 334 ) $error = "Falha ao tentar enviar o USUARIO";

$this->Put(base64_encode($this->pass));

if( $this->Get() <> 334 ) $error = "Falha ao tentar enviar a SENHA";

if( $this->Get() <> 235 ) $error = "Falha ao tentar autentificar";

}

function MakeHeader($to, $from, $subject){

$header = "MIME-Version: 1.0\r\n";

$header .= "Content-type: text/html; charset=iso-8859-1\r\n";

$header .= "Message-Id: <". date('YmdHis').".". md5(microtime()).".". strtoupper($from) ."> \r\n";

$header .= "From: <" . $from . "> \r\n";

$header .= "To: <".$to."> \r\n";

$header .= "Subject: ".$subject." \r\n";

$header .= "Date: ". date('D, d M Y H:i:s O') ." \r\n";

$header .= "X-MSMail-Priority: High \r\n";

return $header;

}

function Send($to, $from, $subject, $msg){

if( $this->isAuth == true )

$this->Auth();

$this->Put("MAIL FROM: " . $from);

if( $this->Get() <> 334 ) $error = "Falha ao tentar enviar o comando MAIL FROM";

$this->Put("RCPT TO: " . $to);

if( $this->Get() <> 334 ) $error = "Falha ao tentar enviar o comando RCPT TO";

$this->Put("DATA");

if( $this->Get() <> 334 ) $error = "Falha ao tentar enviar o comando DATA";

$this->Put($this->MakeHeader($to, $from, $subject));

if( $this->Get() <> 334 ) $error = "Falha ao tentar enviar as HEADERS";

$this->Put("\r\n");

if( $this->Get() <> 334 ) $error = "Falha ao tentar enviar o comando NEWLINE";

$this->Put($msg);

if( $this->Get() <> 334 ) $error = "Falha ao tentar enviar a MENSAGEM";

$this->Put(".");

if( $this->Get() <> 334 ) $error = "Falha ao tentar enviar a SENHA";

if( $this->Get() <> 250 ) return false; else return true;

$this->Close();

}

function Close(){

$this->Put("QUIT");

return fclose($this->sock);

}

function Put($value){

return fputs($this->sock, $value . "\r\n");

}

function Get(){

$line = fgets($this->sock). "<br>\n";

return $line{0}.$line{1}.$line{2};

}

}

define('SMTP_HOST','mail.host.com'); // host do servidor smtp

define('SMTP_PORT',25); // porta do servidor smtp

define('SMTP_USER','user@host.com'); // usuario para autentificação

define('SMTP_PASS','****'); // senha para autentificação

$sendVar["destino"] = "contato@host.com";

$sendVar["assunto"] = "Mensagem enviada via Smtp";

$sendVar["mensagem"] = "Bla<b>bla</b>bla<br>blublu";

$smtp = new SmtpMailer(SMTP_HOST,SMTP_PORT,true);

$smtp->user = SMTP_USER;

$smtp->pass = SMTP_PASS;

$smtp->Send($sendVar["destino"], SMTP_USER, $sendVar["assunto"], $sendVar["mensagem"]);

?>

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0
Guest Visitante
<?
(...)

include "script_onde_tah_a_classe.php";

(...)

// para chamar a classe
$var = new SmtpMailer;
// para usar função de dentro da classe chamada
$var->nomeda_funcao();

(...)
?>[/php]

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,4k
    • Posts
      652,3k
×
×
  • Criar Novo...