ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilMimeMail Class Reference

this class encapsulates the PHP mail() function. More...

+ Collaboration diagram for ilMimeMail:

Public Member Functions

 __construct ()
 Mail contructor.
 autoCheck ($bool)
 activate or desactivate the email addresses validator ex: autoCheck( true ) turn the validator on by default autoCheck feature is on
 Subject ($subject, $a_add_prefix=false)
 Define the subject line of the email.
 From ($from)
 set the sender of the mail
 ReplyTo ($address)
 set the Reply-to header
 Receipt ()
 add a receipt to the mail ie.
 To ($to)
 set the mail recipient
 Cc ($cc)
 Cc() cc : email address(es), accept both array and string.
 Bcc ($bcc)
 Bcc() set the Bcc headers ( blank carbon copy ).
 Body ($body, $charset="")
 Body( text [, charset] ) set the body (message) of the mail define the charset if the message contains extended characters (accents) default to us-ascii $mail->Body( "m�l en fran�ais avec des accents", "iso-8859-1" );.
 Organization ($org)
 Organization( $org ) set the Organization header.
 Priority ($priority)
 Priority( $priority ) set the mail priority $priority : integer taken between 1 (highest) and 5 ( lowest ) ex: $mail->Priority(1) ; => Highest.
 Attach ($filename, $filetype="", $disposition="inline", $display_name=null)
 Attach a file to the mail.
 BuildMail ()
 Build the email message public.
 Send ()
 fornat and send the mail public
 Get ()
 return the whole e-mail , headers + message can be used for displaying the message in plain text or logging it
 ValidEmail ($address)
 check an email address validity public
 CheckAdresses ($aad)
 check validity of email addresses return if unvalid, output an error message and exit, this may -should- be customized
 _build_attachement ()
 check and encode attach file(s) .
 _mimeEncode ($a_string)

Data Fields

 $sendto = array()
 $acc = array()
 $abcc = array()
 $aattach = array()
 $xheaders = array()
 $priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' )
 $charset = "utf-8"
 $ctencoding = "8bit"
 $receipt = 0

Detailed Description

this class encapsulates the PHP mail() function.

implements CC, Bcc, Priority headers include "libmail.php"; $m= new Mail; // create the mail $m->From( "leo@isp.com" ); $m->To( "destination@somewhere.fr" ); $m->Subject( "the subject of the mail" ); $message= "Hello world!\nthis is a test of the Mail class\nplease ignore\nThanks."; $m->Body( $message); // set the body $m->Cc( "someone@somewhere.fr"); $m->Bcc( "someoneelse@somewhere.fr"); $m->Priority(4) ; // set the priority to Low m->Attach( "/home/leo/toto.gif", "image/gif" ) ; // attach a file of type image/gif $m->Send(); // send the mail echo "the mail below has been sent:<br><pre>", $m->Get(), "</pre>";

Author
Leo West - lwest.nosp@m.@fre.nosp@m.e.fr
Version
Id:
class.ilMimeMail.php 55094 2014-11-13 11:05:21Z mjansen

Definition at line 26 of file class.ilMimeMail.php.

Constructor & Destructor Documentation

ilMimeMail::__construct ( )

Mail contructor.

Definition at line 74 of file class.ilMimeMail.php.

References autoCheck().

{
$this->autoCheck( false);
$this->boundary= "--" . md5( uniqid("myboundary") );
}

+ Here is the call graph for this function:

Member Function Documentation

ilMimeMail::_build_attachement ( )

check and encode attach file(s) .

internal use only private

Definition at line 425 of file class.ilMimeMail.php.

References $filename, and exit.

Referenced by BuildMail().

{
$this->xheaders["Content-Type"] = "multipart/mixed;\n boundary=\"$this->boundary\"";
$this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\n";
$this->fullBody .= "Content-Type: text/plain; charset=$this->charset\nContent-Transfer-Encoding: $this->ctencoding\n\n".
$this->body ."\n";
$sep= chr(13) . chr(10);
$ata= array();
$k=0;
// for each attached file, do...
for( $i=0; $i < count( $this->aattach); $i++ ) {
$filename = $this->aattach[$i];
$basename = basename($filename);
$ctype = $this->actype[$i]; // content-type
$disposition = $this->adispo[$i];
$display_name = $this->adisplay[$i];
if(!$display_name)
{
$display_name = $basename;
}
if( ! file_exists( $filename) ) {
echo "Class Mail, method attach : file $filename can't be found"; exit;
}
$subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$basename\"\nContent-Transfer-Encoding:".
"base64\nContent-Disposition: $disposition;\n filename=\"$display_name\"\n\n";
$ata[$k++] = $subhdr;
// non encoded line length
$linesz= filesize( $filename)+1;
$fp= fopen( $filename, 'r' );
$ata[$k++] = chunk_split(base64_encode(fread( $fp, $linesz)));
fclose($fp);
}
$this->fullBody .= implode($sep, $ata);
}

+ Here is the caller graph for this function:

ilMimeMail::_mimeEncode (   $a_string)

Definition at line 467 of file class.ilMimeMail.php.

Referenced by ilMail\addFullname(), ilMail\getIliasMailerAddress(), and Subject().

{
$encoded = '=?utf-8?b?';
$encoded .= base64_encode($a_string);
$encoded .= '?=';
return $encoded;
}

+ Here is the caller graph for this function:

ilMimeMail::Attach (   $filename,
  $filetype = "",
  $disposition = "inline",
  $display_name = null 
)

Attach a file to the mail.

Parameters
stringfilename : path of the file to attach
stringfiletype : MIME-type of the file. default to 'application/x-unknown-content-type'
stringdisposition : instruct the Mailclient to display the file if possible ("inline") or always as a link ("attachment") possible values are "inline", "attachment"
string$display_name,:filename to use in email (if different from source file)

Definition at line 285 of file class.ilMimeMail.php.

References $filename.

{
// TODO : si filetype="", alors chercher dans un tablo de MT connus / extension du fichier
if( $filetype == "" )
$filetype = "application/octet-stream";
$this->aattach[] = $filename;
$this->actype[] = $filetype;
$this->adispo[] = $disposition;
$this->adisplay[] = $display_name;
}
ilMimeMail::autoCheck (   $bool)

activate or desactivate the email addresses validator ex: autoCheck( true ) turn the validator on by default autoCheck feature is on

Parameters
booleanset to true to turn on the auto validation public

Definition at line 88 of file class.ilMimeMail.php.

Referenced by __construct().

{
if( $bool )
$this->checkAddress = true;
else
$this->checkAddress = false;
}

+ Here is the caller graph for this function:

ilMimeMail::Bcc (   $bcc)

Bcc() set the Bcc headers ( blank carbon copy ).

bcc : email address(es), accept both array and string

Parameters
stringbcc

Definition at line 209 of file class.ilMimeMail.php.

References CheckAdresses().

{
if( is_array($bcc) ) {
$this->abcc = $bcc;
} else {
$this->abcc[]= $bcc;
}
if( $this->checkAddress == true )
$this->CheckAdresses( $this->abcc );
}

+ Here is the call graph for this function:

ilMimeMail::Body (   $body,
  $charset = "" 
)

Body( text [, charset] ) set the body (message) of the mail define the charset if the message contains extended characters (accents) default to us-ascii $mail->Body( "m�l en fran�ais avec des accents", "iso-8859-1" );.

Parameters
stringbody
stringcharset (optional)

Definition at line 231 of file class.ilMimeMail.php.

References $charset.

{
$this->body = $body;
if( $charset != "" ) {
$this->charset = strtolower($charset);
if( $this->charset == "us-ascii" )
$this->ctencoding = "7bit";
}
}
ilMimeMail::BuildMail ( )

Build the email message public.

Definition at line 301 of file class.ilMimeMail.php.

References $ctencoding, and _build_attachement().

Referenced by Get(), and Send().

{
// build the headers
$this->headers = "";
// $this->xheaders['To'] = implode( ", ", $this->sendto );
if( count($this->acc) > 0 )
$this->xheaders['CC'] = implode( ", ", $this->acc );
if( count($this->abcc) > 0 )
$this->xheaders['BCC'] = implode( ", ", $this->abcc );
if( $this->receipt ) {
if( isset($this->xheaders["Reply-To"] ) )
$this->xheaders["Disposition-Notification-To"] = $this->xheaders["Reply-To"];
else
$this->xheaders["Disposition-Notification-To"] = $this->xheaders['From'];
}
if( $this->charset != "" ) {
$this->xheaders["Mime-Version"] = "1.0";
$this->xheaders["Content-Type"] = "text/plain; charset=$this->charset";
$this->xheaders["Content-Transfer-Encoding"] = $this->ctencoding;
}
$this->xheaders["X-Mailer"] = "Php/libMailv1.3";
// include attached files
if( count( $this->aattach ) > 0 ) {
} else {
$this->fullBody = $this->body;
}
reset($this->xheaders);
while( list( $hdr,$value ) = each( $this->xheaders ) ) {
if( $hdr != "Subject" )
$this->headers .= "$hdr: $value\n";
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilMimeMail::Cc (   $cc)

Cc() cc : email address(es), accept both array and string.

Parameters
stringcc set the CC headers ( carbon copy )

Definition at line 188 of file class.ilMimeMail.php.

References CheckAdresses().

{
if( is_array($cc) )
$this->acc= $cc;
else
$this->acc[]= $cc;
if( $this->checkAddress == true )
$this->CheckAdresses( $this->acc );
}

+ Here is the call graph for this function:

ilMimeMail::CheckAdresses (   $aad)

check validity of email addresses return if unvalid, output an error message and exit, this may -should- be customized

Parameters
arrayaad -

Definition at line 409 of file class.ilMimeMail.php.

References exit, and ValidEmail().

Referenced by Bcc(), Cc(), and To().

{
for($i=0;$i< count( $aad); $i++ ) {
if( ! $this->ValidEmail( $aad[$i]) ) {
echo "Class Mail, method Mail : invalid address $aad[$i]";
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilMimeMail::From (   $from)

set the sender of the mail

Parameters
stringfrom should be an email address

Definition at line 122 of file class.ilMimeMail.php.

References exit.

Referenced by ilPurchaseBaseGUI\__sendBill().

{
if( ! is_string($from) ) {
echo "Class Mail: error, From is not a string";
}
// base64_encode fullname but not email
$this->xheaders['From'] = $from;
}

+ Here is the caller graph for this function:

ilMimeMail::Get ( )

return the whole e-mail , headers + message can be used for displaying the message in plain text or logging it

Definition at line 374 of file class.ilMimeMail.php.

References BuildMail().

{
$this->BuildMail();
$mail = "To: " . $this->strTo . "\n";
$mail .= $this->headers . "\n";
$mail .= $this->fullBody;
return $mail;
}

+ Here is the call graph for this function:

ilMimeMail::Organization (   $org)

Organization( $org ) set the Organization header.

Parameters
stringorganization

Definition at line 248 of file class.ilMimeMail.php.

{
if( trim( $org != "" ) )
$this->xheaders['Organization'] = $org;
}
ilMimeMail::Priority (   $priority)

Priority( $priority ) set the mail priority $priority : integer taken between 1 (highest) and 5 ( lowest ) ex: $mail->Priority(1) ; => Highest.

Parameters
integerpriority

Definition at line 262 of file class.ilMimeMail.php.

{
if( ! intval( $priority ) )
return false;
if( ! isset( $this->priorities[$priority-1]) )
return false;
$this->xheaders["X-Priority"] = $this->priorities[$priority-1];
return true;
}
ilMimeMail::Receipt ( )

add a receipt to the mail ie.

a confirmation is returned to the "From" address (or "ReplyTo" if defined) when the receiver opens the message.

Warning
this functionality is not a standard, thus only some mail clients are compliants.

Definition at line 156 of file class.ilMimeMail.php.

{
$this->receipt = 1;
}
ilMimeMail::ReplyTo (   $address)

set the Reply-to header

Parameters
stringaddress should be an email address

Definition at line 139 of file class.ilMimeMail.php.

{
if( ! is_string($address) )
return false;
$this->xheaders["Reply-To"] = $address;
}
ilMimeMail::Send ( )

fornat and send the mail public

Definition at line 350 of file class.ilMimeMail.php.

References $ilSetting, $res, and BuildMail().

{
#global $ilLog;
global $ilSetting;
$this->BuildMail();
$this->strTo = implode( ", ", $this->sendto );
// envoie du mail
if(!(int)$ilSetting->get('prevent_smtp_globally'))
{
$res = @mail( $this->strTo, $this->xheaders['Subject'], $this->fullBody, $this->headers );
}
#$ilLog->write($this->strTo.' '. $this->xheaders['Subject'].' '. $this->fullBody.' '. $this->headers);
}

+ Here is the call graph for this function:

ilMimeMail::Subject (   $subject,
  $a_add_prefix = false 
)

Define the subject line of the email.

Parameters
stringsubject any monoline string

Definition at line 101 of file class.ilMimeMail.php.

References _mimeEncode(), and ilMail\getSubjectPrefix().

{
if($a_add_prefix)
{
// #9096
include_once "Services/Mail/classes/class.ilMail.php";
if(trim($prefix))
{
$subject = trim($prefix)." ".$subject;
}
}
$this->xheaders['Subject'] = ilMimeMail::_mimeEncode(strtr($subject,"\r\n"," "));
}

+ Here is the call graph for this function:

ilMimeMail::To (   $to)

set the mail recipient

Parameters
stringto email address, accept both a single address or an array of addresses

Definition at line 167 of file class.ilMimeMail.php.

References CheckAdresses().

{
// TODO : test validit� sur to
if( is_array( $to ) )
$this->sendto= $to;
else
$this->sendto[] = $to;
if( $this->checkAddress == true )
$this->CheckAdresses( $this->sendto );
}

+ Here is the call graph for this function:

ilMimeMail::ValidEmail (   $address)

check an email address validity public

Parameters
stringaddress : email address to check
Returns
boolean true if email adress is ok

Definition at line 391 of file class.ilMimeMail.php.

Referenced by CheckAdresses().

{
if( ereg( ".*<(.+)>", $address, $regs ) ) {
$address = $regs[1];
}
if(ereg( "^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$",$address) )
return true;
else
return false;
}

+ Here is the caller graph for this function:

Field Documentation

ilMimeMail::$aattach = array()

Definition at line 48 of file class.ilMimeMail.php.

ilMimeMail::$abcc = array()

Definition at line 42 of file class.ilMimeMail.php.

ilMimeMail::$acc = array()

Definition at line 37 of file class.ilMimeMail.php.

ilMimeMail::$charset = "utf-8"

Definition at line 66 of file class.ilMimeMail.php.

Referenced by Body().

ilMimeMail::$ctencoding = "8bit"

Definition at line 67 of file class.ilMimeMail.php.

Referenced by BuildMail().

ilMimeMail::$priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' )

Definition at line 60 of file class.ilMimeMail.php.

ilMimeMail::$receipt = 0

Definition at line 68 of file class.ilMimeMail.php.

ilMimeMail::$sendto = array()

Definition at line 32 of file class.ilMimeMail.php.

ilMimeMail::$xheaders = array()

Definition at line 54 of file class.ilMimeMail.php.


The documentation for this class was generated from the following file: