Here is the Email class. It may run out to the right a bit.
<?php
/*
##################################################
#
# Filename..........: $RCSfile: Email.php,v $
# Original Author...: Anthony L. Awtrey
# Version...........: $Revision: 0.1 $
# Last Modified By..: $Author: aawtrey $
# Last Modified.....: $Date: 2006/09/21 18:15:56 $
#
# Copyright 2006 Anthony Awtrey
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
*/
/*
* This class abstracts and simplifies sending email.
*/
class Email {
var $to;
var $from;
var $subject;
var $headers;
var $body;
/*
* Class initialization
*/
function __construct($inTo='[email protected]',$inFrom='[email protected]',$inSubject='',$inBody='') {
global $_SERVER;
global $_SESSION;
global $_REQUEST;
global $_POST;
global $_GET;
$this->setTo($inTo);
$this->setFrom($inFrom);
$this->setSubject($inSubject);
$this->setBody($inBody);
}
function __destruct()
{
}
/*
* Simple email address validator
*/
function _checkEmail($inEmail) {
if( preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9._-] +)+$/" , $inEmail) ){
list($username,$domain)=split('@',$inEmail);
if( !checkdnsrr($domain,'MX') ) {
return false;
}
return true;
}
return false;
}
/*
* Validates and sets the To: line address
*/
function setTo($inTo) {
if ( $this->_checkEmail($inTo) ) {
return false;
}
$this->to = $inTo;
return true;
}
/*
* Gets the To: line address
*/
function getTo() {
return $this->to;
}
/*
* Validates and sets the From: line address
*/
function setFrom($inFrom) {
if ( $this->_checkEmail($inFrom) ) {
return false;
}
$this->from = $inFrom;
return true;
}
/*
* Gets the From: line address
*/
function getFrom() {
return $this->from;
}
/*
* Sets the subject line value
*/
function setSubject($inSubject) {
$this->subject = $inSubject;
return true;
}
/*
* Gets the subject line value
*/
function getSubject() {
return $this->subject;
}
/*
* Sets arbitrary header lines (must be formated correctly with rn per line)
*/
function setHeaders($inHeaders) {
$this->headers = $inHeaders;
return true;
}
/*
* Gets the arbitrary header lines
*/
function getHeaders() {
return $this->headers;
}
/*
* Sets the email body
*/
function setBody($inBody) {
$this->body = $inBody;
return true;
}
/*
* Gets the email body
*/
function getBody() {
return $this->body;
}
/*
* Sends the email
*/
function send() {
if ( $this->getFrom() != '' ) {
$this->setHeaders( 'From: ' . $this->getFrom() . "rn" . 'Reply-To: ' . $this->getFrom() . "rn" );
}
return mail( $this->getTo(), $this->getSubject(), $this->getBody(), $this->getHeaders() );
}
}
?>