<?php
// $Id: mailer.inc.php,v 1.9 2004/10/09 00:25:32 xistence Exp $
// -----------------------------------------------------------
// (C) 2002 - 2003 X-Istence.com
//
// Author: Jan-Willem Regeer
// [email]xistence@x-istence.com[/email]
// -----------------------------------------------------------
// X-Istence.com Mailer Class
class XI_Mailer {
private $to;
private $from;
private $header;
private $message;
private $data;
private $data_orig;
var $server_adress = "localhost";
var $server_port = "25";
var $server_username = "";
var $server_password = "";
function to($to) {
if(issarray($to) {
$this->to = $to; // Has to be an array.
}
else
die("What kind of coding are you doing?");
}
function from ($from) {
$this->from = $from; // Has to be a single adress
}
function subject($subject) {
$this->subject = $subject;
}
function mheader($custom = "") {
if ($custom == "") {
$this->header = "To: {email_name} <{email_usermail}>\r\n";
$this->header .= "From: {name} <{mail_from}>\r\n";
$this->header .= "Reply-To: {name} <{mail_from}>\r\n";
$this->header .= "Subject: {email_subject}\r\n";
$this->header .= "Return-Path: {name} <{mail_from}>\r\n";
$this->header .= "Bounce-To: {name} <{mail_from}>\r\n";
$this->header .= "Errors-To: {name} <{mail_from}>\r\n";
$this->header .= "X-Priority: 3\r\n";
$this->header .= "X-Mailer: X-Istence.com Mailer\r\n";
}
else {
$this->header = $custom;
}
}
function message ($message) {
$this->message = $message;
}
function send () {
$this->compile_entire();
$connect = fsockopen ($this->server_adress , $this->server_port , $errno, $errstr, 5) or die("Mail server is down. Please hit your back button, and try again");
$rcv = fgets($connect, 1024);
fputs($connect, "EHLO {$_SERVER['SERVER_NAME']}\r\n");
$rcv = fgets($connect, 1024);
$x = count($this->to);
for ($y = 0; $y < $x; $y++) {
$stuff['name'] = $this->from['name'];
$stuff['mail_from'] = $this->from['mail'];
$stuff['email_name'] = $this->to[$y]['email_name'];
$stuff['email_usermail'] = $this->to[$y]['email_usermail'];
$stuff['email_subject'] = $this->subject;
fputs($connect, "MAIL FROM: ". $this->from['name'] ." <". $this->from['mail'] .">\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, "RCPT TO: ". $this->to[$y]['email_name'] ." <". $this->to[$y]['email_usermail'] .">\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, "DATA\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, preg_replace("/\{(.+?)\}/e", "\$stuff['\\1']", $this->data));
fputs($connect, ".\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, "RSET\r\n");
$rcv = fgets($connect, 1024);
}
fputs($connect, "QUIT\r\n");
$rcv = fgets($connect, 1024);
fclose($connect);
}
function compile_entire() {
$this->data = $this->header;
$this->data .= "\r\n";
$this->data .= $this->message;
$this->data .= "\r\n";
}
}
?>