< – Inhaltsverzeichnis
FW_Mail: was soll man dazu noch sagen….
/** (c) 2010 Arne "w13531" Wenzel [ mailto: w13531 (at) terrorhippiecrew (dot) net ] **/
class FW_Mail extends FW_Object {
private $to = array();
private $from = null;
private $subject = null;
private $body = null;
private $headers = array();
/**
* constructor
**/
public function __construct($to, $from, $subject, $body) {
if(is_array($to)) {
$this->to = $to;
} else {
$this->to[] = $to;
}
$this->from = $from;
$this->subject = $subject;
$this->body = wordwrap($body, 70);
}
/**
* sends an email with the given data
**/
public function send(){
$this->addHeader('From', $this->from);
$this->addHeader('Reply-To', $this->from);
$this->addHeader('Return-Path', $this->from);
$this->addHeader('X-mailer:', 'RIAD-F Mail System');
foreach($this->headers as $key => $value) {
$header .= $key . ': ' . $value . "\n";
}
foreach($this->to as $value) {
if($this->valid_email($value)) {
mail($value, $this->subject, $this->body, $header);
}
}
}
/**
* add custom header
**/
public function addHeader($name, $value){
$this->headers[$name] = $value;
}
/**
* validates email addresses
* @return bool
**/
public function valid_email($email){
$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
$atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
$quoted_pair = '\\x5c[\\x00-\\x7f]';
$domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
$quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
$domain_ref = $atom;
$sub_domain = "($domain_ref|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(\\x2e$sub_domain)*";
$local_part = "$word(\\x2e$word)*";
$addr_spec = "$local_part\\x40$domain";
return preg_match("!^$addr_spec$!", $email) ? true : false;
}
}