|
|
|
<?
/*
* email.php3
*
* @(#) $Header: /cvsroot/enanet/email.php3,v 1.6 1998/05/18 15:57:17 mlemos Exp $
*
* E na Net service
*
* This information is CONFIDENTIAL and PROPRIETARY
* (C) Copyright Manuel Lemos. All Rights Reserved.
*
* $Log: email.php3,v $
* Revision 1.6 1998/05/18 15:57:17 mlemos
* Added an instance variable to hold the number of added message parts.
* Added the method AddBodyPreEncodedText.
* Made the first body part be directly assigned to the body variable in the
* Send method.
*
* Revision 1.5 1998/05/17 23:10:49 mlemos
* Fixed bug in EmailEncodeQuotedPrintable function of skipping contiguous
* whitespaces.
* Made EmailEncodeQuotedPrintable function not break lines when Q-encoding
* header text.
* Made all methods return an empty string as success code.
* Added the method ResetBody to email_message class to clear the body data
* array.
*
* Revision 1.4 1998/05/15 18:36:33 mlemos
* Made the spaces in the headers be encoded as underscore for better
* readability.
* Turned the statement that actually sends the message into the class method
* SendMail to be easily overridable by any subclass.
*
* Revision 1.3 1998/05/14 22:05:49 mlemos
* Fixed the error messages returned from the send method regarding mandatory
* missing headers.
*
* Revision 1.2 1998/05/11 23:02:25 mlemos
* Added the function to validate an e-mail address.
*
* Revision 1.1 1998/05/11 17:47:50 mlemos
* Initial revision.
*
*
*
*/
Function EmailValidateAddress($address)
{
return(ereg( "^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$",$address));
}
$default_email_charset= "iso-8859-1";
Function EmailEncodeQuotedPrintable($text,$header_charset)
{
$length=strlen($text);
for($whitespace= "",$line=0,$encode= "",$index=0;$index<$length;$index++)
{
$character=substr($text,$index,1);
$order=Ord($character);
$encode=0;
switch($order)
{
case 9:
case 32:
if($header_charset== "")
{
$previous_whitespace=$whitespace;
$whitespace=$character;
$character= "";
}
else
{
if($order==32)
$character= "_";
else
$encode=1;
}
break;
case 10:
case 13:
if($whitespace!= "")
{
if($header_charset== ""
&& $line+3>75)
{
$encoded.= "=\n";
$line=0;
}
$encoded.=sprintf( "=%02X",Ord($whitespace));
$line+=3;
$whitespace= "";
}
$encoded.=$character;
$line=0;
continue 2;
default:
if($order>127
|| $order<32
|| $character== "="
|| ($header_charset!= ""
&& ($character== "?"
|| $character== "_"
|| $character== "("
|| $character== ")")))
$encode=1;
break;
}
if($whitespace!= "")
{
if($header_charset== ""
&& $line+1>75)
{
$encoded.= "=\n";
$line=0;
}
$encoded.=$whitespace;
$line++;
$whitespace= "";
}
if($character!= "")
{
if($encode)
{
$character=sprintf( "=%02X",$order);
$encoded_length=3;
}
else
$encoded_length=1;
if($header_charset== ""
&& $line+$encoded_length>75)
{
$encoded.= "=\n";
$line=0;
}
$encoded.=$character;
$line+=$encoded_length;
}
}
if($whitespace!= "")
{
if($header_charset== ""
&& $line+3>75)
$encoded.= "=\n";
$encoded.=sprintf( "=%02X",Ord($whitespace));
}
if($header_charset!= ""
&& $text!=$encoded)
return( "=?$header_charset?q?$encoded?=");
else
return($encoded);
}
Function EmailEncodeAddress($address,$name,$header_charset)
{
global $default_email_charset;
if($header_charset== "")
$header_charset=$default_email_charset;
return( "$address (".EmailEncodeQuotedPrintable($name,$header_charset). ")");
}
class email_message
{
var $mailer= "";
var $default_charset=$default_email_charset;
var $headers=array( "To"=> "", "Subject"=> "");
var $body=array();
var $parts=0;
Function SetHeader($header,$value)
{
$this->headers[ "$header"]= "$value";
return( "");
}
Function AddBodyText($text)
{
$this->body[$this->parts][ "CONTENTS"]=$text;
$this->body[$this->parts][ "TYPE"]= "TEXT";
$this->parts++;
return( "");
}
Function AddBodyEncodedText($text)
{
$this->body[$this->parts][ "CONTENTS"]=EmailEncodeQuotedPrintable($text, "");
$this->body[$this->parts][ "TYPE"]= "ENCODED_TEXT";
$this->body[$this->parts][ "CHARSET"]=$this->default_charset;
$this->parts++;
return( "");
}
Function AddBodyPreEncodedText($text)
{
$this->body[$this->parts][ "CONTENTS"]=$text;
$this->body[$this->parts][ "TYPE"]= "ENCODED_TEXT";
$this->body[$this->parts][ "CHARSET"]=$this->default_charset;
$this->parts++;
return( "");
}
Function Send()
{
if(!IsSet($this->headers[ "To"])
|| $this->headers[ "To"]== "")
return( "the header To: was not defined");
if(!IsSet($this->headers[ "Subject"])
|| $this->headers[ "Subject"]== "")
return( "the header Subject: was not defined");
for($charset=$body= "",$part=0;$part<$this->parts;$part++)
{
if($part>0)
return( "multipart mails are not yet supported");
switch($this->body[$part][ "TYPE"])
{
case "TEXT":
if($body== "")
$body=$this->body[$part][ "CONTENTS"];
else
$body.=$this->body[$part][ "CONTENTS"];
break;
case "ENCODED_TEXT":
if($body== "")
$body=$this->body[$part][ "CONTENTS"];
else
$body.=$this->body[$part][ "CONTENTS"];
$charset=$this->body[$part][ "CHARSET"];
break;
}
}
for($header=0,$headers= "",Reset($this->headers);$header<count($this->headers);Next($this->headers),$header++)
{
switch(Key($this->headers))
{
case "To":
case "Subject":
break;
default:
$headers.=Key($this->headers). ": ".$this->headers[Key($this->headers)]. "\n";
break;
}
}
if($this->mailer!= "")
$headers.= "X-Mailer: $this->mailer";
if($charset!= "")
$headers.= "MIME-Version: 1.0\nContent-Type: text/plain; charset=$charset\nContent-Transfer-Encoding: quoted-
printable\n";
return($this->SendMail($this->headers[ "To"],EmailEncodeQuotedPrintable($this->headers[ "Subject"],$this-
>default_charset),&$body,$headers));
}
Function SendMail($to,$subject,$body,$headers)
{
mail($to,$subject,&$body,$headers);
return( "");
}
Function ResetBody()
{
$this->body=array();
return( "");
}
};
?> |
|
| Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip Categories : Email, Network, PHP, PHP Classes | | | Class that allows the PHP developer to establish connections with a POP3 mail server amd be able to list, retrieve and delete mail messages from a given mail box.
Categories : Network, Email, PHP, PHP Classes | | | Client classes for Dictionary servers UPDATED: 2000-06-06 Categories : Network, Search, Complete Programs, PHP Classes, PHP | | | Validator - A PHP class that can can be used for validating Email IDs and Dates Categories : PHP, PHP Classes, Data Validation, Email, Date Time | | | Three Cool Classes and One Trick Categories : PHP, PHP Classes, Graphics, Email | | | Sample usage of IPv6 and IPv4 with PHP Categories : PHP, PHP Classes, Network | | | PHP MIME Decoder. This class decodes Mime Encoded email message.
Attachments are stored in a director. Works with Multipart/alternative,
multipart/mixed etc.
see http://p3mail.com for example. Categories : PHP, PHP Classes, Email | | | An email validation script that actually checks against the recipient's mail server. Categories : Email, Complete Programs, PHP, Network, Debugging | | | cPanel Email Accounts Creator Categories : PHP, PHP Classes, Email, Form Processing, Web Services | | | base class to query the whois database Categories : Network, PHP, PHP Classes | | | A class for sending email; it has support for To:, Cc:, Bcc: and Reply-To:
headers. It requires that you have sendmail installed. Categories : Email, PHP Classes, PHP | | | POP3 Class Categories : PHP Classes, PHP, Email | | | very simple ftp class Categories : PHP, PHP Classes, FTP | | | PHP Paypal IPN Integration Class v1.0.0 Categories : PHP, PHP Classes, Payment Gateways | | | email new items in db Categories : PHP, Email, Databases, MySQL, Beginner Guides | |
|
|
|