//
// Contact: Mittlere Ebenhalde
// D-88142 Wasserburg
//
// Creation date: 04.10.2005
//
class Mail
{
public $fromName = "";
public $fromEmail = "";
public $recipientList = array();
public $subjectText = "";
public $mailText = "";
public $mailAttachment = array();
public $mailHeader = "";
public $additional = "";
private $error_reason = array();
// -------------------------------------------------------------------
// public methods
// -------------------------------------------------------------------
// from name setzen
function setFromName($fromName)
{
$this->from_name = $fromName;
}
// from email setzen
function setFromEmail($fromEmail)
{
$this->from_email = $fromEmail;
}
// from email setzen
function setRecipient($recipientList)
{
$this->recipient = $recipientList;
}
// subject setzen
function setSubject($subjectText)
{
$this->subject = $subjectText;
}
// mail message setzen
function setMessage($mailText)
{
$this->message = $mailText;
}
// mail message setzen
function setAttachment($mailAttachment)
{
$this->attachment = $mailAttachment;
}
// zusaetzliche header setzen
function setHeader($mailHeader)
{
$this->header .= $mailHeader."\n";
}
// zusaetzliche parameter setzen
function setAdditional($additional)
{
$this->additional = $additional;
}
// mail versenden
function send()
{
// checken, ob auch alles benoetigte gesetzt ist
if($this->recipientList == "")
$this->error_reason[] = "Empfänger nicht angegeben";
if($this->from_email == "")
$this->error_reason[] = "Absender eMail-Adresse nicht angegeben";
if($this->message == "")
$this->error_reason[] = "Mailtext nicht angegeben";
// alles ok?
if($this->error_reason)
$this->error();
// evtl. zusaetzlichen haeder
// aus email adresse und namen baseteln
if($this->from_email != "")
$this->setHeader("From: ".$this->from_name." <".$this->from_email).">";
// es gibt mehrere empfaenger
if(is_array($this->recipient))
{
for($cc = 0; $cc < count($this->recipient); $cc++)
mail($this->recipient[$cc], $this->subject, $this->message, $this->header, $this->additional);
}
// es gibt nur einen empfaenger
else
{
mail($this->recipient, $this->subject, $this->message, $this->header, $this->additional);
}
}
// -------------------------------------------------------------------
// private methods
// -------------------------------------------------------------------
private function error()
{
$error_msg = "Beim Mailversenden sind Fehler aufgetreten:
\n\n";
for($cc = 0; $cc < count($this->error_reason); $cc++)
$error_msg .= ($cc+1).". ".$this->error_reason[$cc]."
\n";
die($error_msg."\nterminated.\n");
}
}
?>