ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 @access 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 @access 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...
 
 _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.

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 ...

References autoCheck().

+ 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 @access private

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

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

References $filename, and exit.

◆ _mimeEncode()

ilMimeMail::_mimeEncode (   $a_string)

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

599 {
600 $encoded = '=?utf-8?b?';
601 $encoded .= base64_encode($a_string);
602 $encoded .= '?=';
603
604 return $encoded;
605 }

Referenced by ilMail\addFullname().

+ Here is the caller graph for this function:

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

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

References $filename.

◆ 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 @access public

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

94 {
95 if( $bool )
96 {
97 $this->checkAddress = true;
98 }
99 else
100 {
101 $this->checkAddress = false;
102 }
103 }

Referenced by __construct().

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

220 {
221 if( is_array($bcc) )
222 {
223 $this->abcc = $bcc;
224 }
225 else
226 {
227 $this->abcc[]= $bcc;
228 }
229
230 if( $this->checkAddress == true )
231 {
232 $this->CheckAdresses( $this->abcc );
233 }
234 }
CheckAdresses( $aad)
check validity of email addresses return if unvalid, output an error message and exit,...

References CheckAdresses().

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

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

References $charset.

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

197 {
198 if( is_array($cc) )
199 {
200 $this->acc= $cc;
201 }
202 else
203 {
204 $this->acc[]= $cc;
205 }
206
207 if( $this->checkAddress == true )
208 {
209 $this->CheckAdresses( $this->acc );
210 }
211 }

References CheckAdresses().

+ 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 -

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

540 {
541 for($i=0;$i< count( $aad); $i++ ) {
542 if( ! $this->ValidEmail( $aad[$i]) )
543 {
544 echo "Class Mail, method Mail : invalid address $aad[$i]";
545 exit;
546 }
547 }
548 }
ValidEmail($address)
check an email address validity @access public

References exit, and ValidEmail().

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

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

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

References exit.

Referenced by ilPurchaseBaseGUI\__sendBill().

+ Here is the caller graph for this function:

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

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

◆ Organization()

ilMimeMail::Organization (   $org)

Organization( $org ) set the Organization header.

Parameters
stringorganization

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

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

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

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

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

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

◆ ReplyTo()

ilMimeMail::ReplyTo (   $address)

set the Reply-to header

Parameters
stringaddress should be an email address

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

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

◆ Send()

ilMimeMail::Send ( )

fornat and send the mail @access public

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

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

◆ Subject()

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

Define the subject line of the email.

Parameters
stringsubject any monoline string

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

110 {
111 if($a_add_prefix)
112 {
113 // #9096
114 include_once "Services/Mail/classes/class.ilMail.php";
115 $prefix = ilMail::getSubjectPrefix();
116 if(trim($prefix))
117 {
118 $subject = trim($prefix)." ".$subject;
119 }
120 }
121 $this->xheaders['Subject'] = $subject;
122 }
static getSubjectPrefix()
Get text that will be prepended to auto generated mails.

References ilMail\getSubjectPrefix().

+ Here is the call graph for this function:

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

173 {
174 // TODO : test validit� sur to
175 if( is_array( $to ) )
176 {
177 $this->sendto= $to;
178 }
179 else
180 {
181 $this->sendto[] = $to;
182 }
183
184 if( $this->checkAddress == true )
185 {
186 $this->CheckAdresses( $this->sendto );
187 }
188 }

References CheckAdresses().

+ Here is the call graph for this function:

◆ ValidEmail()

ilMimeMail::ValidEmail (   $address)

check an email address validity @access public

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

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

520 {
521 if( ereg( ".*<(.+)>", $address, $regs ) ) {
522 $address = $regs[1];
523 }
524 if(ereg( "^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$",$address) )
525 {
526 return true;
527 }
528 else
529 {
530 return false;
531 }
532 }

Referenced by CheckAdresses().

+ 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.

Referenced by Body().

◆ $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: