PHPMailer Class Reference

List of all members.

Public Member Functions

  • __construct ($exceptions=false)
    Constructor.
  • IsHTML ($ishtml=true)
    Sets message type to HTML.
  • IsSMTP ()
    Sets Mailer to send message using SMTP.
  • IsMail ()
    Sets Mailer to send message using PHP mail() function.
  • IsSendmail ()
    Sets Mailer to send message using the $Sendmail program.
  • IsQmail ()
    Sets Mailer to send message using the qmail MTA.
  • AddAddress ($address, $name= '')
    Adds a "To" address.
  • AddCC ($address, $name= '')
    Adds a "Cc" address.
  • AddBCC ($address, $name= '')
    Adds a "Bcc" address.
  • AddReplyTo ($address, $name= '')
    Adds a "Reply-to" address.
  • SetFrom ($address, $name= '', $auto=1)
    Set the From and FromName properties.
  • Send ()
    Creates message and assigns Mailer.
  • SmtpConnect ()
    Initiates a connection to an SMTP server.
  • SmtpClose ()
    Closes the active SMTP session if one exists.
  • SetLanguage ($langcode= 'en', $lang_path= 'language/')
    Sets the language for all class error messages.
  • GetTranslations ()
    Return the current array of language strings.
  • AddrAppend ($type, $addr)
    Creates recipient headers.
  • AddrFormat ($addr)
    Formats an address correctly.
  • WrapText ($message, $length, $qp_mode=false)
    Wraps message for use with mailers that do not automatically perform wrapping and for quoted-printable.
  • UTF8CharBoundary ($encodedText, $maxLength)
    Finds last character boundary prior to maxLength in a utf-8 quoted (printable) encoded string.
  • SetWordWrap ()
    Set the body wrapping.
  • CreateHeader ()
    Assembles message header.
  • GetMailMIME ()
    Returns the message MIME.
  • CreateBody ()
    Assembles the message body.
  • HeaderLine ($name, $value)
    Returns a formatted header line.
  • TextLine ($value)
    Returns a formatted mail line.
  • AddAttachment ($path, $name= '', $encoding= 'base64', $type= 'application/octet-stream')
    Adds an attachment from a path on the filesystem.
  • GetAttachments ()
    Return the current array of attachments.
  • EncodeString ($str, $encoding= 'base64')
    Encodes string to requested format.
  • EncodeHeader ($str, $position= 'text')
    Encode a header string to best (shortest) of Q, B, quoted or none.
  • HasMultiBytes ($str)
    Checks if a string contains multibyte characters.
  • Base64EncodeWrapMB ($str)
    Correctly encodes and wraps long multibyte strings for mail headers without breaking lines within a character.
  • EncodeQPphp ($input= '', $line_max=76, $space_conv=false)
    Encode string to quoted-printable.
  • EncodeQP ($string, $line_max=76, $space_conv=false)
    Encode string to RFC2045 (6.7) quoted-printable format Uses a PHP5 stream filter to do the encoding about 64x faster than the old version Also results in same content as you started with after decoding.
  • EncodeQ ($str, $position= 'text')
    Encode string to q encoding.
  • AddStringAttachment ($string, $filename, $encoding= 'base64', $type= 'application/octet-stream')
    Adds a string or binary attachment (non-filesystem) to the list.
  • AddEmbeddedImage ($path, $cid, $name= '', $encoding= 'base64', $type= 'application/octet-stream')
    Adds an embedded attachment.
  • InlineImageExists ()
    Returns true if an inline attachment is present.
  • ClearAddresses ()
    Clears all recipients assigned in the TO array.
  • ClearCCs ()
    Clears all recipients assigned in the CC array.
  • ClearBCCs ()
    Clears all recipients assigned in the BCC array.
  • ClearReplyTos ()
    Clears all recipients assigned in the ReplyTo array.
  • ClearAllRecipients ()
    Clears all recipients assigned in the TO, CC and BCC array.
  • ClearAttachments ()
    Clears all previously set filesystem, string, and binary attachments.
  • ClearCustomHeaders ()
    Clears all custom headers.
  • IsError ()
    Returns true if an error occurred.
  • AddCustomHeader ($custom_header)
    Adds a custom header.
  • MsgHTML ($message, $basedir= '')
    Evaluates the message and returns modifications for inline images and backgrounds public.
  • set ($name, $value= '')
    Set (or reset) Class Objects (variables).
  • SecureHeader ($str)
    Strips newlines to prevent header injection.
  • Sign ($cert_filename, $key_filename, $key_pass)
    Set the private key file and password to sign the message.
  • DKIM_QP ($txt)
    Set the private key file and password to sign the message.
  • DKIM_Sign ($s)
    Generate DKIM signature.
  • DKIM_HeaderC ($s)
    Generate DKIM Canonicalization Header.
  • DKIM_BodyC ($body)
    Generate DKIM Canonicalization Body.
  • DKIM_Add ($headers_line, $subject, $body)
    Create the DKIM header, body, as new header.

Static Public Member Functions

  • static ValidateAddress ($address)
    Check that a string looks roughly like an email address should Static so it can be used without instantiation Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator Conforms approximately to RFC2822 Original pattern found here.
  • static RFCDate ()
    Returns the proper RFC 822 formatted date.
  • static _mime_types ($ext= '')
    Gets the MIME type of the embedded or inline image.

Public Attributes

Protected Member Functions

  • SendmailSend ($header, $body)
    Sends mail using the $Sendmail program.
  • MailSend ($header, $body)
    Sends mail using the PHP mail() function.
  • SmtpSend ($header, $body)
    Sends mail via SMTP using PhpSMTP Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
  • SetError ($msg)
    Adds the error message to the error container.
  • doCallback ($isSent, $to, $cc, $bcc, $subject, $body)

Protected Attributes

Private Member Functions

  • AddAnAddress ($kind, $address, $name= '')
    Adds an address to one of the recipient arrays Addresses that have been added already return false, but do not throw exceptions.
  • GetBoundary ($boundary, $charSet, $contentType, $encoding)
    Returns the start of a message boundary.
  • EndBoundary ($boundary)
    Returns the end of a message boundary.
  • SetMessageType ()
    Sets the message type.
  • AttachAll ()
    Attaches all fs, string, and binary attachments to the message.
  • EncodeFile ($path, $encoding= 'base64')
    Encodes attachment in requested format.
  • ServerHostname ()
    Returns the server hostname or 'localhost.localdomain' if unknown.
  • Lang ($key)
    Returns a message in the appropriate language.
  • FixEOL ($str)
    Changes every end of line from CR or LF to CRLF.

Private Attributes


Detailed Description

Definition at line 53 of file PHPMailer.php.


Constructor & Destructor Documentation

PHPMailer::__construct ( exceptions = false  ) 

Constructor.

Parameters:
boolean $exceptions Should we throw external exceptions?

Definition at line 352 of file PHPMailer.php.

00352                                                    {
00353     $this->exceptions = ($exceptions == true);
00354   }


Member Function Documentation

static PHPMailer::_mime_types ( ext = ''  )  [static]

Gets the MIME type of the embedded or inline image.

Parameters:
string File extension public
Returns:
string MIME type of ext

Definition at line 2051 of file PHPMailer.php.

Referenced by MsgHTML().

02051                                                 {
02052     $mimes = array(
02053       'hqx'   =>  'application/mac-binhex40',
02054       'cpt'   =>  'application/mac-compactpro',
02055       'doc'   =>  'application/msword',
02056       'bin'   =>  'application/macbinary',
02057       'dms'   =>  'application/octet-stream',
02058       'lha'   =>  'application/octet-stream',
02059       'lzh'   =>  'application/octet-stream',
02060       'exe'   =>  'application/octet-stream',
02061       'class' =>  'application/octet-stream',
02062       'psd'   =>  'application/octet-stream',
02063       'so'    =>  'application/octet-stream',
02064       'sea'   =>  'application/octet-stream',
02065       'dll'   =>  'application/octet-stream',
02066       'oda'   =>  'application/oda',
02067       'pdf'   =>  'application/pdf',
02068       'ai'    =>  'application/postscript',
02069       'eps'   =>  'application/postscript',
02070       'ps'    =>  'application/postscript',
02071       'smi'   =>  'application/smil',
02072       'smil'  =>  'application/smil',
02073       'mif'   =>  'application/vnd.mif',
02074       'xls'   =>  'application/vnd.ms-excel',
02075       'ppt'   =>  'application/vnd.ms-powerpoint',
02076       'wbxml' =>  'application/vnd.wap.wbxml',
02077       'wmlc'  =>  'application/vnd.wap.wmlc',
02078       'dcr'   =>  'application/x-director',
02079       'dir'   =>  'application/x-director',
02080       'dxr'   =>  'application/x-director',
02081       'dvi'   =>  'application/x-dvi',
02082       'gtar'  =>  'application/x-gtar',
02083       'php'   =>  'application/x-httpd-php',
02084       'php4'  =>  'application/x-httpd-php',
02085       'php3'  =>  'application/x-httpd-php',
02086       'phtml' =>  'application/x-httpd-php',
02087       'phps'  =>  'application/x-httpd-php-source',
02088       'js'    =>  'application/x-javascript',
02089       'swf'   =>  'application/x-shockwave-flash',
02090       'sit'   =>  'application/x-stuffit',
02091       'tar'   =>  'application/x-tar',
02092       'tgz'   =>  'application/x-tar',
02093       'xhtml' =>  'application/xhtml+xml',
02094       'xht'   =>  'application/xhtml+xml',
02095       'zip'   =>  'application/zip',
02096       'mid'   =>  'audio/midi',
02097       'midi'  =>  'audio/midi',
02098       'mpga'  =>  'audio/mpeg',
02099       'mp2'   =>  'audio/mpeg',
02100       'mp3'   =>  'audio/mpeg',
02101       'aif'   =>  'audio/x-aiff',
02102       'aiff'  =>  'audio/x-aiff',
02103       'aifc'  =>  'audio/x-aiff',
02104       'ram'   =>  'audio/x-pn-realaudio',
02105       'rm'    =>  'audio/x-pn-realaudio',
02106       'rpm'   =>  'audio/x-pn-realaudio-plugin',
02107       'ra'    =>  'audio/x-realaudio',
02108       'rv'    =>  'video/vnd.rn-realvideo',
02109       'wav'   =>  'audio/x-wav',
02110       'bmp'   =>  'image/bmp',
02111       'gif'   =>  'image/gif',
02112       'jpeg'  =>  'image/jpeg',
02113       'jpg'   =>  'image/jpeg',
02114       'jpe'   =>  'image/jpeg',
02115       'png'   =>  'image/png',
02116       'tiff'  =>  'image/tiff',
02117       'tif'   =>  'image/tiff',
02118       'css'   =>  'text/css',
02119       'html'  =>  'text/html',
02120       'htm'   =>  'text/html',
02121       'shtml' =>  'text/html',
02122       'txt'   =>  'text/plain',
02123       'text'  =>  'text/plain',
02124       'log'   =>  'text/plain',
02125       'rtx'   =>  'text/richtext',
02126       'rtf'   =>  'text/rtf',
02127       'xml'   =>  'text/xml',
02128       'xsl'   =>  'text/xml',
02129       'mpeg'  =>  'video/mpeg',
02130       'mpg'   =>  'video/mpeg',
02131       'mpe'   =>  'video/mpeg',
02132       'qt'    =>  'video/quicktime',
02133       'mov'   =>  'video/quicktime',
02134       'avi'   =>  'video/x-msvideo',
02135       'movie' =>  'video/x-sgi-movie',
02136       'doc'   =>  'application/msword',
02137       'word'  =>  'application/msword',
02138       'xl'    =>  'application/excel',
02139       'eml'   =>  'message/rfc822'
02140     );
02141     return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
02142   }

PHPMailer::AddAddress ( address,
name = '' 
)

Adds a "To" address.

Parameters:
string $address
string $name
Returns:
boolean true on success, false if address already used

Definition at line 417 of file PHPMailer.php.

00417                                                    {
00418     return $this->AddAnAddress('to', $address, $name);
00419   }

PHPMailer::AddAnAddress ( kind,
address,
name = '' 
) [private]

Adds an address to one of the recipient arrays Addresses that have been added already return false, but do not throw exceptions.

Parameters:
string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
string $address The email address to send to
string $name
Returns:
boolean true on success, false if address already used or invalid in some way private

Definition at line 462 of file PHPMailer.php.

Referenced by AddAddress(), AddBCC(), AddCC(), AddReplyTo(), and SetFrom().

00462                                                              {
00463     if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
00464       echo 'Invalid recipient array: ' . kind;
00465       return false;
00466     }
00467     $address = trim($address);
00468     $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
00469     if (!self::ValidateAddress($address)) {
00470       $this->SetError($this->Lang('invalid_address').': '. $address);
00471       if ($this->exceptions) {
00472         throw new phpmailerException($this->Lang('invalid_address').': '.$address);
00473       }
00474       echo $this->Lang('invalid_address').': '.$address;
00475       return false;
00476     }
00477     if ($kind != 'ReplyTo') {
00478       if (!isset($this->all_recipients[strtolower($address)])) {
00479         array_push($this->$kind, array($address, $name));
00480         $this->all_recipients[strtolower($address)] = true;
00481         return true;
00482       }
00483     } else {
00484       if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
00485         $this->ReplyTo[strtolower($address)] = array($address, $name);
00486       return true;
00487     }
00488   }
00489   return false;
00490 }

PHPMailer::AddAttachment ( path,
name = '',
encoding = 'base64',
type = 'application/octet-stream' 
)

Adds an attachment from a path on the filesystem.

Returns false if the file could not be found or accessed.

Parameters:
string $path Path to the attachment.
string $name Overrides the attachment name.
string $encoding File encoding (see $Encoding).
string $type File extension (MIME) type.
Returns:
bool

Definition at line 1354 of file PHPMailer.php.

01354                                                                                                              {
01355     try {
01356       if ( !@is_file($path) ) {
01357         throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE);
01358       }
01359       $filename = basename($path);
01360       if ( $name == '' ) {
01361         $name = $filename;
01362       }
01363 
01364       $this->attachment[] = array(
01365         0 => $path,
01366         1 => $filename,
01367         2 => $name,
01368         3 => $encoding,
01369         4 => $type,
01370         5 => false,  // isStringAttachment
01371         6 => 'attachment',
01372         7 => 0
01373       );
01374 
01375     } catch (phpmailerException $e) {
01376       $this->SetError($e->getMessage());
01377       if ($this->exceptions) {
01378         throw $e;
01379       }
01380       echo $e->getMessage()."\n";
01381       if ( $e->getCode() == self::STOP_CRITICAL ) {
01382         return false;
01383       }
01384     }
01385     return true;
01386   }

PHPMailer::AddBCC ( address,
name = '' 
)

Adds a "Bcc" address.

Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.

Parameters:
string $address
string $name
Returns:
boolean true on success, false if address already used

Definition at line 439 of file PHPMailer.php.

00439                                                {
00440     return $this->AddAnAddress('bcc', $address, $name);
00441   }

PHPMailer::AddCC ( address,
name = '' 
)

Adds a "Cc" address.

Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.

Parameters:
string $address
string $name
Returns:
boolean true on success, false if address already used

Definition at line 428 of file PHPMailer.php.

00428                                               {
00429     return $this->AddAnAddress('cc', $address, $name);
00430   }

PHPMailer::AddCustomHeader ( custom_header  ) 

Adds a custom header.

public

Returns:
void

Definition at line 2004 of file PHPMailer.php.

02004                                                   {
02005     $this->CustomHeader[] = explode(':', $custom_header, 2);
02006   }

PHPMailer::AddEmbeddedImage ( path,
cid,
name = '',
encoding = 'base64',
type = 'application/octet-stream' 
)

Adds an embedded attachment.

This can include images, sounds, and just about any other document. Make sure to set the $type to an image type. For JPEG images use "image/jpeg" and for GIF images use "image/gif".

Parameters:
string $path Path to the attachment.
string $cid Content ID of the attachment. Use this to identify the Id for accessing the image in an HTML form.
string $name Overrides the attachment name.
string $encoding File encoding (see $Encoding).
string $type File extension (MIME) type.
Returns:
bool

Definition at line 1793 of file PHPMailer.php.

Referenced by MsgHTML().

01793                                                                                                                       {
01794 
01795     if ( !@is_file($path) ) {
01796       $this->SetError($this->Lang('file_access') . $path);
01797       return false;
01798     }
01799 
01800     $filename = basename($path);
01801     if ( $name == '' ) {
01802       $name = $filename;
01803     }
01804 
01805     // Append to $attachment array
01806     $this->attachment[] = array(
01807       0 => $path,
01808       1 => $filename,
01809       2 => $name,
01810       3 => $encoding,
01811       4 => $type,
01812       5 => false,  // isStringAttachment
01813       6 => 'inline',
01814       7 => $cid
01815     );
01816 
01817     return true;
01818   }

PHPMailer::AddrAppend ( type,
addr 
)

Creates recipient headers.

public

Returns:
string

Definition at line 907 of file PHPMailer.php.

Referenced by CreateHeader().

00907                                            {
00908     $addr_str = $type . ': ';
00909     $addresses = array();
00910     foreach ($addr as $a) {
00911       $addresses[] = $this->AddrFormat($a);
00912     }
00913     $addr_str .= implode(', ', $addresses);
00914     $addr_str .= $this->LE;
00915 
00916     return $addr_str;
00917   }

PHPMailer::AddReplyTo ( address,
name = '' 
)

Adds a "Reply-to" address.

Parameters:
string $address
string $name
Returns:
boolean

Definition at line 449 of file PHPMailer.php.

00449                                                    {
00450     return $this->AddAnAddress('ReplyTo', $address, $name);
00451   }

PHPMailer::AddrFormat ( addr  ) 

Formats an address correctly.

public

Returns:
string

Definition at line 924 of file PHPMailer.php.

Referenced by AddrAppend(), CreateHeader(), and MailSend().

00924                                     {
00925     if (empty($addr[1])) {
00926       return $this->SecureHeader($addr[0]);
00927     } else {
00928       return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
00929     }
00930   }

PHPMailer::AddStringAttachment ( string,
filename,
encoding = 'base64',
type = 'application/octet-stream' 
)

Adds a string or binary attachment (non-filesystem) to the list.

This method can be used to attach ascii or binary data, such as a BLOB record from a database.

Parameters:
string $string String attachment data.
string $filename Name of the attachment.
string $encoding File encoding (see $Encoding).
string $type File extension (MIME) type.
Returns:
void

Definition at line 1766 of file PHPMailer.php.

01766                                                                                                                     {
01767     // Append to $attachment array
01768     $this->attachment[] = array(
01769       0 => $string,
01770       1 => $filename,
01771       2 => basename($filename),
01772       3 => $encoding,
01773       4 => $type,
01774       5 => true,  // isStringAttachment
01775       6 => 'attachment',
01776       7 => 0
01777     );
01778   }

PHPMailer::AttachAll (  )  [private]

Attaches all fs, string, and binary attachments to the message.

Returns an empty string on failure. private

Returns:
string

Definition at line 1402 of file PHPMailer.php.

Referenced by CreateBody().

01402                                {
01403     // Return text of body
01404     $mime = array();
01405     $cidUniq = array();
01406     $incl = array();
01407 
01408     // Add all attachments
01409     foreach ($this->attachment as $attachment) {
01410       // Check for string attachment
01411       $bString = $attachment[5];
01412       if ($bString) {
01413         $string = $attachment[0];
01414       } else {
01415         $path = $attachment[0];
01416       }
01417 
01418       if (in_array($attachment[0], $incl)) { continue; }
01419       $filename    = $attachment[1];
01420       $name        = $attachment[2];
01421       $encoding    = $attachment[3];
01422       $type        = $attachment[4];
01423       $disposition = $attachment[6];
01424       $cid         = $attachment[7];
01425       $incl[]      = $attachment[0];
01426       if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
01427       $cidUniq[$cid] = true;
01428 
01429       $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
01430       $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
01431       $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
01432 
01433       if($disposition == 'inline') {
01434         $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
01435       }
01436 
01437       $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
01438 
01439       // Encode as string attachment
01440       if($bString) {
01441         $mime[] = $this->EncodeString($string, $encoding);
01442         if($this->IsError()) {
01443           return '';
01444         }
01445         $mime[] = $this->LE.$this->LE;
01446       } else {
01447         $mime[] = $this->EncodeFile($path, $encoding);
01448         if($this->IsError()) {
01449           return '';
01450         }
01451         $mime[] = $this->LE.$this->LE;
01452       }
01453     }
01454 
01455     $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
01456 
01457     return join('', $mime);
01458   }

PHPMailer::Base64EncodeWrapMB ( str  ) 

Correctly encodes and wraps long multibyte strings for mail headers without breaking lines within a character.

Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php public

Parameters:
string $str multi-byte text to wrap encode
Returns:
string

Definition at line 1609 of file PHPMailer.php.

Referenced by EncodeHeader().

01609                                            {
01610     $start = "=?".$this->CharSet."?B?";
01611     $end = "?=";
01612     $encoded = "";
01613 
01614     $mb_length = mb_strlen($str, $this->CharSet);
01615     // Each line must have length <= 75, including $start and $end
01616     $length = 75 - strlen($start) - strlen($end);
01617     // Average multi-byte ratio
01618     $ratio = $mb_length / strlen($str);
01619     // Base64 has a 4:3 ratio
01620     $offset = $avgLength = floor($length * $ratio * .75);
01621 
01622     for ($i = 0; $i < $mb_length; $i += $offset) {
01623       $lookBack = 0;
01624 
01625       do {
01626         $offset = $avgLength - $lookBack;
01627         $chunk = mb_substr($str, $i, $offset, $this->CharSet);
01628         $chunk = base64_encode($chunk);
01629         $lookBack++;
01630       }
01631       while (strlen($chunk) > $length);
01632 
01633       $encoded .= $chunk . $this->LE;
01634     }
01635 
01636     // Chomp the last linefeed
01637     $encoded = substr($encoded, 0, -strlen($this->LE));
01638     return $encoded;
01639   }

PHPMailer::ClearAddresses (  ) 

Clears all recipients assigned in the TO array.

Returns void.

Returns:
void

Definition at line 1842 of file PHPMailer.php.

01842                                    {
01843     foreach($this->to as $to) {
01844       unset($this->all_recipients[strtolower($to[0])]);
01845     }
01846     $this->to = array();
01847   }

PHPMailer::ClearAllRecipients (  ) 

Clears all recipients assigned in the TO, CC and BCC array.

Returns void.

Returns:
void

Definition at line 1884 of file PHPMailer.php.

01884                                        {
01885     $this->to = array();
01886     $this->cc = array();
01887     $this->bcc = array();
01888     $this->all_recipients = array();
01889   }

PHPMailer::ClearAttachments (  ) 

Clears all previously set filesystem, string, and binary attachments.

Returns void.

Returns:
void

Definition at line 1896 of file PHPMailer.php.

01896                                      {
01897     $this->attachment = array();
01898   }

PHPMailer::ClearBCCs (  ) 

Clears all recipients assigned in the BCC array.

Returns void.

Returns:
void

Definition at line 1864 of file PHPMailer.php.

01864                               {
01865     foreach($this->bcc as $bcc) {
01866       unset($this->all_recipients[strtolower($bcc[0])]);
01867     }
01868     $this->bcc = array();
01869   }

PHPMailer::ClearCCs (  ) 

Clears all recipients assigned in the CC array.

Returns void.

Returns:
void

Definition at line 1853 of file PHPMailer.php.

01853                              {
01854     foreach($this->cc as $cc) {
01855       unset($this->all_recipients[strtolower($cc[0])]);
01856     }
01857     $this->cc = array();
01858   }

PHPMailer::ClearCustomHeaders (  ) 

Clears all custom headers.

Returns void.

Returns:
void

Definition at line 1904 of file PHPMailer.php.

01904                                        {
01905     $this->CustomHeader = array();
01906   }

PHPMailer::ClearReplyTos (  ) 

Clears all recipients assigned in the ReplyTo array.

Returns void.

Returns:
void

Definition at line 1875 of file PHPMailer.php.

01875                                   {
01876     $this->ReplyTo = array();
01877   }

PHPMailer::CreateBody (  ) 

Assembles the message body.

Returns an empty string on failure. public

Returns:
string The assembled message body

Definition at line 1200 of file PHPMailer.php.

Referenced by Send().

01200                                {
01201     $body = '';
01202 
01203     if ($this->sign_key_file) {
01204       $body .= $this->GetMailMIME();
01205     }
01206 
01207     $this->SetWordWrap();
01208 
01209     switch($this->message_type) {
01210       case 'alt':
01211         $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
01212         $body .= $this->EncodeString($this->AltBody, $this->Encoding);
01213         $body .= $this->LE.$this->LE;
01214         $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
01215         $body .= $this->EncodeString($this->Body, $this->Encoding);
01216         $body .= $this->LE.$this->LE;
01217         $body .= $this->EndBoundary($this->boundary[1]);
01218         break;
01219       case 'plain':
01220         $body .= $this->EncodeString($this->Body, $this->Encoding);
01221         break;
01222       case 'attachments':
01223         $body .= $this->GetBoundary($this->boundary[1], '', '', '');
01224         $body .= $this->EncodeString($this->Body, $this->Encoding);
01225         $body .= $this->LE;
01226         $body .= $this->AttachAll();
01227         break;
01228       case 'alt_attachments':
01229         $body .= sprintf("--%s%s", $this->boundary[1], $this->LE);
01230         $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
01231         $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
01232         $body .= $this->EncodeString($this->AltBody, $this->Encoding);
01233         $body .= $this->LE.$this->LE;
01234         $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
01235         $body .= $this->EncodeString($this->Body, $this->Encoding);
01236         $body .= $this->LE.$this->LE;
01237         $body .= $this->EndBoundary($this->boundary[2]);
01238         $body .= $this->AttachAll();
01239         break;
01240     }
01241 
01242     if ($this->IsError()) {
01243       $body = '';
01244     } elseif ($this->sign_key_file) {
01245       try {
01246         $file = tempnam('', 'mail');
01247         file_put_contents($file, $body); //TODO check this worked
01248         $signed = tempnam("", "signed");
01249         if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
01250           @unlink($file);
01251           @unlink($signed);
01252           $body = file_get_contents($signed);
01253         } else {
01254           @unlink($file);
01255           @unlink($signed);
01256           throw new phpmailerException($this->Lang("signing").openssl_error_string());
01257         }
01258       } catch (phpmailerException $e) {
01259         $body = '';
01260         if ($this->exceptions) {
01261           throw $e;
01262         }
01263       }
01264     }
01265 
01266     return $body;
01267   }

PHPMailer::CreateHeader (  ) 

Assembles message header.

public

Returns:
string The assembled header

Definition at line 1083 of file PHPMailer.php.

Referenced by Send().

01083                                  {
01084     $result = '';
01085 
01086     // Set the boundaries
01087     $uniq_id = md5(uniqid(time()));
01088     $this->boundary[1] = 'b1_' . $uniq_id;
01089     $this->boundary[2] = 'b2_' . $uniq_id;
01090 
01091     $result .= $this->HeaderLine('Date', self::RFCDate());
01092     if($this->Sender == '') {
01093       $result .= $this->HeaderLine('Return-Path', trim($this->From));
01094     } else {
01095       $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
01096     }
01097 
01098     // To be created automatically by mail()
01099     if($this->Mailer != 'mail') {
01100       if ($this->SingleTo === true) {
01101         foreach($this->to as $t) {
01102           $this->SingleToArray[] = $this->AddrFormat($t);
01103         }
01104       } else {
01105         if(count($this->to) > 0) {
01106           $result .= $this->AddrAppend('To', $this->to);
01107         } elseif (count($this->cc) == 0) {
01108           $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
01109         }
01110       }
01111     }
01112 
01113     $from = array();
01114     $from[0][0] = trim($this->From);
01115     $from[0][1] = $this->FromName;
01116     $result .= $this->AddrAppend('From', $from);
01117 
01118     // sendmail and mail() extract Cc from the header before sending
01119     if(count($this->cc) > 0) {
01120       $result .= $this->AddrAppend('Cc', $this->cc);
01121     }
01122 
01123     // sendmail and mail() extract Bcc from the header before sending
01124     if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
01125       $result .= $this->AddrAppend('Bcc', $this->bcc);
01126     }
01127 
01128     if(count($this->ReplyTo) > 0) {
01129       $result .= $this->AddrAppend('Reply-to', $this->ReplyTo);
01130     }
01131 
01132     // mail() sets the subject itself
01133     if($this->Mailer != 'mail') {
01134       $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
01135     }
01136 
01137     if($this->MessageID != '') {
01138       $result .= $this->HeaderLine('Message-ID',$this->MessageID);
01139     } else {
01140       $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
01141     }
01142     $result .= $this->HeaderLine('X-Priority', $this->Priority);
01143     $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)');
01144 
01145     if($this->ConfirmReadingTo != '') {
01146       $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
01147     }
01148 
01149     // Add custom headers
01150     for($index = 0; $index < count($this->CustomHeader); $index++) {
01151       $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
01152     }
01153     if (!$this->sign_key_file) {
01154       $result .= $this->HeaderLine('MIME-Version', '1.0');
01155       $result .= $this->GetMailMIME();
01156     }
01157 
01158     return $result;
01159   }

PHPMailer::DKIM_Add ( headers_line,
subject,
body 
)

Create the DKIM header, body, as new header.

public

Parameters:
string $headers_line Header lines
string $subject Subject
string $body Body

Definition at line 2281 of file PHPMailer.php.

Referenced by Send().

02281                                                          {
02282     $DKIMsignatureType    = 'rsa-sha1'; // Signature & hash algorithms
02283     $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
02284     $DKIMquery            = 'dns/txt'; // Query method
02285     $DKIMtime             = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
02286     $subject_header       = "Subject: $subject";
02287     $headers              = explode("\r\n",$headers_line);
02288     foreach($headers as $header) {
02289       if (strpos($header,'From:') === 0) {
02290         $from_header=$header;
02291       } elseif (strpos($header,'To:') === 0) {
02292         $to_header=$header;
02293       }
02294     }
02295     $from     = str_replace('|','=7C',$this->DKIM_QP($from_header));
02296     $to       = str_replace('|','=7C',$this->DKIM_QP($to_header));
02297     $subject  = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable
02298     $body     = $this->DKIM_BodyC($body);
02299     $DKIMlen  = strlen($body) ; // Length of body
02300     $DKIMb64  = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body
02301     $ident    = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";";
02302     $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n".
02303                 "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n".
02304                 "\th=From:To:Subject;\r\n".
02305                 "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n".
02306                 "\tz=$from\r\n".
02307                 "\t|$to\r\n".
02308                 "\t|$subject;\r\n".
02309                 "\tbh=" . $DKIMb64 . ";\r\n".
02310                 "\tb=";
02311     $toSign   = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
02312     $signed   = $this->DKIM_Sign($toSign);
02313     return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
02314   }

PHPMailer::DKIM_BodyC ( body  ) 

Generate DKIM Canonicalization Body.

public

Parameters:
string $body Message Body

Definition at line 2261 of file PHPMailer.php.

Referenced by DKIM_Add().

02261                                     {
02262     if ($body == '') return "\r\n";
02263     // stabilize line endings
02264     $body=str_replace("\r\n","\n",$body);
02265     $body=str_replace("\n","\r\n",$body);
02266     // END stabilize line endings
02267     while (substr($body,strlen($body)-4,4) == "\r\n\r\n") {
02268       $body=substr($body,0,strlen($body)-2);
02269     }
02270     return $body;
02271   }

PHPMailer::DKIM_HeaderC ( s  ) 

Generate DKIM Canonicalization Header.

public

Parameters:
string $s Header

Definition at line 2242 of file PHPMailer.php.

Referenced by DKIM_Add().

02242                                    {
02243     $s=preg_replace("/\r\n\s+/"," ",$s);
02244     $lines=explode("\r\n",$s);
02245     foreach ($lines as $key=>$line) {
02246       list($heading,$value)=explode(":",$line,2);
02247       $heading=strtolower($heading);
02248       $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces
02249       $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value
02250     }
02251     $s=implode("\r\n",$lines);
02252     return $s;
02253   }

PHPMailer::DKIM_QP ( txt  ) 

Set the private key file and password to sign the message.

public

Parameters:
string $key_filename Parameter File Name
string $key_pass Password for private key

Definition at line 2204 of file PHPMailer.php.

Referenced by DKIM_Add().

02204                                 {
02205     $tmp="";
02206     $line="";
02207     for ($i=0;$i<strlen($txt);$i++) {
02208       $ord=ord($txt[$i]);
02209       if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) {
02210         $line.=$txt[$i];
02211       } else {
02212         $line.="=".sprintf("%02X",$ord);
02213       }
02214     }
02215     return $line;
02216   }

PHPMailer::DKIM_Sign ( s  ) 

Generate DKIM signature.

public

Parameters:
string $s Header

Definition at line 2224 of file PHPMailer.php.

Referenced by DKIM_Add().

02224                                 {
02225     $privKeyStr = file_get_contents($this->DKIM_private);
02226     if ($this->DKIM_passphrase!='') {
02227       $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase);
02228     } else {
02229       $privKey = $privKeyStr;
02230     }
02231     if (openssl_sign($s, $signature, $privKey)) {
02232       return base64_encode($signature);
02233     }
02234   }

PHPMailer::doCallback ( isSent,
to,
cc,
bcc,
subject,
body 
) [protected]

Definition at line 2316 of file PHPMailer.php.

Referenced by MailSend(), SendmailSend(), and SmtpSend().

02316                                                                      {
02317     if (!empty($this->action_function) && function_exists($this->action_function)) {
02318       $params = array($isSent,$to,$cc,$bcc,$subject,$body);
02319       call_user_func_array($this->action_function,$params);
02320     }
02321   }

PHPMailer::EncodeFile ( path,
encoding = 'base64' 
) [private]

Encodes attachment in requested format.

Returns an empty string on failure.

Parameters:
string $path The full path to the file
string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
See also:
EncodeFile() private
Returns:
string

Definition at line 1469 of file PHPMailer.php.

Referenced by AttachAll().

01469                                                            {
01470     try {
01471       if (!is_readable($path)) {
01472         throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
01473       }
01474       if (function_exists('get_magic_quotes')) {
01475         function get_magic_quotes() {
01476           return false;
01477         }
01478       }
01479       if (PHP_VERSION < 6) {
01480         $magic_quotes = get_magic_quotes_runtime();
01481         set_magic_quotes_runtime(0);
01482       }
01483       $file_buffer  = file_get_contents($path);
01484       $file_buffer  = $this->EncodeString($file_buffer, $encoding);
01485       if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
01486       return $file_buffer;
01487     } catch (Exception $e) {
01488       $this->SetError($e->getMessage());
01489       return '';
01490     }
01491   }

PHPMailer::EncodeHeader ( str,
position = 'text' 
)

Encode a header string to best (shortest) of Q, B, quoted or none.

public

Returns:
string

Definition at line 1532 of file PHPMailer.php.

Referenced by AddrFormat(), AttachAll(), CreateHeader(), and MailSend().

01532                                                          {
01533     $x = 0;
01534 
01535     switch (strtolower($position)) {
01536       case 'phrase':
01537         if (!preg_match('/[\200-\377]/', $str)) {
01538           // Can't use addslashes as we don't know what value has magic_quotes_sybase
01539           $encoded = addcslashes($str, "\0..\37\177\\\"");
01540           if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
01541             return ($encoded);
01542           } else {
01543             return ("\"$encoded\"");
01544           }
01545         }
01546         $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
01547         break;
01548       case 'comment':
01549         $x = preg_match_all('/[()"]/', $str, $matches);
01550         // Fall-through
01551       case 'text':
01552       default:
01553         $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
01554         break;
01555     }
01556 
01557     if ($x == 0) {
01558       return ($str);
01559     }
01560 
01561     $maxlen = 75 - 7 - strlen($this->CharSet);
01562     // Try to select the encoding which should produce the shortest output
01563     if (strlen($str)/3 < $x) {
01564       $encoding = 'B';
01565       if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
01566         // Use a custom function which correctly encodes and wraps long
01567         // multibyte strings without breaking lines within a character
01568         $encoded = $this->Base64EncodeWrapMB($str);
01569       } else {
01570         $encoded = base64_encode($str);
01571         $maxlen -= $maxlen % 4;
01572         $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
01573       }
01574     } else {
01575       $encoding = 'Q';
01576       $encoded = $this->EncodeQ($str, $position);
01577       $encoded = $this->WrapText($encoded, $maxlen, true);
01578       $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
01579     }
01580 
01581     $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
01582     $encoded = trim(str_replace("\n", $this->LE, $encoded));
01583 
01584     return $encoded;
01585   }

PHPMailer::EncodeQ ( str,
position = 'text' 
)

Encode string to q encoding.

string $str the text to encode string $position Where the text is going to be used, see the RFC for what that means public string

Definition at line 1731 of file PHPMailer.php.

Referenced by EncodeHeader().

01731                                                      {
01732     // There should not be any EOL in the string
01733     $encoded = preg_replace('/[\r\n]*/', '', $str);
01734 
01735     switch (strtolower($position)) {
01736       case 'phrase':
01737         $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
01738         break;
01739       case 'comment':
01740         $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
01741       case 'text':
01742       default:
01743         // Replace every high ascii, control =, ? and _ characters
01744         //TODO using /e (equivalent to eval()) is probably not a good idea
01745         $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
01746               "'='.sprintf('%02X', ord('\\1'))", $encoded);
01747         break;
01748     }
01749 
01750     // Replace every spaces to _ (more readable than =20)
01751     $encoded = str_replace(' ', '_', $encoded);
01752 
01753     return $encoded;
01754   }

PHPMailer::EncodeQP ( string,
line_max = 76,
space_conv = false 
)

Encode string to RFC2045 (6.7) quoted-printable format Uses a PHP5 stream filter to do the encoding about 64x faster than the old version Also results in same content as you started with after decoding.

See also:
EncodeQPphp() public
Parameters:
string $string the text to encode
integer $line_max Number of chars allowed on a line before wrapping
boolean $space_conv Dummy param for compatibility with existing EncodeQP function
Returns:
string
Author:
Marcus Bointon

Definition at line 1702 of file PHPMailer.php.

Referenced by EncodeString().

01702                                                                          {
01703     if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3)
01704       return quoted_printable_encode($string);
01705     }
01706     $filters = stream_get_filters();
01707     if (!in_array('convert.*', $filters)) { //Got convert stream filter?
01708       return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation
01709     }
01710     $fp = fopen('php://temp/', 'r+');
01711     $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks
01712     $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE);
01713     $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
01714     fputs($fp, $string);
01715     rewind($fp);
01716     $out = stream_get_contents($fp);
01717     stream_filter_remove($s);
01718     $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange
01719     fclose($fp);
01720     return $out;
01721   }

PHPMailer::EncodeQPphp ( input = '',
line_max = 76,
space_conv = false 
)

Encode string to quoted-printable.

Only uses standard PHP, slow, but will always work public

Parameters:
string $string the text to encode
integer $line_max Number of chars allowed on a line before wrapping
Returns:
string

Definition at line 1649 of file PHPMailer.php.

Referenced by EncodeQP().

01649                                                                                  {
01650     $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
01651     $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
01652     $eol = "\r\n";
01653     $escape = '=';
01654     $output = '';
01655     while( list(, $line) = each($lines) ) {
01656       $linlen = strlen($line);
01657       $newline = '';
01658       for($i = 0; $i < $linlen; $i++) {
01659         $c = substr( $line, $i, 1 );
01660         $dec = ord( $c );
01661         if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
01662           $c = '=2E';
01663         }
01664         if ( $dec == 32 ) {
01665           if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
01666             $c = '=20';
01667           } else if ( $space_conv ) {
01668             $c = '=20';
01669           }
01670         } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
01671           $h2 = floor($dec/16);
01672           $h1 = floor($dec%16);
01673           $c = $escape.$hex[$h2].$hex[$h1];
01674         }
01675         if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
01676           $output .= $newline.$escape.$eol; //  soft line break; " =\r\n" is okay
01677           $newline = '';
01678           // check if newline first character will be point or not
01679           if ( $dec == 46 ) {
01680             $c = '=2E';
01681           }
01682         }
01683         $newline .= $c;
01684       } // end of for
01685       $output .= $newline.$eol;
01686     } // end of while
01687     return $output;
01688   }

PHPMailer::EncodeString ( str,
encoding = 'base64' 
)

Encodes string to requested format.

Returns an empty string on failure.

Parameters:
string $str The text to encode
string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' public
Returns:
string

Definition at line 1501 of file PHPMailer.php.

Referenced by AttachAll(), CreateBody(), and EncodeFile().

01501                                                             {
01502     $encoded = '';
01503     switch(strtolower($encoding)) {
01504       case 'base64':
01505         $encoded = chunk_split(base64_encode($str), 76, $this->LE);
01506         break;
01507       case '7bit':
01508       case '8bit':
01509         $encoded = $this->FixEOL($str);
01510         //Make sure it ends with a line break
01511         if (substr($encoded, -(strlen($this->LE))) != $this->LE)
01512           $encoded .= $this->LE;
01513         break;
01514       case 'binary':
01515         $encoded = $str;
01516         break;
01517       case 'quoted-printable':
01518         $encoded = $this->EncodeQP($str);
01519         break;
01520       default:
01521         $this->SetError($this->Lang('encoding') . $encoding);
01522         break;
01523     }
01524     return $encoded;
01525   }

PHPMailer::EndBoundary ( boundary  )  [private]

Returns the end of a message boundary.

private

Definition at line 1297 of file PHPMailer.php.

Referenced by CreateBody().

01297                                           {
01298     return $this->LE . '--' . $boundary . '--' . $this->LE;
01299   }

PHPMailer::FixEOL ( str  )  [private]

Changes every end of line from CR or LF to CRLF.

private

Returns:
string

Definition at line 1992 of file PHPMailer.php.

Referenced by EncodeString(), and WrapText().

01992                                 {
01993     $str = str_replace("\r\n", "\n", $str);
01994     $str = str_replace("\r", "\n", $str);
01995     $str = str_replace("\n", $this->LE, $str);
01996     return $str;
01997   }

PHPMailer::GetAttachments (  ) 

Return the current array of attachments.

Returns:
array

Definition at line 1392 of file PHPMailer.php.

01392                                    {
01393     return $this->attachment;
01394   }

PHPMailer::GetBoundary ( boundary,
charSet,
contentType,
encoding 
) [private]

Returns the start of a message boundary.

private

Definition at line 1273 of file PHPMailer.php.

Referenced by CreateBody().

01273                                                                              {
01274     $result = '';
01275     if($charSet == '') {
01276       $charSet = $this->CharSet;
01277     }
01278     if($contentType == '') {
01279       $contentType = $this->ContentType;
01280     }
01281     if($encoding == '') {
01282       $encoding = $this->Encoding;
01283     }
01284     $result .= $this->TextLine('--' . $boundary);
01285     $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
01286     $result .= $this->LE;
01287     $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
01288     $result .= $this->LE;
01289 
01290     return $result;
01291   }

PHPMailer::GetMailMIME (  ) 

Returns the message MIME.

public

Returns:
string

Definition at line 1166 of file PHPMailer.php.

Referenced by CreateBody(), and CreateHeader().

01166                                 {
01167     $result = '';
01168     switch($this->message_type) {
01169       case 'plain':
01170         $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
01171         $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
01172         break;
01173       case 'attachments':
01174       case 'alt_attachments':
01175         if($this->InlineImageExists()){
01176           $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
01177         } else {
01178           $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
01179           $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
01180         }
01181         break;
01182       case 'alt':
01183         $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
01184         $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
01185         break;
01186     }
01187 
01188     if($this->Mailer != 'mail') {
01189       $result .= $this->LE.$this->LE;
01190     }
01191 
01192     return $result;
01193   }

PHPMailer::GetTranslations (  ) 

Return the current array of language strings.

Returns:
array

Definition at line 894 of file PHPMailer.php.

00894                                     {
00895     return $this->language;
00896   }

PHPMailer::HasMultiBytes ( str  ) 

Checks if a string contains multibyte characters.

public

Parameters:
string $str multi-byte text to wrap encode
Returns:
bool

Definition at line 1593 of file PHPMailer.php.

Referenced by EncodeHeader().

01593                                       {
01594     if (function_exists('mb_strlen')) {
01595       return (strlen($str) > mb_strlen($str, $this->CharSet));
01596     } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
01597       return false;
01598     }
01599   }

PHPMailer::HeaderLine ( name,
value 
)

Returns a formatted header line.

public

Returns:
string

Definition at line 1327 of file PHPMailer.php.

Referenced by CreateHeader(), GetBoundary(), and GetMailMIME().

01327                                             {
01328     return $name . ': ' . $value . $this->LE;
01329   }

PHPMailer::InlineImageExists (  ) 

Returns true if an inline attachment is present.

public

Returns:
bool

Definition at line 1825 of file PHPMailer.php.

Referenced by GetMailMIME().

01825                                       {
01826     foreach($this->attachment as $attachment) {
01827       if ($attachment[6] == 'inline') {
01828         return true;
01829       }
01830     }
01831     return false;
01832   }

PHPMailer::IsError (  ) 

Returns true if an error occurred.

public

Returns:
bool

Definition at line 1983 of file PHPMailer.php.

Referenced by AttachAll(), and CreateBody().

01983                             {
01984     return ($this->error_count > 0);
01985   }

PHPMailer::IsHTML ( ishtml = true  ) 

Sets message type to HTML.

Parameters:
bool $ishtml
Returns:
void

Definition at line 361 of file PHPMailer.php.

Referenced by MsgHTML().

00361                                          {
00362     if ($ishtml) {
00363       $this->ContentType = 'text/html';
00364     } else {
00365       $this->ContentType = 'text/plain';
00366     }
00367   }

PHPMailer::IsMail (  ) 

Sets Mailer to send message using PHP mail() function.

Returns:
void

Definition at line 381 of file PHPMailer.php.

00381                            {
00382     $this->Mailer = 'mail';
00383   }

PHPMailer::IsQmail (  ) 

Sets Mailer to send message using the qmail MTA.

Returns:
void

Definition at line 400 of file PHPMailer.php.

00400                             {
00401     if (stristr(ini_get('sendmail_path'), 'qmail')) {
00402       $this->Sendmail = '/var/qmail/bin/sendmail';
00403     }
00404     $this->Mailer = 'sendmail';
00405   }

PHPMailer::IsSendmail (  ) 

Sets Mailer to send message using the $Sendmail program.

Returns:
void

Definition at line 389 of file PHPMailer.php.

00389                                {
00390     if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
00391       $this->Sendmail = '/var/qmail/bin/sendmail';
00392     }
00393     $this->Mailer = 'sendmail';
00394   }

PHPMailer::IsSMTP (  ) 

Sets Mailer to send message using SMTP.

Returns:
void

Definition at line 373 of file PHPMailer.php.

00373                            {
00374     $this->Mailer = 'smtp';
00375   }

PHPMailer::Lang ( key  )  [private]

Returns a message in the appropriate language.

private

Returns:
string

Definition at line 1966 of file PHPMailer.php.

Referenced by AddAnAddress(), AddAttachment(), AddEmbeddedImage(), CreateBody(), EncodeFile(), EncodeString(), MailSend(), Send(), SendmailSend(), set(), SetError(), SetFrom(), SmtpConnect(), and SmtpSend().

01966                               {
01967     if(count($this->language) < 1) {
01968       $this->SetLanguage('en'); // set the default language
01969     }
01970 
01971     if(isset($this->language[$key])) {
01972       return $this->language[$key];
01973     } else {
01974       return 'Language string failed to load: ' . $key;
01975     }
01976   }

PHPMailer::MailSend ( header,
body 
) [protected]

Sends mail using the PHP mail() function.

Parameters:
string $header The message headers
string $body The message body protected
Returns:
bool

Definition at line 654 of file PHPMailer.php.

Referenced by Send().

00654                                               {
00655     $toArr = array();
00656     foreach($this->to as $t) {
00657       $toArr[] = $this->AddrFormat($t);
00658     }
00659     $to = implode(', ', $toArr);
00660 
00661     $params = sprintf("-oi -f %s", $this->Sender);
00662     if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
00663       $old_from = ini_get('sendmail_from');
00664       ini_set('sendmail_from', $this->Sender);
00665       if ($this->SingleTo === true && count($toArr) > 1) {
00666         foreach ($toArr as $key => $val) {
00667           $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
00668           // implement call back function if it exists
00669           $isSent = ($rt == 1) ? 1 : 0;
00670           $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
00671         }
00672       } else {
00673         $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
00674         // implement call back function if it exists
00675         $isSent = ($rt == 1) ? 1 : 0;
00676         $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
00677       }
00678     } else {
00679       if ($this->SingleTo === true && count($toArr) > 1) {
00680         foreach ($toArr as $key => $val) {
00681           $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
00682           // implement call back function if it exists
00683           $isSent = ($rt == 1) ? 1 : 0;
00684           $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
00685         }
00686       } else {
00687         $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
00688         // implement call back function if it exists
00689         $isSent = ($rt == 1) ? 1 : 0;
00690         $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
00691       }
00692     }
00693     if (isset($old_from)) {
00694       ini_set('sendmail_from', $old_from);
00695     }
00696     if(!$rt) {
00697       throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL);
00698     }
00699     return true;
00700   }

PHPMailer::MsgHTML ( message,
basedir = '' 
)

Evaluates the message and returns modifications for inline images and backgrounds public.

Returns:
$message

Definition at line 2013 of file PHPMailer.php.

02013                                                    {
02014     preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
02015     if(isset($images[2])) {
02016       foreach($images[2] as $i => $url) {
02017         // do not change urls for absolute images (thanks to corvuscorax)
02018         if (!preg_match('#^[A-z]+://#',$url)) {
02019           $filename = basename($url);
02020           $directory = dirname($url);
02021           ($directory == '.')?$directory='':'';
02022           $cid = 'cid:' . md5($filename);
02023           $ext = pathinfo($filename, PATHINFO_EXTENSION);
02024           $mimeType  = self::_mime_types($ext);
02025           if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
02026           if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
02027           if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
02028             $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
02029           }
02030         }
02031       }
02032     }
02033     $this->IsHTML(true);
02034     $this->Body = $message;
02035     $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
02036     if (!empty($textMsg) && empty($this->AltBody)) {
02037       $this->AltBody = html_entity_decode($textMsg);
02038     }
02039     if (empty($this->AltBody)) {
02040       $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
02041     }
02042   }

static PHPMailer::RFCDate (  )  [static]

Returns the proper RFC 822 formatted date.

public

Returns:
string

Definition at line 1934 of file PHPMailer.php.

01934                                    {
01935     $tz = date('Z');
01936     $tzs = ($tz < 0) ? '-' : '+';
01937     $tz = abs($tz);
01938     $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
01939     $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
01940 
01941     return $result;
01942   }

PHPMailer::SecureHeader ( str  ) 

Strips newlines to prevent header injection.

public

Parameters:
string $str String
Returns:
string

Definition at line 2178 of file PHPMailer.php.

Referenced by AddrFormat(), AttachAll(), CreateHeader(), and MailSend().

02178                                      {
02179     $str = str_replace("\r", '', $str);
02180     $str = str_replace("\n", '', $str);
02181     return trim($str);
02182   }

PHPMailer::Send (  ) 

Creates message and assigns Mailer.

If the message is not sent successfully then it returns false. Use the ErrorInfo variable to view description of the error.

Returns:
bool

Definition at line 555 of file PHPMailer.php.

00555                          {
00556     try {
00557       if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
00558         throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
00559       }
00560 
00561       // Set whether the message is multipart/alternative
00562       if(!empty($this->AltBody)) {
00563         $this->ContentType = 'multipart/alternative';
00564       }
00565 
00566       $this->error_count = 0; // reset errors
00567       $this->SetMessageType();
00568       $header = $this->CreateHeader();
00569       $body = $this->CreateBody();
00570 
00571       if (empty($this->Body)) {
00572         throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
00573       }
00574 
00575       // digitally sign with DKIM if enabled
00576       if ($this->DKIM_domain && $this->DKIM_private) {
00577         $header_dkim = $this->DKIM_Add($header,$this->Subject,$body);
00578         $header = str_replace("\r\n","\n",$header_dkim) . $header;
00579       }
00580 
00581       // Choose the mailer and send through it
00582       switch($this->Mailer) {
00583         case 'sendmail':
00584           return $this->SendmailSend($header, $body);
00585         case 'smtp':
00586           return $this->SmtpSend($header, $body);
00587         default:
00588           return $this->MailSend($header, $body);
00589       }
00590 
00591     } catch (phpmailerException $e) {
00592       $this->SetError($e->getMessage());
00593       if ($this->exceptions) {
00594         throw $e;
00595       }
00596       echo $e->getMessage()."\n";
00597       return false;
00598     }
00599   }

PHPMailer::SendmailSend ( header,
body 
) [protected]

Sends mail using the $Sendmail program.

Parameters:
string $header The message headers
string $body The message body protected
Returns:
bool

Definition at line 608 of file PHPMailer.php.

Referenced by Send().

00608                                                   {
00609     if ($this->Sender != '') {
00610       $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
00611     } else {
00612       $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
00613     }
00614     if ($this->SingleTo === true) {
00615       foreach ($this->SingleToArray as $key => $val) {
00616         if(!@$mail = popen($sendmail, 'w')) {
00617           throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
00618         }
00619         fputs($mail, "To: " . $val . "\n");
00620         fputs($mail, $header);
00621         fputs($mail, $body);
00622         $result = pclose($mail);
00623         // implement call back function if it exists
00624         $isSent = ($result == 0) ? 1 : 0;
00625         $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
00626         if($result != 0) {
00627           throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
00628         }
00629       }
00630     } else {
00631       if(!@$mail = popen($sendmail, 'w')) {
00632         throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
00633       }
00634       fputs($mail, $header);
00635       fputs($mail, $body);
00636       $result = pclose($mail);
00637       // implement call back function if it exists
00638       $isSent = ($result == 0) ? 1 : 0;
00639       $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);
00640       if($result != 0) {
00641         throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
00642       }
00643     }
00644     return true;
00645   }

PHPMailer::ServerHostname (  )  [private]

Returns the server hostname or 'localhost.localdomain' if unknown.

private

Returns:
string

Definition at line 1949 of file PHPMailer.php.

Referenced by CreateHeader(), and SmtpConnect().

01949                                     {
01950     if (!empty($this->Hostname)) {
01951       $result = $this->Hostname;
01952     } elseif (isset($_SERVER['SERVER_NAME'])) {
01953       $result = $_SERVER['SERVER_NAME'];
01954     } else {
01955       $result = 'localhost.localdomain';
01956     }
01957 
01958     return $result;
01959   }

PHPMailer::set ( name,
value = '' 
)

Set (or reset) Class Objects (variables).

Usage Example: $page->set('X-Priority', '3');

public

Parameters:
string $name Parameter Name
mixed $value Parameter Value NOTE: will not work with arrays, there are no arrays to set/reset
Todo:
Should this not be using __set() magic function?

Definition at line 2156 of file PHPMailer.php.

02156                                           {
02157     try {
02158       if (isset($this->$name) ) {
02159         $this->$name = $value;
02160       } else {
02161         throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL);
02162       }
02163     } catch (Exception $e) {
02164       $this->SetError($e->getMessage());
02165       if ($e->getCode() == self::STOP_CRITICAL) {
02166         return false;
02167       }
02168     }
02169     return true;
02170   }

PHPMailer::SetError ( msg  )  [protected]

Adds the error message to the error container.

protected

Returns:
void

Definition at line 1917 of file PHPMailer.php.

Referenced by AddAnAddress(), AddAttachment(), AddEmbeddedImage(), EncodeFile(), EncodeString(), Send(), set(), and SetFrom().

01917                                     {
01918     $this->error_count++;
01919     if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
01920       $lasterror = $this->smtp->getError();
01921       if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
01922         $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
01923       }
01924     }
01925     $this->ErrorInfo = $msg;
01926   }

PHPMailer::SetFrom ( address,
name = '',
auto = 1 
)

Set the From and FromName properties.

Parameters:
string $address
string $name
Returns:
boolean

Definition at line 498 of file PHPMailer.php.

00498                                                         {
00499     $address = trim($address);
00500     $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
00501     if (!self::ValidateAddress($address)) {
00502       $this->SetError($this->Lang('invalid_address').': '. $address);
00503       if ($this->exceptions) {
00504         throw new phpmailerException($this->Lang('invalid_address').': '.$address);
00505       }
00506       echo $this->Lang('invalid_address').': '.$address;
00507       return false;
00508     }
00509     $this->From = $address;
00510     $this->FromName = $name;
00511     if ($auto) {
00512       if (empty($this->ReplyTo)) {
00513         $this->AddAnAddress('ReplyTo', $address, $name);
00514       }
00515       if (empty($this->Sender)) {
00516         $this->Sender = $address;
00517       }
00518     }
00519     return true;
00520   }

PHPMailer::SetLanguage ( langcode = 'en',
lang_path = 'language/' 
)

Sets the language for all class error messages.

Returns false if it cannot load the language file. The default language is English.

Parameters:
string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
string $lang_path Path to the language file directory public

Definition at line 860 of file PHPMailer.php.

Referenced by Lang().

00860                                                                    {
00861     //Define full set of translatable strings
00862     $PHPMAILER_LANG = array(
00863       'provide_address' => 'You must provide at least one recipient email address.',
00864       'mailer_not_supported' => ' mailer is not supported.',
00865       'execute' => 'Could not execute: ',
00866       'instantiate' => 'Could not instantiate mail function.',
00867       'authenticate' => 'SMTP Error: Could not authenticate.',
00868       'from_failed' => 'The following From address failed: ',
00869       'recipients_failed' => 'SMTP Error: The following recipients failed: ',
00870       'data_not_accepted' => 'SMTP Error: Data not accepted.',
00871       'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
00872       'file_access' => 'Could not access file: ',
00873       'file_open' => 'File Error: Could not open file: ',
00874       'encoding' => 'Unknown encoding: ',
00875       'signing' => 'Signing Error: ',
00876       'smtp_error' => 'SMTP server error: ',
00877       'empty_message' => 'Message body empty',
00878       'invalid_address' => 'Invalid address',
00879       'variable_set' => 'Cannot set or reset variable: '
00880     );
00881     //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"!
00882     $l = true;
00883     if ($langcode != 'en') { //There is no English translation file
00884       $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php';
00885     }
00886     $this->language = $PHPMAILER_LANG;
00887     return ($l == true); //Returns false if language not found
00888   }

PHPMailer::SetMessageType (  )  [private]

Sets the message type.

private

Returns:
void

Definition at line 1306 of file PHPMailer.php.

Referenced by Send().

01306                                     {
01307     if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
01308       $this->message_type = 'plain';
01309     } else {
01310       if(count($this->attachment) > 0) {
01311         $this->message_type = 'attachments';
01312       }
01313       if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
01314         $this->message_type = 'alt';
01315       }
01316       if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
01317         $this->message_type = 'alt_attachments';
01318       }
01319     }
01320   }

PHPMailer::SetWordWrap (  ) 

Set the body wrapping.

public

Returns:
void

Definition at line 1062 of file PHPMailer.php.

Referenced by CreateBody().

01062                                 {
01063     if($this->WordWrap < 1) {
01064       return;
01065     }
01066 
01067     switch($this->message_type) {
01068       case 'alt':
01069       case 'alt_attachments':
01070         $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
01071         break;
01072       default:
01073         $this->Body = $this->WrapText($this->Body, $this->WordWrap);
01074         break;
01075     }
01076   }

PHPMailer::Sign ( cert_filename,
key_filename,
key_pass 
)

Set the private key file and password to sign the message.

public

Parameters:
string $key_filename Parameter File Name
string $key_pass Password for private key

Definition at line 2191 of file PHPMailer.php.

02191                                                                  {
02192     $this->sign_cert_file = $cert_filename;
02193     $this->sign_key_file = $key_filename;
02194     $this->sign_key_pass = $key_pass;
02195   }

PHPMailer::SmtpClose (  ) 

Closes the active SMTP session if one exists.

Returns:
void

Definition at line 844 of file PHPMailer.php.

00844                               {
00845     if(!is_null($this->smtp)) {
00846       if($this->smtp->Connected()) {
00847         $this->smtp->Quit();
00848         $this->smtp->Close();
00849       }
00850     }
00851   }

PHPMailer::SmtpConnect (  ) 

Initiates a connection to an SMTP server.

Returns false if the operation failed. SMTP public

Returns:
bool

Definition at line 782 of file PHPMailer.php.

Referenced by SmtpSend().

00782                                 {
00783     if(is_null($this->smtp)) {
00784       $this->smtp = new SMTP();
00785     }
00786 
00787     $this->smtp->do_debug = $this->SMTPDebug;
00788     $hosts = explode(';', $this->Host);
00789     $index = 0;
00790     $connection = $this->smtp->Connected();
00791 
00792     // Retry while there is no connection
00793     try {
00794       while($index < count($hosts) && !$connection) {
00795         $hostinfo = array();
00796         if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
00797           $host = $hostinfo[1];
00798           $port = $hostinfo[2];
00799         } else {
00800           $host = $hosts[$index];
00801           $port = $this->Port;
00802         }
00803 
00804         $tls = ($this->SMTPSecure == 'tls');
00805         $ssl = ($this->SMTPSecure == 'ssl');
00806 
00807         if ($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) {
00808 
00809           $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname());
00810           $this->smtp->Hello($hello);
00811 
00812           if ($tls) {
00813             if (!$this->smtp->StartTLS()) {
00814               throw new phpmailerException($this->Lang('tls'));
00815             }
00816 
00817             //We must resend HELO after tls negotiation
00818             $this->smtp->Hello($hello);
00819           }
00820 
00821           $connection = true;
00822           if ($this->SMTPAuth) {
00823             if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
00824               throw new phpmailerException($this->Lang('authenticate'));
00825             }
00826           }
00827         }
00828         $index++;
00829         if (!$connection) {
00830           throw new phpmailerException($this->Lang('connect_host'));
00831         }
00832       }
00833     } catch (phpmailerException $e) {
00834       $this->smtp->Reset();
00835       throw $e;
00836     }
00837     return true;
00838   }

PHPMailer::SmtpSend ( header,
body 
) [protected]

Sends mail via SMTP using PhpSMTP Returns false if there is a bad MAIL FROM, RCPT, or DATA input.

Parameters:
string $header The message headers
string $body The message body SMTP protected
Returns:
bool

Definition at line 711 of file PHPMailer.php.

Referenced by Send().

00711                                               {
00712     require_once $this->PluginDir . 'class.smtp.php';
00713     $bad_rcpt = array();
00714 
00715     if(!$this->SmtpConnect()) {
00716       throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL);
00717     }
00718     $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
00719     if(!$this->smtp->Mail($smtp_from)) {
00720       throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL);
00721     }
00722 
00723     // Attempt to send attach all recipients
00724     foreach($this->to as $to) {
00725       if (!$this->smtp->Recipient($to[0])) {
00726         $bad_rcpt[] = $to[0];
00727         // implement call back function if it exists
00728         $isSent = 0;
00729         $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
00730       } else {
00731         // implement call back function if it exists
00732         $isSent = 1;
00733         $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
00734       }
00735     }
00736     foreach($this->cc as $cc) {
00737       if (!$this->smtp->Recipient($cc[0])) {
00738         $bad_rcpt[] = $cc[0];
00739         // implement call back function if it exists
00740         $isSent = 0;
00741         $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
00742       } else {
00743         // implement call back function if it exists
00744         $isSent = 1;
00745         $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
00746       }
00747     }
00748     foreach($this->bcc as $bcc) {
00749       if (!$this->smtp->Recipient($bcc[0])) {
00750         $bad_rcpt[] = $bcc[0];
00751         // implement call back function if it exists
00752         $isSent = 0;
00753         $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
00754       } else {
00755         // implement call back function if it exists
00756         $isSent = 1;
00757         $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
00758       }
00759     }
00760 
00761 
00762     if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses
00763       $badaddresses = implode(', ', $bad_rcpt);
00764       throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses);
00765     }
00766     if(!$this->smtp->Data($header . $body)) {
00767       throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL);
00768     }
00769     if($this->SMTPKeepAlive == true) {
00770       $this->smtp->Reset();
00771     }
00772     return true;
00773   }

PHPMailer::TextLine ( value  ) 

Returns a formatted mail line.

public

Returns:
string

Definition at line 1336 of file PHPMailer.php.

Referenced by GetBoundary(), and GetMailMIME().

01336                                    {
01337     return $value . $this->LE;
01338   }

PHPMailer::UTF8CharBoundary ( encodedText,
maxLength 
)

Finds last character boundary prior to maxLength in a utf-8 quoted (printable) encoded string.

Original written by Colin Brown. public

Parameters:
string $encodedText utf-8 QP text
int $maxLength find last character boundary prior to this length
Returns:
int

Definition at line 1024 of file PHPMailer.php.

Referenced by WrapText().

01024                                                              {
01025     $foundSplitPos = false;
01026     $lookBack = 3;
01027     while (!$foundSplitPos) {
01028       $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
01029       $encodedCharPos = strpos($lastChunk, "=");
01030       if ($encodedCharPos !== false) {
01031         // Found start of encoded character byte within $lookBack block.
01032         // Check the encoded byte value (the 2 chars after the '=')
01033         $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
01034         $dec = hexdec($hex);
01035         if ($dec < 128) { // Single byte character.
01036           // If the encoded char was found at pos 0, it will fit
01037           // otherwise reduce maxLength to start of the encoded char
01038           $maxLength = ($encodedCharPos == 0) ? $maxLength :
01039           $maxLength - ($lookBack - $encodedCharPos);
01040           $foundSplitPos = true;
01041         } elseif ($dec >= 192) { // First byte of a multi byte character
01042           // Reduce maxLength to split at start of character
01043           $maxLength = $maxLength - ($lookBack - $encodedCharPos);
01044           $foundSplitPos = true;
01045         } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
01046           $lookBack += 3;
01047         }
01048       } else {
01049         // No encoded character found
01050         $foundSplitPos = true;
01051       }
01052     }
01053     return $maxLength;
01054   }

static PHPMailer::ValidateAddress ( address  )  [static]

Check that a string looks roughly like an email address should Static so it can be used without instantiation Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator Conforms approximately to RFC2822 Original pattern found here.

Parameters:
string $address The email address to check
Returns:
boolean public

Definition at line 533 of file PHPMailer.php.

00533                                                    {
00534     if (function_exists('filter_var')) { //Introduced in PHP 5.2
00535       if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
00536         return false;
00537       } else {
00538         return true;
00539       }
00540     } else {
00541       return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
00542     }
00543   }

PHPMailer::WrapText ( message,
length,
qp_mode = false 
)

Wraps message for use with mailers that do not automatically perform wrapping and for quoted-printable.

Original written by philippe.

Parameters:
string $message The message to wrap
integer $length The line length to wrap to
boolean $qp_mode Whether to run in Quoted-Printable mode public
Returns:
string

Definition at line 942 of file PHPMailer.php.

Referenced by EncodeHeader(), and SetWordWrap().

00942                                                                 {
00943     $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
00944     // If utf-8 encoding is used, we will need to make sure we don't
00945     // split multibyte characters when we wrap
00946     $is_utf8 = (strtolower($this->CharSet) == "utf-8");
00947 
00948     $message = $this->FixEOL($message);
00949     if (substr($message, -1) == $this->LE) {
00950       $message = substr($message, 0, -1);
00951     }
00952 
00953     $line = explode($this->LE, $message);
00954     $message = '';
00955     for ($i=0 ;$i < count($line); $i++) {
00956       $line_part = explode(' ', $line[$i]);
00957       $buf = '';
00958       for ($e = 0; $e<count($line_part); $e++) {
00959         $word = $line_part[$e];
00960         if ($qp_mode and (strlen($word) > $length)) {
00961           $space_left = $length - strlen($buf) - 1;
00962           if ($e != 0) {
00963             if ($space_left > 20) {
00964               $len = $space_left;
00965               if ($is_utf8) {
00966                 $len = $this->UTF8CharBoundary($word, $len);
00967               } elseif (substr($word, $len - 1, 1) == "=") {
00968                 $len--;
00969               } elseif (substr($word, $len - 2, 1) == "=") {
00970                 $len -= 2;
00971               }
00972               $part = substr($word, 0, $len);
00973               $word = substr($word, $len);
00974               $buf .= ' ' . $part;
00975               $message .= $buf . sprintf("=%s", $this->LE);
00976             } else {
00977               $message .= $buf . $soft_break;
00978             }
00979             $buf = '';
00980           }
00981           while (strlen($word) > 0) {
00982             $len = $length;
00983             if ($is_utf8) {
00984               $len = $this->UTF8CharBoundary($word, $len);
00985             } elseif (substr($word, $len - 1, 1) == "=") {
00986               $len--;
00987             } elseif (substr($word, $len - 2, 1) == "=") {
00988               $len -= 2;
00989             }
00990             $part = substr($word, 0, $len);
00991             $word = substr($word, $len);
00992 
00993             if (strlen($word) > 0) {
00994               $message .= $part . sprintf("=%s", $this->LE);
00995             } else {
00996               $buf = $part;
00997             }
00998           }
00999         } else {
01000           $buf_o = $buf;
01001           $buf .= ($e == 0) ? $word : (' ' . $word);
01002 
01003           if (strlen($buf) > $length and $buf_o != '') {
01004             $message .= $buf_o . $soft_break;
01005             $buf = $word;
01006           }
01007         }
01008       }
01009       $message .= $buf . $this->LE;
01010     }
01011 
01012     return $message;
01013   }


Member Data Documentation

PHPMailer::$action_function = ''

Definition at line 307 of file PHPMailer.php.

PHPMailer::$all_recipients = array() [private]

Definition at line 324 of file PHPMailer.php.

PHPMailer::$AltBody = ''

Definition at line 129 of file PHPMailer.php.

PHPMailer::$attachment = array() [private]

Definition at line 325 of file PHPMailer.php.

Referenced by AttachAll(), and InlineImageExists().

PHPMailer::$bcc = array() [private]

Definition at line 322 of file PHPMailer.php.

Referenced by ClearBCCs(), doCallback(), and SmtpSend().

PHPMailer::$Body = ''

Definition at line 120 of file PHPMailer.php.

PHPMailer::$boundary = array() [private]

Definition at line 328 of file PHPMailer.php.

Referenced by EndBoundary(), and GetBoundary().

PHPMailer::$cc = array() [private]

Definition at line 321 of file PHPMailer.php.

Referenced by ClearCCs(), doCallback(), and SmtpSend().

PHPMailer::$CharSet = 'iso-8859-1'

Definition at line 69 of file PHPMailer.php.

PHPMailer::$ConfirmReadingTo = ''

Definition at line 161 of file PHPMailer.php.

PHPMailer::$ContentType = 'text/plain'

Definition at line 75 of file PHPMailer.php.

PHPMailer::$CustomHeader = array() [private]

Definition at line 326 of file PHPMailer.php.

PHPMailer::$DKIM_domain = ''

Definition at line 287 of file PHPMailer.php.

PHPMailer::$DKIM_identity = ''

Definition at line 280 of file PHPMailer.php.

PHPMailer::$DKIM_private = ''

Definition at line 294 of file PHPMailer.php.

PHPMailer::$DKIM_selector = 'phpmailer'

Definition at line 273 of file PHPMailer.php.

PHPMailer::$Encoding = '8bit'

Definition at line 82 of file PHPMailer.php.

PHPMailer::$error_count = 0 [private]

Definition at line 330 of file PHPMailer.php.

PHPMailer::$ErrorInfo = ''

Definition at line 88 of file PHPMailer.php.

PHPMailer::$exceptions = false [private]

Definition at line 334 of file PHPMailer.php.

Referenced by __construct().

PHPMailer::$From = 'root@localhost'

Definition at line 94 of file PHPMailer.php.

PHPMailer::$FromName = 'Root User'

Definition at line 100 of file PHPMailer.php.

PHPMailer::$Helo = ''

Definition at line 202 of file PHPMailer.php.

PHPMailer::$Host = 'localhost'

Definition at line 190 of file PHPMailer.php.

PHPMailer::$Hostname = ''

Definition at line 169 of file PHPMailer.php.

PHPMailer::$language = array() [protected]

Definition at line 329 of file PHPMailer.php.

PHPMailer::$LE = "\n"

Definition at line 267 of file PHPMailer.php.

PHPMailer::$Mailer = 'mail'

Definition at line 142 of file PHPMailer.php.

PHPMailer::$message_type = '' [private]

Definition at line 327 of file PHPMailer.php.

PHPMailer::$MessageID = ''

Definition at line 176 of file PHPMailer.php.

PHPMailer::$Password = ''

Definition at line 227 of file PHPMailer.php.

PHPMailer::$PluginDir = 'mailer_drivers/'

Definition at line 155 of file PHPMailer.php.

PHPMailer::$Port = 25

Definition at line 196 of file PHPMailer.php.

PHPMailer::$Priority = 3

Definition at line 63 of file PHPMailer.php.

PHPMailer::$ReplyTo = array() [private]

Definition at line 323 of file PHPMailer.php.

PHPMailer::$Sender = ''

Definition at line 107 of file PHPMailer.php.

PHPMailer::$Sendmail = '/usr/sbin/sendmail'

Definition at line 148 of file PHPMailer.php.

PHPMailer::$sign_cert_file = "" [private]

Definition at line 331 of file PHPMailer.php.

PHPMailer::$sign_key_file = "" [private]

Definition at line 332 of file PHPMailer.php.

PHPMailer::$sign_key_pass = "" [private]

Definition at line 333 of file PHPMailer.php.

PHPMailer::$SingleTo = false

Definition at line 255 of file PHPMailer.php.

PHPMailer::$SingleToArray = array()

Definition at line 261 of file PHPMailer.php.

PHPMailer::$smtp = NULL [private]

Definition at line 319 of file PHPMailer.php.

PHPMailer::$SMTPAuth = false

Definition at line 215 of file PHPMailer.php.

PHPMailer::$SMTPDebug = false

Definition at line 240 of file PHPMailer.php.

PHPMailer::$SMTPKeepAlive = false

Definition at line 248 of file PHPMailer.php.

PHPMailer::$SMTPSecure = ''

Definition at line 209 of file PHPMailer.php.

PHPMailer::$Subject = ''

Definition at line 113 of file PHPMailer.php.

PHPMailer::$Timeout = 10

Definition at line 234 of file PHPMailer.php.

PHPMailer::$to = array() [private]

Definition at line 320 of file PHPMailer.php.

Referenced by ClearAddresses(), DKIM_Add(), doCallback(), MailSend(), and SmtpSend().

PHPMailer::$Username = ''

Definition at line 221 of file PHPMailer.php.

PHPMailer::$Version = '5.1'

Definition at line 313 of file PHPMailer.php.

PHPMailer::$WordWrap = 0

Definition at line 136 of file PHPMailer.php.

Definition at line 341 of file PHPMailer.php.

Definition at line 342 of file PHPMailer.php.

Definition at line 340 of file PHPMailer.php.


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