note 52071 deleted from function.mail by bjori
| From: | bjori@php.net | Date: | Tue, 05 Sep 2006 08:26:57 +0000 |
| Subject: | note 52071 deleted from function.mail by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-116679@lists.php.net to get a copy of this message | ||
Note Submitter: Jeffrey
----
<?php
class clsMail
{
var $to;
var $from;
var $cc;
var $bcc;
var $subject;
var $message;
var $contentType;
function clsMail() //init
{
$this->to = "";
$this->from = "";
$this->cc = "";
$this->bcc = "";
$this->subject = "";
$this->message = "";
$this->contentType = "html"; // text, html
}
function isemail($email)
{
// regx to test for valid e-mail adres
$regex = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$';
if (eregi($regex, $email)) return true;
else return false;
}
function send()
{
// check if e-mail adresses are valid.
if (!clsMail::isemail($this->to)) die('ERROR: Invalid To e-mail adres');
if (!clsMail::isemail($this->from)) die('ERROR: Invalid From e-mail adres');
if (!clsMail::isemail($this->cc) && !$this->cc=="") die('ERROR:
Invalid CC e-mail adres');
if (!clsMail::isemail($this->bcc) && !$this->bcc=="") die('ERROR:
Invalid BCC e-mail adres');
// To send HTML mail, you can set the Content-type header. html is the default
$headers = "MIME-Version: 1.0\r\n";
if ($this->contentType=="html") $headers .= "Content-type: text/html;
charset=iso-8859-1\r\n";
else $headers .= "Content-type: text/plain; charset=us-ascii\r\n";
// additional headers for From, Cc and Bcc
$headers .= "From: ".$this->from."\r\n";
if (!$this->cc=="") $headers .= "Cc: ".$this->cc."\r\n";
if (!$this->bcc=="") $headers .= "Bcc: ".$this->bcc."\r\n";
// send the e-mail
return mail($this->to, $this->subject, $this->message, $headers);
}
}
// example how te use the mail class
$mail = new clsMail();
$mail->to="someone@domain.com";
$mail->from="me@domain.com";
$mail->subject="My Subject";
$mail->message="My Message body";
echo $mail->send(); // returns true or false at failure
?>