ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilMimeMail Class Reference

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

+ Collaboration diagram for ilMimeMail:

Public Member Functions

 __construct ()
 Mail contructor. More...
 
 autoCheck ($bool)
 activate or desactivate the email addresses validator ex: autoCheck( true ) turn the validator on by default autoCheck feature is on More...
 
 Subject ($subject, $a_add_prefix=false)
 Define the subject line of the email. More...
 
 From ($from)
 set the sender of the mail More...
 
 ReplyTo ( $address)
 set the Reply-to header More...
 
 Receipt ()
 add a receipt to the mail ie. More...
 
 To ( $to)
 set the mail recipient More...
 
 Cc ($cc)
 Cc() cc : email address(es), accept both array and string. More...
 
 Bcc ( $bcc)
 Bcc() set the Bcc headers ( blank carbon copy ). More...
 
 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" );. More...
 
 Organization ( $org)
 Organization( $org ) set the Organization header. More...
 
 Priority ( $priority)
 Priority( $priority ) set the mail priority $priority : integer taken between 1 (highest) and 5 ( lowest ) ex: $mail->Priority(1) ; => Highest. More...
 
 Attach ( $filename, $filetype="", $disposition="inline", $display_name=null)
 Attach a file to the mail. More...
 
 Send ()
 fornat and send the mail public More...
 
 Get ()
 return the whole e-mail , headers + message can be used for displaying the message in plain text or logging it More...
 
 ValidEmail ($address)
 check an email address validity public More...
 
 CheckAdresses ( $aad)
 check validity of email addresses return if unvalid, output an error message and exit, this may -should- be customized More...
 
 _build_attachement ()
 check and encode attach file(s) . More...
 

Static Public Member Functions

static _mimeEncode ($a_string)
 

Data Fields

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

Protected Attributes

 $aattach = array()
 
 $adisplay = array()
 

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 46278 2013-11-19 13:27:05Z jluetzen

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

Constructor & Destructor Documentation

◆ __construct()

ilMimeMail::__construct ( )

Mail contructor.

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

References autoCheck().

81  {
82  $this->autoCheck( false);
83  $this->boundary= "--" . md5( uniqid("myboundary") );
84  }
autoCheck($bool)
activate or desactivate the email addresses validator ex: autoCheck( true ) turn the validator on by ...
+ Here is the call graph for this function:

Member Function Documentation

◆ _build_attachement()

ilMimeMail::_build_attachement ( )

check and encode attach file(s) .

internal use only private

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

References $filename, array, and exit.

561  {
562  $this->xheaders["Content-Type"] = "multipart/mixed;\n boundary=\"$this->boundary\"";
563 
564  $this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\n";
565  $this->fullBody .= "Content-Type: text/plain; charset=$this->charset\nContent-Transfer-Encoding: $this->ctencoding\n\n".
566  $this->body ."\n";
567 
568  $sep= chr(13) . chr(10);
569 
570  $ata= array();
571  $k=0;
572 
573  // for each attached file, do...
574  for( $i=0; $i < count( $this->aattach); $i++ ) {
575 
576  $filename = $this->aattach[$i];
577  $basename = basename($filename);
578  $ctype = $this->actype[$i]; // content-type
579  $disposition = $this->adispo[$i];
580  $display_name = $this->adisplay[$i];
581  if(!$display_name)
582  {
583  $display_name = $basename;
584  }
585 
586  if( ! file_exists( $filename) ) {
587  echo "Class Mail, method attach : file $filename can't be found";
588  exit;
589  }
590 
591  $subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$basename\"\nContent-Transfer-Encoding:".
592  "base64\nContent-Disposition: $disposition;\n filename=\"$display_name\"\n\n";
593  $ata[$k++] = $subhdr;
594  // non encoded line length
595  $linesz= filesize( $filename)+1;
596  $fp= fopen( $filename, 'r' );
597  $ata[$k++] = chunk_split(base64_encode(fread( $fp, $linesz)));
598  fclose($fp);
599  }
600 
601  $this->fullBody .= implode($sep, $ata);
602  }
Create styles array
The data for the language used.

◆ _mimeEncode()

static ilMimeMail::_mimeEncode (   $a_string)
static

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

605  {
606  $encoded = '=?utf-8?b?';
607  $encoded .= base64_encode($a_string);
608  $encoded .= '?=';
609 
610  return $encoded;
611  }

◆ Attach()

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 304 of file class.ilMimeMail.php.

References $filename, $files, $ilSetting, $ilUser, $result, array, ilLoggerFactory\getLogger(), and ilUtil\makeClickable().

305  {
306  // TODO : si filetype="", alors chercher dans un tablo de MT connus / extension du fichier
307  if( $filetype == "" )
308  {
309  $filetype = "application/octet-stream";
310  }
311 
312  $this->aattach[] = $filename;
313  $this->actype[] = $filetype;
314  $this->adispo[] = $disposition;
315  $this->adisplay[] = $display_name;
316  }
+ Here is the call graph for this function:

◆ autoCheck()

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
Deprecated:

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

Referenced by __construct().

95  {
96  if( $bool )
97  {
98  $this->checkAddress = true;
99  }
100  else
101  {
102  $this->checkAddress = false;
103  }
104  }
+ Here is the caller graph for this function:

◆ Bcc()

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 220 of file class.ilMimeMail.php.

References CheckAdresses().

221  {
222  if( is_array($bcc) )
223  {
224  $this->abcc = $bcc;
225  }
226  else
227  {
228  $this->abcc[]= $bcc;
229  }
230 
231  if( $this->checkAddress == true )
232  {
233  $this->CheckAdresses( $this->abcc );
234  }
235  }
CheckAdresses( $aad)
check validity of email addresses return if unvalid, output an error message and exit, this may -should- be customized
+ Here is the call graph for this function:

◆ Body()

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 246 of file class.ilMimeMail.php.

247  {
248  $this->body = $body;
249 
250  if( $charset != "" )
251  {
252  $this->charset = strtolower($charset);
253  if( $this->charset == "us-ascii" )
254  {
255  $this->ctencoding = "7bit";
256  }
257  }
258  }

◆ Cc()

ilMimeMail::Cc (   $cc)

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

Parameters
stringcc set the CC headers ( carbon copy )

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

References CheckAdresses().

198  {
199  if( is_array($cc) )
200  {
201  $this->acc= $cc;
202  }
203  else
204  {
205  $this->acc[]= $cc;
206  }
207 
208  if( $this->checkAddress == true )
209  {
210  $this->CheckAdresses( $this->acc );
211  }
212  }
CheckAdresses( $aad)
check validity of email addresses return if unvalid, output an error message and exit, this may -should- be customized
+ Here is the call graph for this function:

◆ CheckAdresses()

ilMimeMail::CheckAdresses (   $aad)

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

Parameters
arrayaad -
Deprecated:

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

References exit, and ValidEmail().

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

546  {
547  for($i=0;$i< count( $aad); $i++ ) {
548  if( ! $this->ValidEmail( $aad[$i]) )
549  {
550  echo "Class Mail, method Mail : invalid address $aad[$i]";
551  exit;
552  }
553  }
554  }
ValidEmail($address)
check an email address validity public
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ From()

ilMimeMail::From (   $from)

set the sender of the mail

Parameters
stringfrom should be an email address

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

References exit.

130  {
131  if( ! is_string($from) && !is_array($from)) {
132  echo "Class Mail: error, From is not a string or array";
133  exit;
134  }
135  if(is_array($from))
136  {
137  $this->xheaders['From'] = $from[0];
138  $this->xheaders['FromName'] = $from[1];
139  return;
140  }
141 
142  $this->xheaders['From'] = $from;
143  }

◆ Get()

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 504 of file class.ilMimeMail.php.

505  {
506  $this->BuildMail();
507  $mail = "To: " . $this->strTo . "\n";
508  $mail .= $this->headers . "\n";
509  $mail .= $this->fullBody;
510  return $mail;
511  }

◆ Organization()

ilMimeMail::Organization (   $org)

Organization( $org ) set the Organization header.

Parameters
stringorganization

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

266  {
267  if( trim( $org != "" ) )
268  {
269  $this->xheaders['Organization'] = $org;
270  }
271  }

◆ Priority()

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 280 of file class.ilMimeMail.php.

281  {
282  if( ! intval( $priority ) )
283  {
284  return false;
285  }
286 
287  if( ! isset( $this->priorities[$priority-1]) )
288  {
289  return false;
290  }
291 
292  $this->xheaders["X-Priority"] = $this->priorities[$priority-1];
293 
294  return true;
295  }

◆ Receipt()

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 164 of file class.ilMimeMail.php.

165  {
166  $this->receipt = 1;
167  }

◆ ReplyTo()

ilMimeMail::ReplyTo (   $address)

set the Reply-to header

Parameters
stringaddress should be an email address

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

150  {
151  if( ! is_string($address) )
152  {
153  return false;
154  }
155 
156  $this->xheaders["Reply-To"] = $address;
157  }

◆ Send()

ilMimeMail::Send ( )

fornat and send the mail public

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

496  {
497  $this->BuildMail();
498  }

◆ Subject()

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

Define the subject line of the email.

Parameters
stringsubject any monoline string

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

111  {
112  if($a_add_prefix)
113  {
114  // #9096
115  include_once "Services/Mail/classes/class.ilMail.php";
116  $prefix = ilMail::getSubjectPrefix();
117  if(trim($prefix))
118  {
119  $subject = trim($prefix)." ".$subject;
120  }
121  }
122  $this->xheaders['Subject'] = $subject;
123  }

◆ To()

ilMimeMail::To (   $to)

set the mail recipient

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

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

References CheckAdresses().

174  {
175  // TODO : test validit� sur to
176  if( is_array( $to ) )
177  {
178  $this->sendto= $to;
179  }
180  else
181  {
182  $this->sendto[] = $to;
183  }
184 
185  if( $this->checkAddress == true )
186  {
187  $this->CheckAdresses( $this->sendto );
188  }
189  }
CheckAdresses( $aad)
check validity of email addresses return if unvalid, output an error message and exit, this may -should- be customized
+ Here is the call graph for this function:

◆ ValidEmail()

ilMimeMail::ValidEmail (   $address)

check an email address validity public

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

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

References array.

Referenced by CheckAdresses().

522  {
523  $regs = array();
524  if(preg_match("/.*<(.+)>/", $address, $regs))
525  {
526  $address = $regs[1];
527  }
528 
529  if(preg_match('/^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)$/', $address))
530  {
531  return true;
532  }
533  else
534  {
535  return false;
536  }
537  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

Field Documentation

◆ $aattach

ilMimeMail::$aattach = array()
protected

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

◆ $abcc

ilMimeMail::$abcc = array()

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

◆ $acc

ilMimeMail::$acc = array()

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

◆ $adisplay

ilMimeMail::$adisplay = array()
protected

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

◆ $charset

ilMimeMail::$charset = "utf-8"

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

◆ $ctencoding

ilMimeMail::$ctencoding = "8bit"

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

◆ $priorities

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

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

◆ $receipt

ilMimeMail::$receipt = 0

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

◆ $sendto

ilMimeMail::$sendto = array()

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

◆ $xheaders

ilMimeMail::$xheaders = array()

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


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