Public Member Functions | |
ilMimeMail () | |
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) | |
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") | |
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 = "7bit" | |
$receipt = 0 |
Definition at line 48 of file class.ilMimeMail.php.
ilMimeMail::_build_attachement | ( | ) |
check and encode attach file(s) .
internal use only private
Definition at line 432 of file class.ilMimeMail.php.
References 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]; 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=\"$basename\"\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); }
ilMimeMail::_mimeEncode | ( | $ | a_string | ) |
Definition at line 469 of file class.ilMimeMail.php.
Referenced by ilMail::addFullname(), and Subject().
{ $encoded = '=?utf-8?b?'; $encoded .= base64_encode($a_string); $encoded .= '?='; return $encoded; }
ilMimeMail::Attach | ( | $ | filename, | |
$ | filetype = "" , |
|||
$ | disposition = "inline" | |||
) |
Attach a file to the mail.
string | filename : path of the file to attach | |
string | filetype : MIME-type of the file. default to 'application/x-unknown-content-type' | |
string | disposition : instruct the Mailclient to display the file if possible ("inline") or always as a link ("attachment") possible values are "inline", "attachment" |
Definition at line 297 of file class.ilMimeMail.php.
{ // TODO : si filetype="", alors chercher dans un tablo de MT connus / extension du fichier if( $filetype == "" ) $filetype = "application/x-unknown-content-type"; $this->aattach[] = $filename; $this->actype[] = $filetype; $this->adispo[] = $disposition; }
ilMimeMail::autoCheck | ( | $ | bool | ) |
activate or desactivate the email addresses validator ex: autoCheck( true ) turn the validator on by default autoCheck feature is on
boolean | set to true to turn on the auto validation public |
Definition at line 111 of file class.ilMimeMail.php.
Referenced by ilMimeMail().
{ if( $bool ) $this->checkAddress = true; else $this->checkAddress = false; }
ilMimeMail::Bcc | ( | $ | bcc | ) |
Bcc() set the Bcc headers ( blank carbon copy ).
bcc : email address(es), accept both array and string
string | bcc |
Definition at line 222 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 ); }
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" );.
string | body | |
string | charset (optional) |
Definition at line 244 of file class.ilMimeMail.php.
References $charset.
ilMimeMail::BuildMail | ( | ) |
Build the email message public.
Definition at line 312 of file class.ilMimeMail.php.
References _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 ) { $this->_build_attachement(); } else { $this->fullBody = $this->body; } reset($this->xheaders); while( list( $hdr,$value ) = each( $this->xheaders ) ) { if( $hdr != "Subject" ) $this->headers .= "$hdr: $value\n"; } }
ilMimeMail::Cc | ( | $ | cc | ) |
Cc() cc : email address(es), accept both array and string.
string | cc set the CC headers ( carbon copy ) |
Definition at line 201 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 ); }
ilMimeMail::CheckAdresses | ( | $ | aad | ) |
check validity of email addresses return if unvalid, output an error message and exit, this may -should- be customized
array | aad - |
Definition at line 416 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]"; exit; } } }
ilMimeMail::From | ( | $ | from | ) |
set the sender of the mail
string | from should be an email address |
Definition at line 135 of file class.ilMimeMail.php.
References exit.
{ if( ! is_string($from) ) { echo "Class Mail: error, From is not a string"; exit; } // base64_encode fullname but not email $this->xheaders['From'] = $from; }
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 381 of file class.ilMimeMail.php.
References BuildMail().
{ $this->BuildMail(); $mail = "To: " . $this->strTo . "\n"; $mail .= $this->headers . "\n"; $mail .= $this->fullBody; return $mail; }
ilMimeMail::ilMimeMail | ( | ) |
Mail contructor.
Definition at line 97 of file class.ilMimeMail.php.
References autoCheck().
{ $this->autoCheck( false); $this->boundary= "--" . md5( uniqid("myboundary") ); }
ilMimeMail::Organization | ( | $ | org | ) |
Organization( $org ) set the Organization header.
string | organization |
Definition at line 261 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.
integer | priority |
Definition at line 275 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.
Definition at line 169 of file class.ilMimeMail.php.
{ $this->receipt = 1; }
ilMimeMail::ReplyTo | ( | $ | address | ) |
set the Reply-to header
string | address should be an email address |
Definition at line 152 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 361 of file class.ilMimeMail.php.
References $res, and BuildMail().
{ #global $ilLog; $this->BuildMail(); $this->strTo = implode( ", ", $this->sendto ); // envoie du mail $res = @mail( $this->strTo, $this->xheaders['Subject'], $this->fullBody, $this->headers ); #$ilLog->write($this->strTo.' '. $this->xheaders['Subject'].' '. $this->fullBody.' '. $this->headers); }
ilMimeMail::Subject | ( | $ | subject | ) |
Define the subject line of the email.
string | subject any monoline string |
Definition at line 124 of file class.ilMimeMail.php.
References _mimeEncode().
{ $this->xheaders['Subject'] = ilMimeMail::_mimeEncode(strtr($subject,"\r\n"," ")); }
ilMimeMail::To | ( | $ | to | ) |
set the mail recipient
string | to email address, accept both a single address or an array of addresses |
Definition at line 180 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 ); }
ilMimeMail::ValidEmail | ( | $ | address | ) |
check an email address validity public
string | address : email address to check |
Definition at line 398 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; }
ilMimeMail::$aattach = array() |
Definition at line 70 of file class.ilMimeMail.php.
ilMimeMail::$abcc = array() |
Definition at line 64 of file class.ilMimeMail.php.
ilMimeMail::$acc = array() |
Definition at line 59 of file class.ilMimeMail.php.
ilMimeMail::$charset = "utf-8" |
Definition at line 88 of file class.ilMimeMail.php.
Referenced by Body().
ilMimeMail::$ctencoding = "7bit" |
Definition at line 89 of file class.ilMimeMail.php.
ilMimeMail::$priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' ) |
Definition at line 82 of file class.ilMimeMail.php.
ilMimeMail::$receipt = 0 |
Definition at line 90 of file class.ilMimeMail.php.
ilMimeMail::$sendto = array() |
Definition at line 54 of file class.ilMimeMail.php.
ilMimeMail::$xheaders = array() |
Definition at line 76 of file class.ilMimeMail.php.