Scripts

smtp php class

Met deze class kun je email's zenden over smtp. bijvoorbeeld als je met bijvoorbeeld mail() niet verzonden krijgt hoe te gebruiken

smtp.class.php
<?php
/*
SMTP mail class for php by daiman meijers
You can use this script if the php function mail() fails.
here can you send mails with the SMTP protocol.
gmail is a good smtp host for the smtp server and free.
*/

class smtp {

public $fp;
public $log;
public $nlijn;
public $logb;

public function sconnect($host, $port, $gebruiker, $wachtwoord, $timeout, $logb) {
$this->nlijn = "\r\n";
        $this->fp = fsockopen($host, $port, $erstr, $erli, $timeout);
		if (empty($this->fp)) {
	    echo exit("kon niet met de opgegeven host verbinden");
		}
		else {
		$this->log["connect"] = fgets($this->fp, 515);
		}
	
		fputs($this->fp,"AUTH LOGIN" . $this->nlijn);
		$this->log["auth"] = fgets($this->fp, 515);
		fputs($this->fp, base64_encode($gebruiker) . $this->nlijn);
		$this->log["usr"] = fgets($this->fp, 515);
		fputs($this->fp, base64_encode($wachtwoord) . $this->nlijn);
		$this->log["pass"] = fgets($this->fp, 515);
		
		fputs($this->fp, "HELO localhost" . $this->nlijn);
		$this->log["helo"] = fgets($this->fp, 515);
		$this->logb = $logb;
}

	public function smail($van, $vannaam, $aan, $aannaam, $bericht, $onderwerp) {
	    
		

		fputs($this->fp, "MAIL FROM: $van" . $this->nlijn);
		$this->log["from"] = fgets($this->fp, 515);
		fputs($this->fp, "RCPT TO: $aan" . $this->nlijn);
		$this->log["to"] = fgets($this->fp, 515);
		fputs($this->fp, "DATA" . $this->nlijn);
		$this->log["data"] = fgets($this->fp, 515);
		
		$headers = "MIME-Version: 1.0" . $this->nlijn;
		$headers .= "Content-type: text/html; charset=iso-8859-1" . $this->nlijn;
		$headers .= "To: $aannaam <$aan>" . $this->nlijn;
		$headers .= "From: $vannaam <$van>" . $this->nlijn;
		$headers .= "Subject: $onderwerp" . $this->nlijn;
		
		fputs($this->fp, "$headers\n\n$bericht\r\n.\r\n");
		$this->log["head"] = fgets($this->fp, 515);
		
		fputs($this->fp,"QUIT" . $nlijn); 
		$this->log["close"] = fgets($this->fp, 515);
		if ($this->logb = 1) {
		print_r($this->log);
		}
	}
	
}
?>

Reacties

0
Nog geen reacties.