ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
PHPMailer Class Reference
+ Inheritance diagram for PHPMailer:
+ Collaboration diagram for PHPMailer:

Public Member Functions

 __construct ($exceptions=null)
 Constructor. More...
 
 __destruct ()
 Destructor. More...
 
 isHTML ($isHtml=true)
 Sets message type to HTML or plain. More...
 
 isSMTP ()
 Send messages using SMTP. More...
 
 isMail ()
 Send messages using PHP's mail() function. More...
 
 isSendmail ()
 Send messages using $Sendmail. More...
 
 isQmail ()
 Send messages using qmail. More...
 
 addAddress ($address, $name='')
 Add a "To" address. More...
 
 addCC ($address, $name='')
 Add a "CC" address. More...
 
 addBCC ($address, $name='')
 Add a "BCC" address. More...
 
 addReplyTo ($address, $name='')
 Add a "Reply-To" address. More...
 
 parseAddresses ($addrstr, $useimap=true)
 Parse and validate a string containing one or more RFC822-style comma-separated email addresses of the form "display name <address>" into an array of name/address pairs. More...
 
 setFrom ($address, $name='', $auto=true)
 Set the From and FromName properties. More...
 
 getLastMessageID ()
 Return the Message-ID header of the last email. More...
 
 idnSupported ()
 Tells whether IDNs (Internationalized Domain Names) are supported or not. More...
 
 punyencodeAddress ($address)
 Converts IDN in given email address to its ASCII form, also known as punycode, if possible. More...
 
 send ()
 Create a message and send it. More...
 
 preSend ()
 Prepare a message for sending. More...
 
 postSend ()
 Actually send a message. More...
 
 getSMTPInstance ()
 Get an instance to use for SMTP operations. More...
 
 smtpConnect ($options=null)
 Initiate a connection to an SMTP server. More...
 
 smtpClose ()
 Close the active SMTP session if one exists. More...
 
 setLanguage ($langcode='en', $lang_path='')
 Set the language for error messages. More...
 
 getTranslations ()
 Get the array of strings for the current language. More...
 
 addrAppend ($type, $addr)
 Create recipient headers. More...
 
 addrFormat ($addr)
 Format an address for use in a message header. More...
 
 wrapText ($message, $length, $qp_mode=false)
 Word-wrap message. More...
 
 utf8CharBoundary ($encodedText, $maxLength)
 Find the last character boundary prior to $maxLength in a utf-8 quoted-printable encoded string. More...
 
 setWordWrap ()
 Apply word wrapping to the message body. More...
 
 createHeader ()
 Assemble message headers. More...
 
 getMailMIME ()
 Get the message MIME type headers. More...
 
 getSentMIMEMessage ()
 Returns the whole MIME message. More...
 
 createBody ()
 Assemble the message body. More...
 
 headerLine ($name, $value)
 Format a header line. More...
 
 textLine ($value)
 Return a formatted mail line. More...
 
 addAttachment ($path, $name='', $encoding='base64', $type='', $disposition='attachment')
 Add an attachment from a path on the filesystem. More...
 
 getAttachments ()
 Return the array of attachments. More...
 
 encodeString ($str, $encoding='base64')
 Encode a string in requested format. More...
 
 encodeHeader ($str, $position='text')
 Encode a header string optimally. More...
 
 hasMultiBytes ($str)
 Check if a string contains multi-byte characters. More...
 
 has8bitChars ($text)
 Does a string contain any 8-bit chars (in any charset)? More...
 
 base64EncodeWrapMB ($str, $linebreak=null)
 Encode and wrap long multibyte strings for mail headers without breaking lines within a character. More...
 
 encodeQP ($string, $line_max=76)
 Encode a string in quoted-printable format. More...
 
 encodeQPphp ( $string, $line_max=76, $space_conv=false)
 Backward compatibility wrapper for an old QP encoding function that was removed. More...
 
 encodeQ ($str, $position='text')
 Encode a string using Q encoding. More...
 
 addStringAttachment ( $string, $filename, $encoding='base64', $type='', $disposition='attachment')
 Add a string or binary attachment (non-filesystem). More...
 
 addEmbeddedImage ($path, $cid, $name='', $encoding='base64', $type='', $disposition='inline')
 Add an embedded (inline) attachment from a file. More...
 
 addStringEmbeddedImage ( $string, $cid, $name='', $encoding='base64', $type='', $disposition='inline')
 Add an embedded stringified attachment. More...
 
 inlineImageExists ()
 Check if an inline attachment is present. More...
 
 attachmentExists ()
 Check if an attachment (non-inline) is present. More...
 
 alternativeExists ()
 Check if this message has an alternative body set. More...
 
 clearQueuedAddresses ($kind)
 Clear queued addresses of given kind. More...
 
 clearAddresses ()
 Clear all To recipients. More...
 
 clearCCs ()
 Clear all CC recipients. More...
 
 clearBCCs ()
 Clear all BCC recipients. More...
 
 clearReplyTos ()
 Clear all ReplyTo recipients. More...
 
 clearAllRecipients ()
 Clear all recipient types. More...
 
 clearAttachments ()
 Clear all filesystem, string, and binary attachments. More...
 
 clearCustomHeaders ()
 Clear all custom headers. More...
 
 isError ()
 Check if an error occurred. More...
 
 fixEOL ($str)
 Ensure consistent line endings in a string. More...
 
 addCustomHeader ($name, $value=null)
 Add a custom header. More...
 
 getCustomHeaders ()
 Returns all custom headers. More...
 
 msgHTML ($message, $basedir='', $advanced=false)
 Create a message body from an HTML string. More...
 
 html2text ($html, $advanced=false)
 Convert an HTML string into plain text. More...
 
 set ($name, $value='')
 Set or reset instance properties. More...
 
 secureHeader ($str)
 Strip newlines to prevent header injection. More...
 
 sign ($cert_filename, $key_filename, $key_pass, $extracerts_filename='')
 Set the public and private key files and password for S/MIME signing. More...
 
 DKIM_QP ($txt)
 Quoted-Printable-encode a DKIM header. More...
 
 DKIM_Sign ($signHeader)
 Generate a DKIM signature. More...
 
 DKIM_HeaderC ($signHeader)
 Generate a DKIM canonicalization header. More...
 
 DKIM_BodyC ($body)
 Generate a DKIM canonicalization body. More...
 
 DKIM_Add ($headers_line, $subject, $body)
 Create the DKIM header and body in a new message header. More...
 
 getToAddresses ()
 Allows for public read access to 'to' property. More...
 
 getCcAddresses ()
 Allows for public read access to 'cc' property. More...
 
 getBccAddresses ()
 Allows for public read access to 'bcc' property. More...
 
 getReplyToAddresses ()
 Allows for public read access to 'ReplyTo' property. More...
 
 getAllRecipientAddresses ()
 Allows for public read access to 'all_recipients' property. More...
 

Static Public Member Functions

static validateAddress ($address, $patternselect=null)
 Check that a string looks like an email address. More...
 
static rfcDate ()
 Return an RFC 822 formatted date. More...
 
static _mime_types ($ext='')
 Get the MIME type for a file extension. More...
 
static filenameToType ($filename)
 Map a file name to a MIME type. More...
 
static mb_pathinfo ($path, $options=null)
 Multi-byte-safe pathinfo replacement. More...
 
static normalizeBreaks ($text, $breaktype="\r\n")
 Normalize line breaks in a string. More...
 
static hasLineLongerThanMax ($str)
 Detect if a string contains a line longer than the maximum line length allowed. More...
 

Data Fields

 $Version = '5.2.22'
 
 $Priority = null
 
 $CharSet = 'iso-8859-1'
 
 $ContentType = 'text/plain'
 
 $Encoding = '8bit'
 
 $ErrorInfo = ''
 
 $From = 'root@localhost'
 
 $FromName = 'Root User'
 
 $Sender = ''
 
 $ReturnPath = ''
 
 $Subject = ''
 
 $Body = ''
 
 $AltBody = ''
 
 $Ical = ''
 
 $WordWrap = 0
 
 $Mailer = 'mail'
 
 $Sendmail = '/usr/sbin/sendmail'
 
 $UseSendmailOptions = true
 
 $PluginDir = ''
 
 $ConfirmReadingTo = ''
 
 $Hostname = ''
 
 $MessageID = ''
 
 $MessageDate = ''
 
 $Host = 'localhost'
 
 $Port = 25
 
 $Helo = ''
 
 $SMTPSecure = ''
 
 $SMTPAutoTLS = true
 
 $SMTPAuth = false
 
 $SMTPOptions = array()
 
 $Username = ''
 
 $Password = ''
 
 $AuthType = ''
 
 $Realm = ''
 
 $Workstation = ''
 
 $Timeout = 300
 
 $SMTPDebug = 0
 
 $Debugoutput = 'echo'
 
 $SMTPKeepAlive = false
 
 $SingleTo = false
 
 $SingleToArray = array()
 
 $do_verp = false
 
 $AllowEmpty = false
 
 $LE = "\n"
 
 $DKIM_selector = ''
 
 $DKIM_identity = ''
 
 $DKIM_passphrase = ''
 
 $DKIM_domain = ''
 
 $DKIM_private = ''
 
 $DKIM_private_string = ''
 
 $action_function = ''
 
 $XMailer = ''
 
const STOP_MESSAGE = 0
 Error severity: message only, continue processing. More...
 
const STOP_CONTINUE = 1
 Error severity: message, likely ok to continue processing. More...
 
const STOP_CRITICAL = 2
 Error severity: message, plus full stop, critical error reached. More...
 
const CRLF = "\r\n"
 SMTP RFC standard line ending. More...
 
const MAX_LINE_LENGTH = 998
 

Static Public Attributes

static $validator = 'auto'
 

Protected Member Functions

 edebug ($str)
 Output debugging info via user-defined method. More...
 
 addOrEnqueueAnAddress ($kind, $address, $name)
 Add an address to one of the recipient arrays or to the ReplyTo array. More...
 
 addAnAddress ($kind, $address, $name='')
 Add an address to one of the recipient arrays or to the ReplyTo array. More...
 
 sendmailSend ($header, $body)
 Send mail using the $Sendmail program. More...
 
 mailSend ($header, $body)
 Send mail using the PHP mail() function. More...
 
 smtpSend ($header, $body)
 Send mail via SMTP. More...
 
 generateId ()
 Create unique ID. More...
 
 getBoundary ($boundary, $charSet, $contentType, $encoding)
 Return the start of a message boundary. More...
 
 endBoundary ($boundary)
 Return the end of a message boundary. More...
 
 setMessageType ()
 Set the message type. More...
 
 attachAll ($disposition_type, $boundary)
 Attach all file, string, and binary attachments to the message. More...
 
 encodeFile ($path, $encoding='base64')
 Encode a file attachment in requested format. More...
 
 setError ($msg)
 Add an error message to the error container. More...
 
 serverHostname ()
 Get the server hostname. More...
 
 lang ($key)
 Get an error message in the current language. More...
 
 doCallback ($isSent, $to, $cc, $bcc, $subject, $body, $from)
 Perform a callback. More...
 

Static Protected Member Functions

static isShellSafe ($string)
 Fix CVE-2016-10033 and CVE-2016-10045 by disallowing potentially unsafe shell characters. More...
 

Protected Attributes

 $MIMEBody = ''
 
 $MIMEHeader = ''
 
 $mailHeader = ''
 
 $smtp = null
 
 $to = array()
 
 $cc = array()
 
 $bcc = array()
 
 $ReplyTo = array()
 
 $all_recipients = array()
 
 $RecipientsQueue = array()
 
 $ReplyToQueue = array()
 
 $attachment = array()
 
 $CustomHeader = array()
 
 $lastMessageID = ''
 
 $message_type = ''
 
 $boundary = array()
 
 $language = array()
 
 $error_count = 0
 
 $sign_cert_file = ''
 
 $sign_key_file = ''
 
 $sign_extracerts_file = ''
 
 $sign_key_pass = ''
 
 $exceptions = false
 
 $uniqueid = ''
 

Private Member Functions

 mailPassthru ($to, $subject, $body, $header, $params)
 Call mail() in a safe_mode-aware fashion. More...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

PHPMailer::__construct (   $exceptions = null)

Constructor.

Parameters
boolean$exceptionsShould we throw external exceptions?

Definition at line 657 of file class.phpmailer.php.

658 {
659 if ($exceptions !== null) {
660 $this->exceptions = (boolean)$exceptions;
661 }
662 }

References $exceptions.

◆ __destruct()

PHPMailer::__destruct ( )

Destructor.

Definition at line 667 of file class.phpmailer.php.

668 {
669 //Close any open SMTP connection nicely
670 $this->smtpClose();
671 }
smtpClose()
Close the active SMTP session if one exists.

References smtpClose().

+ Here is the call graph for this function:

Member Function Documentation

◆ _mime_types()

static PHPMailer::_mime_types (   $ext = '')
static

Get the MIME type for a file extension.

Parameters
string$extFile extension @access public
Returns
string MIME type of file.

Definition at line 3516 of file class.phpmailer.php.

3517 {
3518 $mimes = array(
3519 'xl' => 'application/excel',
3520 'js' => 'application/javascript',
3521 'hqx' => 'application/mac-binhex40',
3522 'cpt' => 'application/mac-compactpro',
3523 'bin' => 'application/macbinary',
3524 'doc' => 'application/msword',
3525 'word' => 'application/msword',
3526 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
3527 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
3528 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
3529 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
3530 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
3531 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
3532 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
3533 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
3534 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
3535 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
3536 'class' => 'application/octet-stream',
3537 'dll' => 'application/octet-stream',
3538 'dms' => 'application/octet-stream',
3539 'exe' => 'application/octet-stream',
3540 'lha' => 'application/octet-stream',
3541 'lzh' => 'application/octet-stream',
3542 'psd' => 'application/octet-stream',
3543 'sea' => 'application/octet-stream',
3544 'so' => 'application/octet-stream',
3545 'oda' => 'application/oda',
3546 'pdf' => 'application/pdf',
3547 'ai' => 'application/postscript',
3548 'eps' => 'application/postscript',
3549 'ps' => 'application/postscript',
3550 'smi' => 'application/smil',
3551 'smil' => 'application/smil',
3552 'mif' => 'application/vnd.mif',
3553 'xls' => 'application/vnd.ms-excel',
3554 'ppt' => 'application/vnd.ms-powerpoint',
3555 'wbxml' => 'application/vnd.wap.wbxml',
3556 'wmlc' => 'application/vnd.wap.wmlc',
3557 'dcr' => 'application/x-director',
3558 'dir' => 'application/x-director',
3559 'dxr' => 'application/x-director',
3560 'dvi' => 'application/x-dvi',
3561 'gtar' => 'application/x-gtar',
3562 'php3' => 'application/x-httpd-php',
3563 'php4' => 'application/x-httpd-php',
3564 'php' => 'application/x-httpd-php',
3565 'phtml' => 'application/x-httpd-php',
3566 'phps' => 'application/x-httpd-php-source',
3567 'swf' => 'application/x-shockwave-flash',
3568 'sit' => 'application/x-stuffit',
3569 'tar' => 'application/x-tar',
3570 'tgz' => 'application/x-tar',
3571 'xht' => 'application/xhtml+xml',
3572 'xhtml' => 'application/xhtml+xml',
3573 'zip' => 'application/zip',
3574 'mid' => 'audio/midi',
3575 'midi' => 'audio/midi',
3576 'mp2' => 'audio/mpeg',
3577 'mp3' => 'audio/mpeg',
3578 'mpga' => 'audio/mpeg',
3579 'aif' => 'audio/x-aiff',
3580 'aifc' => 'audio/x-aiff',
3581 'aiff' => 'audio/x-aiff',
3582 'ram' => 'audio/x-pn-realaudio',
3583 'rm' => 'audio/x-pn-realaudio',
3584 'rpm' => 'audio/x-pn-realaudio-plugin',
3585 'ra' => 'audio/x-realaudio',
3586 'wav' => 'audio/x-wav',
3587 'bmp' => 'image/bmp',
3588 'gif' => 'image/gif',
3589 'jpeg' => 'image/jpeg',
3590 'jpe' => 'image/jpeg',
3591 'jpg' => 'image/jpeg',
3592 'png' => 'image/png',
3593 'tiff' => 'image/tiff',
3594 'tif' => 'image/tiff',
3595 'eml' => 'message/rfc822',
3596 'css' => 'text/css',
3597 'html' => 'text/html',
3598 'htm' => 'text/html',
3599 'shtml' => 'text/html',
3600 'log' => 'text/plain',
3601 'text' => 'text/plain',
3602 'txt' => 'text/plain',
3603 'rtx' => 'text/richtext',
3604 'rtf' => 'text/rtf',
3605 'vcf' => 'text/vcard',
3606 'vcard' => 'text/vcard',
3607 'xml' => 'text/xml',
3608 'xsl' => 'text/xml',
3609 'mpeg' => 'video/mpeg',
3610 'mpe' => 'video/mpeg',
3611 'mpg' => 'video/mpeg',
3612 'mov' => 'video/quicktime',
3613 'qt' => 'video/quicktime',
3614 'rv' => 'video/vnd.rn-realvideo',
3615 'avi' => 'video/x-msvideo',
3616 'movie' => 'video/x-sgi-movie'
3617 );
3618 if (array_key_exists(strtolower($ext), $mimes)) {
3619 return $mimes[strtolower($ext)];
3620 }
3621 return 'application/octet-stream';
3622 }

Referenced by filenameToType().

+ Here is the caller graph for this function:

◆ addAddress()

PHPMailer::addAddress (   $address,
  $name = '' 
)

Add a "To" address.

Parameters
string$addressThe email address to send to
string$name
Returns
boolean true on success, false if address already used or invalid in some way

Definition at line 823 of file class.phpmailer.php.

824 {
825 return $this->addOrEnqueueAnAddress('to', $address, $name);
826 }
addOrEnqueueAnAddress($kind, $address, $name)
Add an address to one of the recipient arrays or to the ReplyTo array.

References addOrEnqueueAnAddress().

+ Here is the call graph for this function:

◆ addAnAddress()

PHPMailer::addAnAddress (   $kind,
  $address,
  $name = '' 
)
protected

Add an address to one of the recipient arrays or to the ReplyTo array.

Addresses that have been added already return false, but do not throw exceptions.

Parameters
string$kindOne of 'to', 'cc', 'bcc', or 'ReplyTo'
string$addressThe email address to send, resp. to reply to
string$name
Exceptions
phpmailerException
Returns
boolean true on success, false if address already used or invalid in some way @access protected

Definition at line 919 of file class.phpmailer.php.

920 {
921 if (!in_array($kind, array('to', 'cc', 'bcc', 'Reply-To'))) {
922 $error_message = $this->lang('Invalid recipient kind: ') . $kind;
923 $this->setError($error_message);
924 $this->edebug($error_message);
925 if ($this->exceptions) {
926 throw new phpmailerException($error_message);
927 }
928 return false;
929 }
930 if (!$this->validateAddress($address)) {
931 $error_message = $this->lang('invalid_address') . " (addAnAddress $kind): $address";
932 $this->setError($error_message);
933 $this->edebug($error_message);
934 if ($this->exceptions) {
935 throw new phpmailerException($error_message);
936 }
937 return false;
938 }
939 if ($kind != 'Reply-To') {
940 if (!array_key_exists(strtolower($address), $this->all_recipients)) {
941 array_push($this->$kind, array($address, $name));
942 $this->all_recipients[strtolower($address)] = true;
943 return true;
944 }
945 } else {
946 if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
947 $this->ReplyTo[strtolower($address)] = array($address, $name);
948 return true;
949 }
950 }
951 return false;
952 }
lang($key)
Get an error message in the current language.
static validateAddress($address, $patternselect=null)
Check that a string looks like an email address.
setError($msg)
Add an error message to the error container.
edebug($str)
Output debugging info via user-defined method.

References edebug(), lang(), setError(), and validateAddress().

+ Here is the call graph for this function:

◆ addAttachment()

PHPMailer::addAttachment (   $path,
  $name = '',
  $encoding = 'base64',
  $type = '',
  $disposition = 'attachment' 
)

Add an attachment from a path on the filesystem.

Never use a user-supplied path to a file! Returns false if the file could not be found or read.

Parameters
string$pathPath to the attachment.
string$nameOverrides the attachment name.
string$encodingFile encoding (see $Encoding).
string$typeFile extension (MIME) type.
string$dispositionDisposition to use
Exceptions
phpmailerException
Returns
boolean

Definition at line 2511 of file class.phpmailer.php.

2512 {
2513 try {
2514 if (!@is_file($path)) {
2515 throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
2516 }
2517
2518 // If a MIME type is not specified, try to work it out from the file name
2519 if ($type == '') {
2520 $type = self::filenameToType($path);
2521 }
2522
2523 $filename = basename($path);
2524 if ($name == '') {
2525 $name = $filename;
2526 }
2527
2528 $this->attachment[] = array(
2529 0 => $path,
2530 1 => $filename,
2531 2 => $name,
2532 3 => $encoding,
2533 4 => $type,
2534 5 => false, // isStringAttachment
2535 6 => $disposition,
2536 7 => 0
2537 );
2538
2539 } catch (phpmailerException $exc) {
2540 $this->setError($exc->getMessage());
2541 $this->edebug($exc->getMessage());
2542 if ($this->exceptions) {
2543 throw $exc;
2544 }
2545 return false;
2546 }
2547 return true;
2548 }
$filename
Definition: buildRTE.php:89
static filenameToType($filename)
Map a file name to a MIME type.
$path
Definition: index.php:22

References $filename, $path, edebug(), filenameToType(), lang(), and setError().

+ Here is the call graph for this function:

◆ addBCC()

PHPMailer::addBCC (   $address,
  $name = '' 
)

Add a "BCC" address.

Note
: This function works with the SMTP mailer on win32, not with the "mail" mailer.
Parameters
string$addressThe email address to send to
string$name
Returns
boolean true on success, false if address already used or invalid in some way

Definition at line 847 of file class.phpmailer.php.

848 {
849 return $this->addOrEnqueueAnAddress('bcc', $address, $name);
850 }

References addOrEnqueueAnAddress().

+ Here is the call graph for this function:

◆ addCC()

PHPMailer::addCC (   $address,
  $name = '' 
)

Add a "CC" address.

Note
: This function works with the SMTP mailer on win32, not with the "mail" mailer.
Parameters
string$addressThe email address to send to
string$name
Returns
boolean true on success, false if address already used or invalid in some way

Definition at line 835 of file class.phpmailer.php.

836 {
837 return $this->addOrEnqueueAnAddress('cc', $address, $name);
838 }

References addOrEnqueueAnAddress().

+ Here is the call graph for this function:

◆ addCustomHeader()

PHPMailer::addCustomHeader (   $name,
  $value = null 
)

Add a custom header.

$name value can be overloaded to contain both header name and value (name:value) @access public

Parameters
string$nameCustom header name
string$valueHeader value
Returns
void

Definition at line 3368 of file class.phpmailer.php.

3369 {
3370 if ($value === null) {
3371 // Value passed in as name:value
3372 $this->CustomHeader[] = explode(':', $name, 2);
3373 } else {
3374 $this->CustomHeader[] = array($name, $value);
3375 }
3376 }

◆ addEmbeddedImage()

PHPMailer::addEmbeddedImage (   $path,
  $cid,
  $name = '',
  $encoding = 'base64',
  $type = '',
  $disposition = 'inline' 
)

Add an embedded (inline) attachment from a file.

This can include images, sounds, and just about any other document type. These differ from 'regular' attachments in that they are intended to be displayed inline with the message, not just attached for download. This is used in HTML messages that embed the images the HTML refers to using the $cid value. Never use a user-supplied path to a file!

Parameters
string$pathPath to the attachment.
string$cidContent ID of the attachment; Use this to reference the content when using an embedded image in HTML.
string$nameOverrides the attachment name.
string$encodingFile encoding (see $Encoding).
string$typeFile MIME type.
string$dispositionDisposition to use
Returns
boolean True on successfully adding an attachment

Definition at line 3037 of file class.phpmailer.php.

3038 {
3039 if (!@is_file($path)) {
3040 $this->setError($this->lang('file_access') . $path);
3041 return false;
3042 }
3043
3044 // If a MIME type is not specified, try to work it out from the file name
3045 if ($type == '') {
3046 $type = self::filenameToType($path);
3047 }
3048
3049 $filename = basename($path);
3050 if ($name == '') {
3051 $name = $filename;
3052 }
3053
3054 // Append to $attachment array
3055 $this->attachment[] = array(
3056 0 => $path,
3057 1 => $filename,
3058 2 => $name,
3059 3 => $encoding,
3060 4 => $type,
3061 5 => false, // isStringAttachment
3062 6 => $disposition,
3063 7 => $cid
3064 );
3065 return true;
3066 }

References $filename, $path, filenameToType(), lang(), and setError().

Referenced by msgHTML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addOrEnqueueAnAddress()

PHPMailer::addOrEnqueueAnAddress (   $kind,
  $address,
  $name 
)
protected

Add an address to one of the recipient arrays or to the ReplyTo array.

Because PHPMailer can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still be modified after calling this function), addition of such addresses is delayed until send(). Addresses that have been added already return false, but do not throw exceptions.

Parameters
string$kindOne of 'to', 'cc', 'bcc', or 'ReplyTo'
string$addressThe email address to send, resp. to reply to
string$name
Exceptions
phpmailerException
Returns
boolean true on success, false if address already used or invalid in some way @access protected

Definition at line 875 of file class.phpmailer.php.

876 {
877 $address = trim($address);
878 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
879 if (($pos = strrpos($address, '@')) === false) {
880 // At-sign is misssing.
881 $error_message = $this->lang('invalid_address') . " (addAnAddress $kind): $address";
882 $this->setError($error_message);
883 $this->edebug($error_message);
884 if ($this->exceptions) {
885 throw new phpmailerException($error_message);
886 }
887 return false;
888 }
889 $params = array($kind, $address, $name);
890 // Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
891 if ($this->has8bitChars(substr($address, ++$pos)) and $this->idnSupported()) {
892 if ($kind != 'Reply-To') {
893 if (!array_key_exists($address, $this->RecipientsQueue)) {
894 $this->RecipientsQueue[$address] = $params;
895 return true;
896 }
897 } else {
898 if (!array_key_exists($address, $this->ReplyToQueue)) {
899 $this->ReplyToQueue[$address] = $params;
900 return true;
901 }
902 }
903 return false;
904 }
905 // Immediately add standard addresses without IDN.
906 return call_user_func_array(array($this, 'addAnAddress'), $params);
907 }
has8bitChars($text)
Does a string contain any 8-bit chars (in any charset)?
idnSupported()
Tells whether IDNs (Internationalized Domain Names) are supported or not.
$params
Definition: example_049.php:96

References $params, edebug(), has8bitChars(), idnSupported(), lang(), and setError().

Referenced by addAddress(), addBCC(), addCC(), and addReplyTo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addrAppend()

PHPMailer::addrAppend (   $type,
  $addr 
)

Create recipient headers.

@access public

Parameters
string$type
array$addrAn array of recipient, where each recipient is a 2-element indexed array with element 0 containing an address and element 1 containing a name, like: array(array('joe@e.nosp@m.xamp.nosp@m.le.co.nosp@m.m', 'Joe User'), array('zoe@e.nosp@m.xamp.nosp@m.le.co.nosp@m.m', 'Zoe User'))
Returns
string

Definition at line 1823 of file class.phpmailer.php.

1824 {
1825 $addresses = array();
1826 foreach ($addr as $address) {
1827 $addresses[] = $this->addrFormat($address);
1828 }
1829 return $type . ': ' . implode(', ', $addresses) . $this->LE;
1830 }
addrFormat($addr)
Format an address for use in a message header.

References $LE, and addrFormat().

Referenced by createHeader(), and preSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addReplyTo()

PHPMailer::addReplyTo (   $address,
  $name = '' 
)

Add a "Reply-To" address.

Parameters
string$addressThe email address to reply to
string$name
Returns
boolean true on success, false if address already used or invalid in some way

Definition at line 858 of file class.phpmailer.php.

859 {
860 return $this->addOrEnqueueAnAddress('Reply-To', $address, $name);
861 }

References addOrEnqueueAnAddress().

+ Here is the call graph for this function:

◆ addrFormat()

PHPMailer::addrFormat (   $addr)

Format an address for use in a message header.

@access public

Parameters
array$addrA 2-element indexed array, element 0 containing an address, element 1 containing a name like array('joe@e.nosp@m.xamp.nosp@m.le.co.nosp@m.m', 'Joe User')
Returns
string

Definition at line 1839 of file class.phpmailer.php.

1840 {
1841 if (empty($addr[1])) { // No name provided
1842 return $this->secureHeader($addr[0]);
1843 } else {
1844 return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
1845 $addr[0]
1846 ) . '>';
1847 }
1848 }
secureHeader($str)
Strip newlines to prevent header injection.
encodeHeader($str, $position='text')
Encode a header string optimally.

References encodeHeader(), and secureHeader().

Referenced by addrAppend(), createHeader(), and mailSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addStringAttachment()

PHPMailer::addStringAttachment (   $string,
  $filename,
  $encoding = 'base64',
  $type = '',
  $disposition = 'attachment' 
)

Add a string or binary attachment (non-filesystem).

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

Parameters
string$stringString attachment data.
string$filenameName of the attachment.
string$encodingFile encoding (see $Encoding).
string$typeFile extension (MIME) type.
string$dispositionDisposition to use
Returns
void

Definition at line 2996 of file class.phpmailer.php.

3002 {
3003 // If a MIME type is not specified, try to work it out from the file name
3004 if ($type == '') {
3006 }
3007 // Append to $attachment array
3008 $this->attachment[] = array(
3009 0 => $string,
3010 1 => $filename,
3011 2 => basename($filename),
3012 3 => $encoding,
3013 4 => $type,
3014 5 => true, // isStringAttachment
3015 6 => $disposition,
3016 7 => 0
3017 );
3018 }

References $filename, and filenameToType().

+ Here is the call graph for this function:

◆ addStringEmbeddedImage()

PHPMailer::addStringEmbeddedImage (   $string,
  $cid,
  $name = '',
  $encoding = 'base64',
  $type = '',
  $disposition = 'inline' 
)

Add an embedded stringified attachment.

This can include images, sounds, and just about any other document type. Be sure to set the $type to an image type for images: JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'.

Parameters
string$stringThe attachment binary data.
string$cidContent ID of the attachment; Use this to reference the content when using an embedded image in HTML.
string$name
string$encodingFile encoding (see $Encoding).
string$typeMIME type.
string$dispositionDisposition to use
Returns
boolean True on successfully adding an attachment

Definition at line 3082 of file class.phpmailer.php.

3089 {
3090 // If a MIME type is not specified, try to work it out from the name
3091 if ($type == '' and !empty($name)) {
3092 $type = self::filenameToType($name);
3093 }
3094
3095 // Append to $attachment array
3096 $this->attachment[] = array(
3097 0 => $string,
3098 1 => $name,
3099 2 => $name,
3100 3 => $encoding,
3101 4 => $type,
3102 5 => true, // isStringAttachment
3103 6 => $disposition,
3104 7 => $cid
3105 );
3106 return true;
3107 }

References filenameToType().

Referenced by msgHTML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ alternativeExists()

PHPMailer::alternativeExists ( )

Check if this message has an alternative body set.

Returns
boolean

Definition at line 3142 of file class.phpmailer.php.

3143 {
3144 return !empty($this->AltBody);
3145 }

Referenced by msgHTML(), preSend(), and setMessageType().

+ Here is the caller graph for this function:

◆ attachAll()

PHPMailer::attachAll (   $disposition_type,
  $boundary 
)
protected

Attach all file, string, and binary attachments to the message.

Returns an empty string on failure. @access protected

Parameters
string$disposition_type
string$boundary
Returns
string

Definition at line 2567 of file class.phpmailer.php.

2568 {
2569 // Return text of body
2570 $mime = array();
2571 $cidUniq = array();
2572 $incl = array();
2573
2574 // Add all attachments
2575 foreach ($this->attachment as $attachment) {
2576 // Check if it is a valid disposition_filter
2577 if ($attachment[6] == $disposition_type) {
2578 // Check for string attachment
2579 $string = '';
2580 $path = '';
2581 $bString = $attachment[5];
2582 if ($bString) {
2583 $string = $attachment[0];
2584 } else {
2585 $path = $attachment[0];
2586 }
2587
2588 $inclhash = md5(serialize($attachment));
2589 if (in_array($inclhash, $incl)) {
2590 continue;
2591 }
2592 $incl[] = $inclhash;
2593 $name = $attachment[2];
2594 $encoding = $attachment[3];
2595 $type = $attachment[4];
2596 $disposition = $attachment[6];
2597 $cid = $attachment[7];
2598 if ($disposition == 'inline' && array_key_exists($cid, $cidUniq)) {
2599 continue;
2600 }
2601 $cidUniq[$cid] = true;
2602
2603 $mime[] = sprintf('--%s%s', $boundary, $this->LE);
2604 //Only include a filename property if we have one
2605 if (!empty($name)) {
2606 $mime[] = sprintf(
2607 'Content-Type: %s; name="%s"%s',
2608 $type,
2609 $this->encodeHeader($this->secureHeader($name)),
2610 $this->LE
2611 );
2612 } else {
2613 $mime[] = sprintf(
2614 'Content-Type: %s%s',
2615 $type,
2616 $this->LE
2617 );
2618 }
2619 // RFC1341 part 5 says 7bit is assumed if not specified
2620 if ($encoding != '7bit') {
2621 $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
2622 }
2623
2624 if ($disposition == 'inline') {
2625 $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
2626 }
2627
2628 // If a filename contains any of these chars, it should be quoted,
2629 // but not otherwise: RFC2183 & RFC2045 5.1
2630 // Fixes a warning in IETF's msglint MIME checker
2631 // Allow for bypassing the Content-Disposition header totally
2632 if (!(empty($disposition))) {
2633 $encoded_name = $this->encodeHeader($this->secureHeader($name));
2634 if (preg_match('/[ \‍(\‍)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) {
2635 $mime[] = sprintf(
2636 'Content-Disposition: %s; filename="%s"%s',
2637 $disposition,
2638 $encoded_name,
2639 $this->LE . $this->LE
2640 );
2641 } else {
2642 if (!empty($encoded_name)) {
2643 $mime[] = sprintf(
2644 'Content-Disposition: %s; filename=%s%s',
2645 $disposition,
2646 $encoded_name,
2647 $this->LE . $this->LE
2648 );
2649 } else {
2650 $mime[] = sprintf(
2651 'Content-Disposition: %s%s',
2652 $disposition,
2653 $this->LE . $this->LE
2654 );
2655 }
2656 }
2657 } else {
2658 $mime[] = $this->LE;
2659 }
2660
2661 // Encode as string attachment
2662 if ($bString) {
2663 $mime[] = $this->encodeString($string, $encoding);
2664 if ($this->isError()) {
2665 return '';
2666 }
2667 $mime[] = $this->LE . $this->LE;
2668 } else {
2669 $mime[] = $this->encodeFile($path, $encoding);
2670 if ($this->isError()) {
2671 return '';
2672 }
2673 $mime[] = $this->LE . $this->LE;
2674 }
2675 }
2676 }
2677
2678 $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
2679
2680 return implode('', $mime);
2681 }
encodeString($str, $encoding='base64')
Encode a string in requested format.
encodeFile($path, $encoding='base64')
Encode a file attachment in requested format.
isError()
Check if an error occurred.

References $attachment, $boundary, $LE, $path, encodeFile(), encodeHeader(), encodeString(), isError(), and secureHeader().

Referenced by createBody().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attachmentExists()

PHPMailer::attachmentExists ( )

Check if an attachment (non-inline) is present.

Returns
boolean

Definition at line 3128 of file class.phpmailer.php.

3129 {
3130 foreach ($this->attachment as $attachment) {
3131 if ($attachment[6] == 'attachment') {
3132 return true;
3133 }
3134 }
3135 return false;
3136 }

References $attachment.

Referenced by setMessageType().

+ Here is the caller graph for this function:

◆ base64EncodeWrapMB()

PHPMailer::base64EncodeWrapMB (   $str,
  $linebreak = null 
)

Encode and wrap long multibyte strings for mail headers without breaking lines within a character.

Adapted from a function by paravoid public string $str multi-byte text to wrap encode string $linebreak string to use as linefeed/end-of-line string

Definition at line 2862 of file class.phpmailer.php.

2863 {
2864 $start = '=?' . $this->CharSet . '?B?';
2865 $end = '?=';
2866 $encoded = '';
2867 if ($linebreak === null) {
2868 $linebreak = $this->LE;
2869 }
2870
2871 $mb_length = mb_strlen($str, $this->CharSet);
2872 // Each line must have length <= 75, including $start and $end
2873 $length = 75 - strlen($start) - strlen($end);
2874 // Average multi-byte ratio
2875 $ratio = $mb_length / strlen($str);
2876 // Base64 has a 4:3 ratio
2877 $avgLength = floor($length * $ratio * .75);
2878
2879 for ($i = 0; $i < $mb_length; $i += $offset) {
2880 $lookBack = 0;
2881 do {
2882 $offset = $avgLength - $lookBack;
2883 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
2884 $chunk = base64_encode($chunk);
2885 $lookBack++;
2886 } while (strlen($chunk) > $length);
2887 $encoded .= $chunk . $linebreak;
2888 }
2889
2890 // Chomp the last linefeed
2891 $encoded = substr($encoded, 0, -strlen($linebreak));
2892 return $encoded;
2893 }

References $LE.

Referenced by encodeHeader().

+ Here is the caller graph for this function:

◆ clearAddresses()

PHPMailer::clearAddresses ( )

Clear all To recipients.

Returns
void

Definition at line 3167 of file class.phpmailer.php.

3168 {
3169 foreach ($this->to as $to) {
3170 unset($this->all_recipients[strtolower($to[0])]);
3171 }
3172 $this->to = array();
3173 $this->clearQueuedAddresses('to');
3174 }
clearQueuedAddresses($kind)
Clear queued addresses of given kind.

References $to, and clearQueuedAddresses().

+ Here is the call graph for this function:

◆ clearAllRecipients()

PHPMailer::clearAllRecipients ( )

Clear all recipient types.

Returns
void

Definition at line 3216 of file class.phpmailer.php.

3217 {
3218 $this->to = array();
3219 $this->cc = array();
3220 $this->bcc = array();
3221 $this->all_recipients = array();
3222 $this->RecipientsQueue = array();
3223 }

◆ clearAttachments()

PHPMailer::clearAttachments ( )

Clear all filesystem, string, and binary attachments.

Returns
void

Definition at line 3229 of file class.phpmailer.php.

3230 {
3231 $this->attachment = array();
3232 }

◆ clearBCCs()

PHPMailer::clearBCCs ( )

Clear all BCC recipients.

Returns
void

Definition at line 3193 of file class.phpmailer.php.

3194 {
3195 foreach ($this->bcc as $bcc) {
3196 unset($this->all_recipients[strtolower($bcc[0])]);
3197 }
3198 $this->bcc = array();
3199 $this->clearQueuedAddresses('bcc');
3200 }

References $bcc, and clearQueuedAddresses().

+ Here is the call graph for this function:

◆ clearCCs()

PHPMailer::clearCCs ( )

Clear all CC recipients.

Returns
void

Definition at line 3180 of file class.phpmailer.php.

3181 {
3182 foreach ($this->cc as $cc) {
3183 unset($this->all_recipients[strtolower($cc[0])]);
3184 }
3185 $this->cc = array();
3186 $this->clearQueuedAddresses('cc');
3187 }

References $cc, and clearQueuedAddresses().

+ Here is the call graph for this function:

◆ clearCustomHeaders()

PHPMailer::clearCustomHeaders ( )

Clear all custom headers.

Returns
void

Definition at line 3238 of file class.phpmailer.php.

3239 {
3240 $this->CustomHeader = array();
3241 }

◆ clearQueuedAddresses()

PHPMailer::clearQueuedAddresses (   $kind)

Clear queued addresses of given kind.

@access protected

Parameters
string$kind'to', 'cc', or 'bcc'
Returns
void

Definition at line 3153 of file class.phpmailer.php.

3154 {
3156 foreach ($RecipientsQueue as $address => $params) {
3157 if ($params[0] == $kind) {
3158 unset($this->RecipientsQueue[$address]);
3159 }
3160 }
3161 }

References $params, and $RecipientsQueue.

Referenced by clearAddresses(), clearBCCs(), and clearCCs().

+ Here is the caller graph for this function:

◆ clearReplyTos()

PHPMailer::clearReplyTos ( )

Clear all ReplyTo recipients.

Returns
void

Definition at line 3206 of file class.phpmailer.php.

3207 {
3208 $this->ReplyTo = array();
3209 $this->ReplyToQueue = array();
3210 }

◆ createBody()

PHPMailer::createBody ( )

Assemble the message body.

Returns an empty string on failure. @access public

Exceptions
phpmailerException
Returns
string The assembled message body

Definition at line 2202 of file class.phpmailer.php.

2203 {
2204 $body = '';
2205 //Create unique IDs and preset boundaries
2206 $this->uniqueid = $this->generateId();
2207 $this->boundary[1] = 'b1_' . $this->uniqueid;
2208 $this->boundary[2] = 'b2_' . $this->uniqueid;
2209 $this->boundary[3] = 'b3_' . $this->uniqueid;
2210
2211 if ($this->sign_key_file) {
2212 $body .= $this->getMailMIME() . $this->LE;
2213 }
2214
2215 $this->setWordWrap();
2216
2217 $bodyEncoding = $this->Encoding;
2218 $bodyCharSet = $this->CharSet;
2219 //Can we do a 7-bit downgrade?
2220 if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
2221 $bodyEncoding = '7bit';
2222 //All ISO 8859, Windows codepage and UTF-8 charsets are ascii compatible up to 7-bit
2223 $bodyCharSet = 'us-ascii';
2224 }
2225 //If lines are too long, and we're not already using an encoding that will shorten them,
2226 //change to quoted-printable transfer encoding for the body part only
2227 if ('base64' != $this->Encoding and self::hasLineLongerThanMax($this->Body)) {
2228 $bodyEncoding = 'quoted-printable';
2229 }
2230
2231 $altBodyEncoding = $this->Encoding;
2232 $altBodyCharSet = $this->CharSet;
2233 //Can we do a 7-bit downgrade?
2234 if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
2235 $altBodyEncoding = '7bit';
2236 //All ISO 8859, Windows codepage and UTF-8 charsets are ascii compatible up to 7-bit
2237 $altBodyCharSet = 'us-ascii';
2238 }
2239 //If lines are too long, and we're not already using an encoding that will shorten them,
2240 //change to quoted-printable transfer encoding for the alt body part only
2241 if ('base64' != $altBodyEncoding and self::hasLineLongerThanMax($this->AltBody)) {
2242 $altBodyEncoding = 'quoted-printable';
2243 }
2244 //Use this as a preamble in all multipart message types
2245 $mimepre = "This is a multi-part message in MIME format." . $this->LE . $this->LE;
2246 switch ($this->message_type) {
2247 case 'inline':
2248 $body .= $mimepre;
2249 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
2250 $body .= $this->encodeString($this->Body, $bodyEncoding);
2251 $body .= $this->LE . $this->LE;
2252 $body .= $this->attachAll('inline', $this->boundary[1]);
2253 break;
2254 case 'attach':
2255 $body .= $mimepre;
2256 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
2257 $body .= $this->encodeString($this->Body, $bodyEncoding);
2258 $body .= $this->LE . $this->LE;
2259 $body .= $this->attachAll('attachment', $this->boundary[1]);
2260 break;
2261 case 'inline_attach':
2262 $body .= $mimepre;
2263 $body .= $this->textLine('--' . $this->boundary[1]);
2264 $body .= $this->headerLine('Content-Type', 'multipart/related;');
2265 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
2266 $body .= $this->LE;
2267 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
2268 $body .= $this->encodeString($this->Body, $bodyEncoding);
2269 $body .= $this->LE . $this->LE;
2270 $body .= $this->attachAll('inline', $this->boundary[2]);
2271 $body .= $this->LE;
2272 $body .= $this->attachAll('attachment', $this->boundary[1]);
2273 break;
2274 case 'alt':
2275 $body .= $mimepre;
2276 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
2277 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
2278 $body .= $this->LE . $this->LE;
2279 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
2280 $body .= $this->encodeString($this->Body, $bodyEncoding);
2281 $body .= $this->LE . $this->LE;
2282 if (!empty($this->Ical)) {
2283 $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
2284 $body .= $this->encodeString($this->Ical, $this->Encoding);
2285 $body .= $this->LE . $this->LE;
2286 }
2287 $body .= $this->endBoundary($this->boundary[1]);
2288 break;
2289 case 'alt_inline':
2290 $body .= $mimepre;
2291 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
2292 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
2293 $body .= $this->LE . $this->LE;
2294 $body .= $this->textLine('--' . $this->boundary[1]);
2295 $body .= $this->headerLine('Content-Type', 'multipart/related;');
2296 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
2297 $body .= $this->LE;
2298 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
2299 $body .= $this->encodeString($this->Body, $bodyEncoding);
2300 $body .= $this->LE . $this->LE;
2301 $body .= $this->attachAll('inline', $this->boundary[2]);
2302 $body .= $this->LE;
2303 $body .= $this->endBoundary($this->boundary[1]);
2304 break;
2305 case 'alt_attach':
2306 $body .= $mimepre;
2307 $body .= $this->textLine('--' . $this->boundary[1]);
2308 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
2309 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
2310 $body .= $this->LE;
2311 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
2312 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
2313 $body .= $this->LE . $this->LE;
2314 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
2315 $body .= $this->encodeString($this->Body, $bodyEncoding);
2316 $body .= $this->LE . $this->LE;
2317 $body .= $this->endBoundary($this->boundary[2]);
2318 $body .= $this->LE;
2319 $body .= $this->attachAll('attachment', $this->boundary[1]);
2320 break;
2321 case 'alt_inline_attach':
2322 $body .= $mimepre;
2323 $body .= $this->textLine('--' . $this->boundary[1]);
2324 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
2325 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
2326 $body .= $this->LE;
2327 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
2328 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
2329 $body .= $this->LE . $this->LE;
2330 $body .= $this->textLine('--' . $this->boundary[2]);
2331 $body .= $this->headerLine('Content-Type', 'multipart/related;');
2332 $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
2333 $body .= $this->LE;
2334 $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
2335 $body .= $this->encodeString($this->Body, $bodyEncoding);
2336 $body .= $this->LE . $this->LE;
2337 $body .= $this->attachAll('inline', $this->boundary[3]);
2338 $body .= $this->LE;
2339 $body .= $this->endBoundary($this->boundary[2]);
2340 $body .= $this->LE;
2341 $body .= $this->attachAll('attachment', $this->boundary[1]);
2342 break;
2343 default:
2344 // Catch case 'plain' and case '', applies to simple `text/plain` and `text/html` body content types
2345 //Reset the `Encoding` property in case we changed it for line length reasons
2346 $this->Encoding = $bodyEncoding;
2347 $body .= $this->encodeString($this->Body, $this->Encoding);
2348 break;
2349 }
2350
2351 if ($this->isError()) {
2352 $body = '';
2353 } elseif ($this->sign_key_file) {
2354 try {
2355 if (!defined('PKCS7_TEXT')) {
2356 throw new phpmailerException($this->lang('extension_missing') . 'openssl');
2357 }
2358 // @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
2359 $file = tempnam(sys_get_temp_dir(), 'mail');
2360 if (false === file_put_contents($file, $body)) {
2361 throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
2362 }
2363 $signed = tempnam(sys_get_temp_dir(), 'signed');
2364 //Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
2365 if (empty($this->sign_extracerts_file)) {
2366 $sign = @openssl_pkcs7_sign(
2367 $file,
2368 $signed,
2369 'file://' . realpath($this->sign_cert_file),
2370 array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
2371 null
2372 );
2373 } else {
2374 $sign = @openssl_pkcs7_sign(
2375 $file,
2376 $signed,
2377 'file://' . realpath($this->sign_cert_file),
2378 array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
2379 null,
2380 PKCS7_DETACHED,
2381 $this->sign_extracerts_file
2382 );
2383 }
2384 if ($sign) {
2385 @unlink($file);
2386 $body = file_get_contents($signed);
2387 @unlink($signed);
2388 //The message returned by openssl contains both headers and body, so need to split them up
2389 $parts = explode("\n\n", $body, 2);
2390 $this->MIMEHeader .= $parts[0] . $this->LE . $this->LE;
2391 $body = $parts[1];
2392 } else {
2393 @unlink($file);
2394 @unlink($signed);
2395 throw new phpmailerException($this->lang('signing') . openssl_error_string());
2396 }
2397 } catch (phpmailerException $exc) {
2398 $body = '';
2399 if ($this->exceptions) {
2400 throw $exc;
2401 }
2402 }
2403 }
2404 return $body;
2405 }
print $file
getMailMIME()
Get the message MIME type headers.
setWordWrap()
Apply word wrapping to the message body.
attachAll($disposition_type, $boundary)
Attach all file, string, and binary attachments to the message.
getBoundary($boundary, $charSet, $contentType, $encoding)
Return the start of a message boundary.
endBoundary($boundary)
Return the end of a message boundary.
textLine($value)
Return a formatted mail line.
generateId()
Create unique ID.
headerLine($name, $value)
Format a header line.

References $CharSet, $Encoding, $file, $LE, $uniqueid, attachAll(), encodeString(), endBoundary(), generateId(), getBoundary(), getMailMIME(), has8bitChars(), headerLine(), isError(), lang(), setWordWrap(), and textLine().

Referenced by preSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createHeader()

PHPMailer::createHeader ( )

Assemble message headers.

@access public

Returns
string The assembled headers

Definition at line 2029 of file class.phpmailer.php.

2030 {
2031 $result = '';
2032
2033 if ($this->MessageDate == '') {
2034 $this->MessageDate = self::rfcDate();
2035 }
2036 $result .= $this->headerLine('Date', $this->MessageDate);
2037
2038 // To be created automatically by mail()
2039 if ($this->SingleTo) {
2040 if ($this->Mailer != 'mail') {
2041 foreach ($this->to as $toaddr) {
2042 $this->SingleToArray[] = $this->addrFormat($toaddr);
2043 }
2044 }
2045 } else {
2046 if (count($this->to) > 0) {
2047 if ($this->Mailer != 'mail') {
2048 $result .= $this->addrAppend('To', $this->to);
2049 }
2050 } elseif (count($this->cc) == 0) {
2051 $result .= $this->headerLine('To', 'undisclosed-recipients:;');
2052 }
2053 }
2054
2055 $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
2056
2057 // sendmail and mail() extract Cc from the header before sending
2058 if (count($this->cc) > 0) {
2059 $result .= $this->addrAppend('Cc', $this->cc);
2060 }
2061
2062 // sendmail and mail() extract Bcc from the header before sending
2063 if ((
2064 $this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail'
2065 )
2066 and count($this->bcc) > 0
2067 ) {
2068 $result .= $this->addrAppend('Bcc', $this->bcc);
2069 }
2070
2071 if (count($this->ReplyTo) > 0) {
2072 $result .= $this->addrAppend('Reply-To', $this->ReplyTo);
2073 }
2074
2075 // mail() sets the subject itself
2076 if ($this->Mailer != 'mail') {
2077 $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
2078 }
2079
2080 // Only allow a custom message ID if it conforms to RFC 5322 section 3.6.4
2081 // https://tools.ietf.org/html/rfc5322#section-3.6.4
2082 if ('' != $this->MessageID and preg_match('/^<.*@.*>$/', $this->MessageID)) {
2083 $this->lastMessageID = $this->MessageID;
2084 } else {
2085 $this->lastMessageID = sprintf('<%s@%s>', $this->uniqueid, $this->serverHostname());
2086 }
2087 $result .= $this->headerLine('Message-ID', $this->lastMessageID);
2088 if (!is_null($this->Priority)) {
2089 $result .= $this->headerLine('X-Priority', $this->Priority);
2090 }
2091 if ($this->XMailer == '') {
2092 $result .= $this->headerLine(
2093 'X-Mailer',
2094 'PHPMailer ' . $this->Version . ' (https://github.com/PHPMailer/PHPMailer)'
2095 );
2096 } else {
2097 $myXmailer = trim($this->XMailer);
2098 if ($myXmailer) {
2099 $result .= $this->headerLine('X-Mailer', $myXmailer);
2100 }
2101 }
2102
2103 if ($this->ConfirmReadingTo != '') {
2104 $result .= $this->headerLine('Disposition-Notification-To', '<' . $this->ConfirmReadingTo . '>');
2105 }
2106
2107 // Add custom headers
2108 foreach ($this->CustomHeader as $header) {
2109 $result .= $this->headerLine(
2110 trim($header[0]),
2111 $this->encodeHeader(trim($header[1]))
2112 );
2113 }
2114 if (!$this->sign_key_file) {
2115 $result .= $this->headerLine('MIME-Version', '1.0');
2116 $result .= $this->getMailMIME();
2117 }
2118
2119 return $result;
2120 }
$result
static rfcDate()
Return an RFC 822 formatted date.
serverHostname()
Get the server hostname.
addrAppend($type, $addr)
Create recipient headers.
$header

References $header, $MessageID, $result, addrAppend(), addrFormat(), encodeHeader(), getMailMIME(), headerLine(), rfcDate(), secureHeader(), and serverHostname().

Referenced by preSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DKIM_Add()

PHPMailer::DKIM_Add (   $headers_line,
  $subject,
  $body 
)

Create the DKIM header and body in a new message header.

@access public

Parameters
string$headers_lineHeader lines
string$subjectSubject
string$bodyBody
Returns
string

Definition at line 3872 of file class.phpmailer.php.

3873 {
3874 $DKIMsignatureType = 'rsa-sha256'; // Signature & hash algorithms
3875 $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
3876 $DKIMquery = 'dns/txt'; // Query method
3877 $DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
3878 $subject_header = "Subject: $subject";
3879 $headers = explode($this->LE, $headers_line);
3880 $from_header = '';
3881 $to_header = '';
3882 $date_header = '';
3883 $current = '';
3884 foreach ($headers as $header) {
3885 if (strpos($header, 'From:') === 0) {
3886 $from_header = $header;
3887 $current = 'from_header';
3888 } elseif (strpos($header, 'To:') === 0) {
3889 $to_header = $header;
3890 $current = 'to_header';
3891 } elseif (strpos($header, 'Date:') === 0) {
3892 $date_header = $header;
3893 $current = 'date_header';
3894 } else {
3895 if (!empty($$current) && strpos($header, ' =?') === 0) {
3896 $$current .= $header;
3897 } else {
3898 $current = '';
3899 }
3900 }
3901 }
3902 $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
3903 $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
3904 $date = str_replace('|', '=7C', $this->DKIM_QP($date_header));
3905 $subject = str_replace(
3906 '|',
3907 '=7C',
3908 $this->DKIM_QP($subject_header)
3909 ); // Copied header fields (dkim-quoted-printable)
3910 $body = $this->DKIM_BodyC($body);
3911 $DKIMlen = strlen($body); // Length of body
3912 $DKIMb64 = base64_encode(pack('H*', hash('sha256', $body))); // Base64 of packed binary SHA-256 hash of body
3913 if ('' == $this->DKIM_identity) {
3914 $ident = '';
3915 } else {
3916 $ident = ' i=' . $this->DKIM_identity . ';';
3917 }
3918 $dkimhdrs = 'DKIM-Signature: v=1; a=' .
3919 $DKIMsignatureType . '; q=' .
3920 $DKIMquery . '; l=' .
3921 $DKIMlen . '; s=' .
3922 $this->DKIM_selector .
3923 ";\r\n" .
3924 "\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" .
3925 "\th=From:To:Date:Subject;\r\n" .
3926 "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" .
3927 "\tz=$from\r\n" .
3928 "\t|$to\r\n" .
3929 "\t|$date\r\n" .
3930 "\t|$subject;\r\n" .
3931 "\tbh=" . $DKIMb64 . ";\r\n" .
3932 "\tb=";
3933 $toSign = $this->DKIM_HeaderC(
3934 $from_header . "\r\n" .
3935 $to_header . "\r\n" .
3936 $date_header . "\r\n" .
3937 $subject_header . "\r\n" .
3938 $dkimhdrs
3939 );
3940 $signed = $this->DKIM_Sign($toSign);
3941 return $dkimhdrs . $signed . "\r\n";
3942 }
DKIM_Sign($signHeader)
Generate a DKIM signature.
DKIM_HeaderC($signHeader)
Generate a DKIM canonicalization header.
DKIM_QP($txt)
Quoted-Printable-encode a DKIM header.
DKIM_BodyC($body)
Generate a DKIM canonicalization body.

References $header, $to, DKIM_BodyC(), DKIM_HeaderC(), DKIM_QP(), and DKIM_Sign().

Referenced by preSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DKIM_BodyC()

PHPMailer::DKIM_BodyC (   $body)

Generate a DKIM canonicalization body.

@access public

Parameters
string$bodyMessage Body
Returns
string

Definition at line 3849 of file class.phpmailer.php.

3850 {
3851 if ($body == '') {
3852 return "\r\n";
3853 }
3854 // stabilize line endings
3855 $body = str_replace("\r\n", "\n", $body);
3856 $body = str_replace("\n", "\r\n", $body);
3857 // END stabilize line endings
3858 while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
3859 $body = substr($body, 0, strlen($body) - 2);
3860 }
3861 return $body;
3862 }

Referenced by DKIM_Add().

+ Here is the caller graph for this function:

◆ DKIM_HeaderC()

PHPMailer::DKIM_HeaderC (   $signHeader)

Generate a DKIM canonicalization header.

@access public

Parameters
string$signHeaderHeader
Returns
string

Definition at line 3829 of file class.phpmailer.php.

3830 {
3831 $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
3832 $lines = explode("\r\n", $signHeader);
3833 foreach ($lines as $key => $line) {
3834 list($heading, $value) = explode(':', $line, 2);
3835 $heading = strtolower($heading);
3836 $value = preg_replace('/\s{2,}/', ' ', $value); // Compress useless spaces
3837 $lines[$key] = $heading . ':' . trim($value); // Don't forget to remove WSP around the value
3838 }
3839 $signHeader = implode("\r\n", $lines);
3840 return $signHeader;
3841 }

Referenced by DKIM_Add().

+ Here is the caller graph for this function:

◆ DKIM_QP()

PHPMailer::DKIM_QP (   $txt)

Quoted-Printable-encode a DKIM header.

@access public

Parameters
string$txt
Returns
string

Definition at line 3762 of file class.phpmailer.php.

3763 {
3764 $line = '';
3765 for ($i = 0; $i < strlen($txt); $i++) {
3766 $ord = ord($txt[$i]);
3767 if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
3768 $line .= $txt[$i];
3769 } else {
3770 $line .= '=' . sprintf('%02X', $ord);
3771 }
3772 }
3773 return $line;
3774 }
$txt
Definition: error.php:12

References $txt.

Referenced by DKIM_Add().

+ Here is the caller graph for this function:

◆ DKIM_Sign()

PHPMailer::DKIM_Sign (   $signHeader)

Generate a DKIM signature.

@access public

Parameters
string$signHeader
Exceptions
phpmailerException
Returns
string The DKIM signature value

Definition at line 3783 of file class.phpmailer.php.

3784 {
3785 if (!defined('PKCS7_TEXT')) {
3786 if ($this->exceptions) {
3787 throw new phpmailerException($this->lang('extension_missing') . 'openssl');
3788 }
3789 return '';
3790 }
3791 $privKeyStr = !empty($this->DKIM_private_string) ? $this->DKIM_private_string : file_get_contents($this->DKIM_private);
3792 if ('' != $this->DKIM_passphrase) {
3793 $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
3794 } else {
3795 $privKey = openssl_pkey_get_private($privKeyStr);
3796 }
3797 //Workaround for missing digest algorithms in old PHP & OpenSSL versions
3798 //@link http://stackoverflow.com/a/11117338/333340
3799 if (version_compare(PHP_VERSION, '5.3.0') >= 0 and
3800 in_array('sha256WithRSAEncryption', openssl_get_md_methods(true))) {
3801 if (openssl_sign($signHeader, $signature, $privKey, 'sha256WithRSAEncryption')) {
3802 openssl_pkey_free($privKey);
3803 return base64_encode($signature);
3804 }
3805 } else {
3806 $pinfo = openssl_pkey_get_details($privKey);
3807 $hash = hash('sha256', $signHeader);
3808 //'Magic' constant for SHA256 from RFC3447
3809 //@link https://tools.ietf.org/html/rfc3447#page-43
3810 $t = '3031300d060960864801650304020105000420' . $hash;
3811 $pslen = $pinfo['bits'] / 8 - (strlen($t) / 2 + 3);
3812 $eb = pack('H*', '0001' . str_repeat('FF', $pslen) . '00' . $t);
3813
3814 if (openssl_private_encrypt($eb, $signature, $privKey, OPENSSL_NO_PADDING)) {
3815 openssl_pkey_free($privKey);
3816 return base64_encode($signature);
3817 }
3818 }
3819 openssl_pkey_free($privKey);
3820 return '';
3821 }

References $t, and lang().

Referenced by DKIM_Add().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doCallback()

PHPMailer::doCallback (   $isSent,
  $to,
  $cc,
  $bcc,
  $subject,
  $body,
  $from 
)
protected

Perform a callback.

Parameters
boolean$isSent
array$to
array$cc
array$bcc
string$subject
string$body
string$from

Definition at line 4021 of file class.phpmailer.php.

4022 {
4023 if (!empty($this->action_function) && is_callable($this->action_function)) {
4024 $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
4025 call_user_func_array($this->action_function, $params);
4026 }
4027 }

References $bcc, $cc, $params, and $to.

Referenced by mailSend(), sendmailSend(), and smtpSend().

+ Here is the caller graph for this function:

◆ edebug()

PHPMailer::edebug (   $str)
protected

Output debugging info via user-defined method.

Only generates output if SMTP debug output is enabled (

See also
SMTP::$do_debug).
PHPMailer::$Debugoutput
PHPMailer::$SMTPDebug
Parameters
string$str

Definition at line 717 of file class.phpmailer.php.

718 {
719 if ($this->SMTPDebug <= 0) {
720 return;
721 }
722 //Avoid clash with built-in function names
723 if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
724 call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
725 return;
726 }
727 switch ($this->Debugoutput) {
728 case 'error_log':
729 //Don't output, just log
730 error_log($str);
731 break;
732 case 'html':
733 //Cleans up output a bit for a better looking, HTML-safe output
734 echo htmlentities(
735 preg_replace('/[\r\n]+/', '', $str),
736 ENT_QUOTES,
737 'UTF-8'
738 )
739 . "<br>\n";
740 break;
741 case 'echo':
742 default:
743 //Normalize line breaks
744 $str = preg_replace('/\r\n?/ms', "\n", $str);
745 echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
746 "\n",
747 "\n \t ",
748 trim($str)
749 ) . "\n";
750 }
751 }

References Monolog\Handler\error_log().

Referenced by addAnAddress(), addAttachment(), addOrEnqueueAnAddress(), postSend(), preSend(), setFrom(), PHPMailerOAuth\smtpConnect(), and smtpConnect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeFile()

PHPMailer::encodeFile (   $path,
  $encoding = 'base64' 
)
protected

Encode a file attachment in requested format.

Returns an empty string on failure.

Parameters
string$pathThe full path to the file
string$encodingThe encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
Exceptions
phpmailerException@access protected
Returns
string

Definition at line 2692 of file class.phpmailer.php.

2693 {
2694 try {
2695 if (!is_readable($path)) {
2696 throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
2697 }
2698 $magic_quotes = get_magic_quotes_runtime();
2699 if ($magic_quotes) {
2700 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
2701 set_magic_quotes_runtime(false);
2702 } else {
2703 //Doesn't exist in PHP 5.4, but we don't need to check because
2704 //get_magic_quotes_runtime always returns false in 5.4+
2705 //so it will never get here
2706 ini_set('magic_quotes_runtime', false);
2707 }
2708 }
2709 $file_buffer = file_get_contents($path);
2710 $file_buffer = $this->encodeString($file_buffer, $encoding);
2711 if ($magic_quotes) {
2712 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
2713 set_magic_quotes_runtime($magic_quotes);
2714 } else {
2715 ini_set('magic_quotes_runtime', $magic_quotes);
2716 }
2717 }
2718 return $file_buffer;
2719 } catch (Exception $exc) {
2720 $this->setError($exc->getMessage());
2721 return '';
2722 }
2723 }

References $path, encodeString(), lang(), and setError().

Referenced by attachAll().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeHeader()

PHPMailer::encodeHeader (   $str,
  $position = 'text' 
)

Encode a header string optimally.

Picks shortest of Q, B, quoted-printable or none. @access public

Parameters
string$str
string$position
Returns
string

@noinspection PhpMissingBreakStatementInspection

Definition at line 2769 of file class.phpmailer.php.

2770 {
2771 $matchcount = 0;
2772 switch (strtolower($position)) {
2773 case 'phrase':
2774 if (!preg_match('/[\200-\377]/', $str)) {
2775 // Can't use addslashes as we don't know the value of magic_quotes_sybase
2776 $encoded = addcslashes($str, "\0..\37\177\\\"");
2777 if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
2778 return ($encoded);
2779 } else {
2780 return ("\"$encoded\"");
2781 }
2782 }
2783 $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
2784 break;
2786 case 'comment':
2787 $matchcount = preg_match_all('/[()"]/', $str, $matches);
2788 // Intentional fall-through
2789 case 'text':
2790 default:
2791 $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
2792 break;
2793 }
2794
2795 //There are no chars that need encoding
2796 if ($matchcount == 0) {
2797 return ($str);
2798 }
2799
2800 $maxlen = 75 - 7 - strlen($this->CharSet);
2801 // Try to select the encoding which should produce the shortest output
2802 if ($matchcount > strlen($str) / 3) {
2803 // More than a third of the content will need encoding, so B encoding will be most efficient
2804 $encoding = 'B';
2805 if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) {
2806 // Use a custom function which correctly encodes and wraps long
2807 // multibyte strings without breaking lines within a character
2808 $encoded = $this->base64EncodeWrapMB($str, "\n");
2809 } else {
2810 $encoded = base64_encode($str);
2811 $maxlen -= $maxlen % 4;
2812 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
2813 }
2814 } else {
2815 $encoding = 'Q';
2816 $encoded = $this->encodeQ($str, $position);
2817 $encoded = $this->wrapText($encoded, $maxlen, true);
2818 $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
2819 }
2820
2821 $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
2822 $encoded = trim(str_replace("\n", $this->LE, $encoded));
2823
2824 return $encoded;
2825 }
encodeQ($str, $position='text')
Encode a string using Q encoding.
base64EncodeWrapMB($str, $linebreak=null)
Encode and wrap long multibyte strings for mail headers without breaking lines within a character.
wrapText($message, $length, $qp_mode=false)
Word-wrap message.
hasMultiBytes($str)
Check if a string contains multi-byte characters.

References base64EncodeWrapMB(), encodeQ(), hasMultiBytes(), and wrapText().

Referenced by addrFormat(), attachAll(), createHeader(), mailPassthru(), and preSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeQ()

PHPMailer::encodeQ (   $str,
  $position = 'text' 
)

Encode a string using 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

@noinspection PhpMissingBreakStatementInspection

Definition at line 2945 of file class.phpmailer.php.

2946 {
2947 // There should not be any EOL in the string
2948 $pattern = '';
2949 $encoded = str_replace(array("\r", "\n"), '', $str);
2950 switch (strtolower($position)) {
2951 case 'phrase':
2952 // RFC 2047 section 5.3
2953 $pattern = '^A-Za-z0-9!*+\/ -';
2954 break;
2956 case 'comment':
2957 // RFC 2047 section 5.2
2958 $pattern = '\‍(\‍)"';
2959 // intentional fall-through
2960 // for this reason we build the $pattern without including delimiters and []
2961 case 'text':
2962 default:
2963 // RFC 2047 section 5.1
2964 // Replace every high ascii, control, =, ? and _ characters
2965 $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
2966 break;
2967 }
2968 $matches = array();
2969 if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
2970 // If the string contains an '=', make sure it's the first thing we replace
2971 // so as to avoid double-encoding
2972 $eqkey = array_search('=', $matches[0]);
2973 if (false !== $eqkey) {
2974 unset($matches[0][$eqkey]);
2975 array_unshift($matches[0], '=');
2976 }
2977 foreach (array_unique($matches[0]) as $char) {
2978 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
2979 }
2980 }
2981 // Replace every spaces to _ (more readable than =20)
2982 return str_replace(' ', '_', $encoded);
2983 }

Referenced by encodeHeader().

+ Here is the caller graph for this function:

◆ encodeQP()

PHPMailer::encodeQP (   $string,
  $line_max = 76 
)

Encode a string in quoted-printable format.

According to RFC2045 section 6.7. @access public

Parameters
string$stringThe text to encode
integer$line_maxNumber of chars allowed on a line before wrapping
Returns
string Adapted from this comment

Definition at line 2904 of file class.phpmailer.php.

2905 {
2906 // Use native function if it's available (>= PHP5.3)
2907 if (function_exists('quoted_printable_encode')) {
2908 return quoted_printable_encode($string);
2909 }
2910 // Fall back to a pure PHP implementation
2911 $string = str_replace(
2912 array('%20', '%0D%0A.', '%0D%0A', '%'),
2913 array(' ', "\r\n=2E", "\r\n", '='),
2914 rawurlencode($string)
2915 );
2916 return preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
2917 }

Referenced by encodeQPphp(), and encodeString().

+ Here is the caller graph for this function:

◆ encodeQPphp()

PHPMailer::encodeQPphp (   $string,
  $line_max = 76,
  $space_conv = false 
)

Backward compatibility wrapper for an old QP encoding function that was removed.

See also
PHPMailer::encodeQP() @access User interface
Parameters
string$string
integer$line_max
boolean$space_conv
Returns
string
Deprecated:
Use encodeQP instead.
Parameters
$space_conv@noinspection PhpUnusedParameterInspection

Definition at line 2929 of file class.phpmailer.php.

2933 {
2934 return $this->encodeQP($string, $line_max);
2935 }
encodeQP($string, $line_max=76)
Encode a string in quoted-printable format.

References encodeQP().

+ Here is the call graph for this function:

◆ encodeString()

PHPMailer::encodeString (   $str,
  $encoding = 'base64' 
)

Encode a string in requested format.

Returns an empty string on failure.

Parameters
string$strThe text to encode
string$encodingThe encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' @access public
Returns
string

Definition at line 2733 of file class.phpmailer.php.

2734 {
2735 $encoded = '';
2736 switch (strtolower($encoding)) {
2737 case 'base64':
2738 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
2739 break;
2740 case '7bit':
2741 case '8bit':
2742 $encoded = $this->fixEOL($str);
2743 // Make sure it ends with a line break
2744 if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
2745 $encoded .= $this->LE;
2746 }
2747 break;
2748 case 'binary':
2749 $encoded = $str;
2750 break;
2751 case 'quoted-printable':
2752 $encoded = $this->encodeQP($str);
2753 break;
2754 default:
2755 $this->setError($this->lang('encoding') . $encoding);
2756 break;
2757 }
2758 return $encoded;
2759 }
fixEOL($str)
Ensure consistent line endings in a string.

References $LE, encodeQP(), fixEOL(), lang(), and setError().

Referenced by attachAll(), createBody(), and encodeFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ endBoundary()

PHPMailer::endBoundary (   $boundary)
protected

Return the end of a message boundary.

@access protected

Parameters
string$boundary
Returns
string

Definition at line 2446 of file class.phpmailer.php.

2447 {
2448 return $this->LE . '--' . $boundary . '--' . $this->LE;
2449 }

References $boundary, and $LE.

Referenced by createBody().

+ Here is the caller graph for this function:

◆ filenameToType()

static PHPMailer::filenameToType (   $filename)
static

Map a file name to a MIME type.

Defaults to 'application/octet-stream', i.e.. arbitrary binary data.

Parameters
string$filenameA file name or full path, does not need to exist as a file
Returns
string

Definition at line 3631 of file class.phpmailer.php.

3632 {
3633 // In case the path is a URL, strip any query string before getting extension
3634 $qpos = strpos($filename, '?');
3635 if (false !== $qpos) {
3636 $filename = substr($filename, 0, $qpos);
3637 }
3638 $pathinfo = self::mb_pathinfo($filename);
3639 return self::_mime_types($pathinfo['extension']);
3640 }
static mb_pathinfo($path, $options=null)
Multi-byte-safe pathinfo replacement.
static _mime_types($ext='')
Get the MIME type for a file extension.

References $filename, _mime_types(), and mb_pathinfo().

Referenced by addAttachment(), addEmbeddedImage(), addStringAttachment(), and addStringEmbeddedImage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fixEOL()

PHPMailer::fixEOL (   $str)

Ensure consistent line endings in a string.

Changes every end of line from CRLF, CR or LF to $this->LE. @access public

Parameters
string$strString to fixEOL
Returns
string

Definition at line 3348 of file class.phpmailer.php.

3349 {
3350 // Normalise to \n
3351 $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
3352 // Now convert LE as needed
3353 if ($this->LE !== "\n") {
3354 $nstr = str_replace("\n", $this->LE, $nstr);
3355 }
3356 return $nstr;
3357 }

Referenced by encodeString(), and wrapText().

+ Here is the caller graph for this function:

◆ generateId()

PHPMailer::generateId ( )
protected

Create unique ID.

Returns
string

Definition at line 2191 of file class.phpmailer.php.

2191 {
2192 return md5(uniqid(time()));
2193 }

Referenced by createBody().

+ Here is the caller graph for this function:

◆ getAllRecipientAddresses()

PHPMailer::getAllRecipientAddresses ( )

Allows for public read access to 'all_recipients' property.

Note
: Before the send() call, queued addresses (i.e. with IDN) are not yet included. @access public
Returns
array

Definition at line 4006 of file class.phpmailer.php.

4007 {
4008 return $this->all_recipients;
4009 }

References $all_recipients.

◆ getAttachments()

PHPMailer::getAttachments ( )

Return the array of attachments.

Returns
array

Definition at line 2554 of file class.phpmailer.php.

2555 {
2556 return $this->attachment;
2557 }

References $attachment.

◆ getBccAddresses()

PHPMailer::getBccAddresses ( )

Allows for public read access to 'bcc' property.

Note
: Before the send() call, queued addresses (i.e. with IDN) are not yet included. @access public
Returns
array

Definition at line 3984 of file class.phpmailer.php.

3985 {
3986 return $this->bcc;
3987 }

References $bcc.

◆ getBoundary()

PHPMailer::getBoundary (   $boundary,
  $charSet,
  $contentType,
  $encoding 
)
protected

Return the start of a message boundary.

@access protected

Parameters
string$boundary
string$charSet
string$contentType
string$encoding
Returns
string

Definition at line 2416 of file class.phpmailer.php.

2417 {
2418 $result = '';
2419 if ($charSet == '') {
2420 $charSet = $this->CharSet;
2421 }
2422 if ($contentType == '') {
2423 $contentType = $this->ContentType;
2424 }
2425 if ($encoding == '') {
2426 $encoding = $this->Encoding;
2427 }
2428 $result .= $this->textLine('--' . $boundary);
2429 $result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
2430 $result .= $this->LE;
2431 // RFC1341 part 5 says 7bit is assumed if not specified
2432 if ($encoding != '7bit') {
2433 $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
2434 }
2435 $result .= $this->LE;
2436
2437 return $result;
2438 }

References $boundary, $CharSet, $ContentType, $Encoding, $LE, $result, headerLine(), and textLine().

Referenced by createBody().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCcAddresses()

PHPMailer::getCcAddresses ( )

Allows for public read access to 'cc' property.

Note
: Before the send() call, queued addresses (i.e. with IDN) are not yet included. @access public
Returns
array

Definition at line 3973 of file class.phpmailer.php.

3974 {
3975 return $this->cc;
3976 }

References $cc.

◆ getCustomHeaders()

PHPMailer::getCustomHeaders ( )

Returns all custom headers.

Returns
array

Definition at line 3382 of file class.phpmailer.php.

3383 {
3384 return $this->CustomHeader;
3385 }

References $CustomHeader.

◆ getLastMessageID()

PHPMailer::getLastMessageID ( )

Return the Message-ID header of the last email.

Technically this is the value from the last time the headers were created, but it's also the message ID of the last sent message except in pathological cases.

Returns
string

Definition at line 1050 of file class.phpmailer.php.

1051 {
1052 return $this->lastMessageID;
1053 }

References $lastMessageID.

◆ getMailMIME()

PHPMailer::getMailMIME ( )

Get the message MIME type headers.

@access public

Returns
string

Definition at line 2127 of file class.phpmailer.php.

2128 {
2129 $result = '';
2130 $ismultipart = true;
2131 switch ($this->message_type) {
2132 case 'inline':
2133 $result .= $this->headerLine('Content-Type', 'multipart/related;');
2134 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
2135 break;
2136 case 'attach':
2137 case 'inline_attach':
2138 case 'alt_attach':
2139 case 'alt_inline_attach':
2140 $result .= $this->headerLine('Content-Type', 'multipart/mixed;');
2141 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
2142 break;
2143 case 'alt':
2144 case 'alt_inline':
2145 $result .= $this->headerLine('Content-Type', 'multipart/alternative;');
2146 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
2147 break;
2148 default:
2149 // Catches case 'plain': and case '':
2150 $result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
2151 $ismultipart = false;
2152 break;
2153 }
2154 // RFC1341 part 5 says 7bit is assumed if not specified
2155 if ($this->Encoding != '7bit') {
2156 // RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
2157 if ($ismultipart) {
2158 if ($this->Encoding == '8bit') {
2159 $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
2160 }
2161 // The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
2162 } else {
2163 $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
2164 }
2165 }
2166
2167 if ($this->Mailer != 'mail') {
2168 $result .= $this->LE;
2169 }
2170
2171 return $result;
2172 }

References $LE, $result, headerLine(), and textLine().

Referenced by createBody(), and createHeader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getReplyToAddresses()

PHPMailer::getReplyToAddresses ( )

Allows for public read access to 'ReplyTo' property.

Note
: Before the send() call, queued addresses (i.e. with IDN) are not yet included. @access public
Returns
array

Definition at line 3995 of file class.phpmailer.php.

3996 {
3997 return $this->ReplyTo;
3998 }

References $ReplyTo.

◆ getSentMIMEMessage()

PHPMailer::getSentMIMEMessage ( )

Returns the whole MIME message.

Includes complete headers and body. Only valid post preSend().

See also
PHPMailer::preSend() @access User interface
Returns
string

Definition at line 2182 of file class.phpmailer.php.

2183 {
2184 return rtrim($this->MIMEHeader . $this->mailHeader, "\n\r") . self::CRLF . self::CRLF . $this->MIMEBody;
2185 }

References $MIMEBody.

◆ getSMTPInstance()

PHPMailer::getSMTPInstance ( )

Get an instance to use for SMTP operations.

Override this function to load your own SMTP implementation

Returns
SMTP

Definition at line 1523 of file class.phpmailer.php.

1524 {
1525 if (!is_object($this->smtp)) {
1526 $this->smtp = new SMTP;
1527 }
1528 return $this->smtp;
1529 }

References $smtp.

Referenced by PHPMailerOAuth\smtpConnect(), and smtpConnect().

+ Here is the caller graph for this function:

◆ getToAddresses()

PHPMailer::getToAddresses ( )

Allows for public read access to 'to' property.

Note
: Before the send() call, queued addresses (i.e. with IDN) are not yet included. @access public
Returns
array

Definition at line 3962 of file class.phpmailer.php.

3963 {
3964 return $this->to;
3965 }

References $to.

◆ getTranslations()

PHPMailer::getTranslations ( )

Get the array of strings for the current language.

Returns
array

Definition at line 1808 of file class.phpmailer.php.

1809 {
1810 return $this->language;
1811 }

References $language.

◆ has8bitChars()

PHPMailer::has8bitChars (   $text)

Does a string contain any 8-bit chars (in any charset)?

Parameters
string$text
Returns
boolean

Definition at line 2847 of file class.phpmailer.php.

2848 {
2849 return (boolean)preg_match('/[\x80-\xFF]/', $text);
2850 }
$text

References $text.

Referenced by addOrEnqueueAnAddress(), createBody(), punyencodeAddress(), and setFrom().

+ Here is the caller graph for this function:

◆ hasLineLongerThanMax()

static PHPMailer::hasLineLongerThanMax (   $str)
static

Detect if a string contains a line longer than the maximum line length allowed.

Parameters
string$str
Returns
boolean

Definition at line 3950 of file class.phpmailer.php.

3951 {
3952 //+2 to include CRLF line break for a 1000 total
3953 return (boolean)preg_match('/^(.{'.(self::MAX_LINE_LENGTH + 2).',})/m', $str);
3954 }

◆ hasMultiBytes()

PHPMailer::hasMultiBytes (   $str)

Check if a string contains multi-byte characters.

@access public

Parameters
string$strmulti-byte text to wrap encode
Returns
boolean

Definition at line 2833 of file class.phpmailer.php.

2834 {
2835 if (function_exists('mb_strlen')) {
2836 return (strlen($str) > mb_strlen($str, $this->CharSet));
2837 } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
2838 return false;
2839 }
2840 }

Referenced by encodeHeader().

+ Here is the caller graph for this function:

◆ headerLine()

PHPMailer::headerLine (   $name,
  $value 
)

Format a header line.

@access public

Parameters
string$name
string$value
Returns
string

Definition at line 2483 of file class.phpmailer.php.

2484 {
2485 return $name . ': ' . $value . $this->LE;
2486 }

References $LE.

Referenced by createBody(), createHeader(), getBoundary(), getMailMIME(), and preSend().

+ Here is the caller graph for this function:

◆ html2text()

PHPMailer::html2text (   $html,
  $advanced = false 
)

Convert an HTML string into plain text.

This is used by msgHTML(). Note - older versions of this function used a bundled advanced converter which was been removed for license reasons in #232. Example usage: // Use default conversion $plain = $mail->html2text($html); // Use your own custom converter $plain = $mail->html2text($html, function($html) { $converter = new MyHtml2text($html); return $converter->get_text(); });

Parameters
string$htmlThe HTML text to convert
boolean | callable$advancedAny boolean value to use the internal converter, or provide your own callable for custom conversion.
Returns
string

Definition at line 3497 of file class.phpmailer.php.

3498 {
3499 if (is_callable($advanced)) {
3500 return call_user_func($advanced, $html);
3501 }
3502 return html_entity_decode(
3503 trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))),
3504 ENT_QUOTES,
3505 $this->CharSet
3506 );
3507 }
$html
Definition: example_001.php:87

References $html.

Referenced by msgHTML().

+ Here is the caller graph for this function:

◆ idnSupported()

PHPMailer::idnSupported ( )

Tells whether IDNs (Internationalized Domain Names) are supported or not.

This requires the "intl" and "mbstring" PHP extensions.

Returns
bool "true" if required functions for IDN support are present

Definition at line 1170 of file class.phpmailer.php.

1171 {
1172 // @TODO: Write our own "idn_to_ascii" function for PHP <= 5.2.
1173 return function_exists('idn_to_ascii') and function_exists('mb_convert_encoding');
1174 }

Referenced by addOrEnqueueAnAddress(), punyencodeAddress(), and setFrom().

+ Here is the caller graph for this function:

◆ inlineImageExists()

PHPMailer::inlineImageExists ( )

Check if an inline attachment is present.

@access public

Returns
boolean

Definition at line 3114 of file class.phpmailer.php.

3115 {
3116 foreach ($this->attachment as $attachment) {
3117 if ($attachment[6] == 'inline') {
3118 return true;
3119 }
3120 }
3121 return false;
3122 }

References $attachment.

Referenced by setMessageType().

+ Here is the caller graph for this function:

◆ isError()

PHPMailer::isError ( )

Check if an error occurred.

@access public

Returns
boolean True if an error did occur.

Definition at line 3336 of file class.phpmailer.php.

3337 {
3338 return ($this->error_count > 0);
3339 }

Referenced by attachAll(), and createBody().

+ Here is the caller graph for this function:

◆ isHTML()

PHPMailer::isHTML (   $isHtml = true)

Sets message type to HTML or plain.

Parameters
boolean$isHtmlTrue for HTML mode.
Returns
void

Definition at line 758 of file class.phpmailer.php.

759 {
760 if ($isHtml) {
761 $this->ContentType = 'text/html';
762 } else {
763 $this->ContentType = 'text/plain';
764 }
765 }

Referenced by msgHTML().

+ Here is the caller graph for this function:

◆ isMail()

PHPMailer::isMail ( )

Send messages using PHP's mail() function.

Returns
void

Definition at line 780 of file class.phpmailer.php.

781 {
782 $this->Mailer = 'mail';
783 }

◆ isQmail()

PHPMailer::isQmail ( )

Send messages using qmail.

Returns
void

Definition at line 805 of file class.phpmailer.php.

806 {
807 $ini_sendmail_path = ini_get('sendmail_path');
808
809 if (!stristr($ini_sendmail_path, 'qmail')) {
810 $this->Sendmail = '/var/qmail/bin/qmail-inject';
811 } else {
812 $this->Sendmail = $ini_sendmail_path;
813 }
814 $this->Mailer = 'qmail';
815 }

◆ isSendmail()

PHPMailer::isSendmail ( )

Send messages using $Sendmail.

Returns
void

Definition at line 789 of file class.phpmailer.php.

790 {
791 $ini_sendmail_path = ini_get('sendmail_path');
792
793 if (!stristr($ini_sendmail_path, 'sendmail')) {
794 $this->Sendmail = '/usr/sbin/sendmail';
795 } else {
796 $this->Sendmail = $ini_sendmail_path;
797 }
798 $this->Mailer = 'sendmail';
799 }

◆ isShellSafe()

static PHPMailer::isShellSafe (   $string)
staticprotected

Fix CVE-2016-10033 and CVE-2016-10045 by disallowing potentially unsafe shell characters.

Note that escapeshellarg and escapeshellcmd are inadequate for our purposes, especially on Windows.

Parameters
string$stringThe string to be validated
See also
https://github.com/PHPMailer/PHPMailer/issues/924 CVE-2016-10045 bug report @access protected
Returns
boolean

Definition at line 1445 of file class.phpmailer.php.

1446 {
1447 // Future-proof
1448 if (escapeshellcmd($string) !== $string
1449 or !in_array(escapeshellarg($string), array("'$string'", "\"$string\""))
1450 ) {
1451 return false;
1452 }
1453
1454 $length = strlen($string);
1455
1456 for ($i = 0; $i < $length; $i++) {
1457 $c = $string[$i];
1458
1459 // All other characters have a special meaning in at least one common shell, including = and +.
1460 // Full stop (.) has a special meaning in cmd.exe, but its impact should be negligible here.
1461 // Note that this does permit non-Latin alphanumeric characters based on the current locale.
1462 if (!ctype_alnum($c) && strpos('@_-.', $c) === false) {
1463 return false;
1464 }
1465 }
1466
1467 return true;
1468 }

◆ isSMTP()

PHPMailer::isSMTP ( )

Send messages using SMTP.

Returns
void

Definition at line 771 of file class.phpmailer.php.

772 {
773 $this->Mailer = 'smtp';
774 }

◆ lang()

PHPMailer::lang (   $key)
protected

Get an error message in the current language.

@access protected

Parameters
string$key
Returns
string

Definition at line 3311 of file class.phpmailer.php.

3312 {
3313 if (count($this->language) < 1) {
3314 $this->setLanguage('en'); // set the default language
3315 }
3316
3317 if (array_key_exists($key, $this->language)) {
3318 if ($key == 'smtp_connect_failed') {
3319 //Include a link to troubleshooting docs on SMTP connection failure
3320 //this is by far the biggest cause of support questions
3321 //but it's usually not PHPMailer's fault.
3322 return $this->language[$key] . ' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting';
3323 }
3324 return $this->language[$key];
3325 } else {
3326 //Return the key as a fallback
3327 return $key;
3328 }
3329 }
setLanguage($langcode='en', $lang_path='')
Set the language for error messages.

References setLanguage().

Referenced by addAnAddress(), addAttachment(), addEmbeddedImage(), addOrEnqueueAnAddress(), createBody(), DKIM_Sign(), encodeFile(), encodeString(), mailSend(), preSend(), sendmailSend(), set(), setError(), setFrom(), PHPMailerOAuth\smtpConnect(), smtpConnect(), and smtpSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailPassthru()

PHPMailer::mailPassthru (   $to,
  $subject,
  $body,
  $header,
  $params 
)
private

Call mail() in a safe_mode-aware fashion.

Also, unless sendmail_path points to sendmail (or something that claims to be sendmail), don't pass params (not a perfect fix, but it will do)

Parameters
string$toTo
string$subjectSubject
string$bodyMessage Body
string$headerAdditional Header(s)
string$paramsParams @access private
Returns
boolean

Definition at line 686 of file class.phpmailer.php.

687 {
688 //Check overloading of mail function to avoid double-encoding
689 if (ini_get('mbstring.func_overload') & 1) {
690 $subject = $this->secureHeader($subject);
691 } else {
692 $subject = $this->encodeHeader($this->secureHeader($subject));
693 }
694 // patch-mjansen: begin #20376
695 if(0 == strlen($to) && strpos($header, 'To: undisclosed-recipients:;') !== false)
696 {
697 $to = 'undisclosed-recipients:;';
698 $header = preg_replace('/To: undisclosed-recipients:;(\s*)/', '', $header);
699 }
700 // patch-mjansen: end
701 //Can't use additional_parameters in safe_mode, calling mail() with null params breaks
702 //@link http://php.net/manual/en/function.mail.php
703 if (ini_get('safe_mode') or !$this->UseSendmailOptions or is_null($params)) {
704 $result = @mail($to, $subject, $body, $header);
705 } else {
706 $result = @mail($to, $subject, $body, $header, $params);
707 }
708 return $result;
709 }

References $header, $params, $result, $to, encodeHeader(), and secureHeader().

Referenced by mailSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailSend()

PHPMailer::mailSend (   $header,
  $body 
)
protected

Send mail using the PHP mail() function.

Parameters
string$headerThe message headers
string$bodyThe message body phpmailerException protected boolean

Definition at line 1479 of file class.phpmailer.php.

1480 {
1481 $toArr = array();
1482 foreach ($this->to as $toaddr) {
1483 $toArr[] = $this->addrFormat($toaddr);
1484 }
1485 $to = implode(', ', $toArr);
1486
1487 $params = null;
1488 //This sets the SMTP envelope sender which gets turned into a return-path header by the receiver
1489 if (!empty($this->Sender) and $this->validateAddress($this->Sender)) {
1490 // CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped.
1491 if (self::isShellSafe($this->Sender)) {
1492 $params = sprintf('-f%s', $this->Sender);
1493 }
1494 }
1495 if (!empty($this->Sender) and !ini_get('safe_mode') and $this->validateAddress($this->Sender)) {
1496 $old_from = ini_get('sendmail_from');
1497 ini_set('sendmail_from', $this->Sender);
1498 }
1499 $result = false;
1500 if ($this->SingleTo and count($toArr) > 1) {
1501 foreach ($toArr as $toAddr) {
1502 $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
1503 $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1504 }
1505 } else {
1506 $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
1507 $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1508 }
1509 if (isset($old_from)) {
1510 ini_set('sendmail_from', $old_from);
1511 }
1512 if (!$result) {
1513 throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
1514 }
1515 return true;
1516 }
mailPassthru($to, $subject, $body, $header, $params)
Call mail() in a safe_mode-aware fashion.
doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
Perform a callback.

References $header, $params, $result, $to, addrFormat(), doCallback(), lang(), mailPassthru(), and validateAddress().

Referenced by postSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mb_pathinfo()

static PHPMailer::mb_pathinfo (   $path,
  $options = null 
)
static

Multi-byte-safe pathinfo replacement.

Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe. Works similarly to the one in PHP >= 5.2.0 string $path A filename or path, does not need to exist as a file integer|string $options Either a PATHINFO_* constant, or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2 string|array

Definition at line 3653 of file class.phpmailer.php.

3654 {
3655 $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
3656 $pathinfo = array();
3657 if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
3658 if (array_key_exists(1, $pathinfo)) {
3659 $ret['dirname'] = $pathinfo[1];
3660 }
3661 if (array_key_exists(2, $pathinfo)) {
3662 $ret['basename'] = $pathinfo[2];
3663 }
3664 if (array_key_exists(5, $pathinfo)) {
3665 $ret['extension'] = $pathinfo[5];
3666 }
3667 if (array_key_exists(3, $pathinfo)) {
3668 $ret['filename'] = $pathinfo[3];
3669 }
3670 }
3671 switch ($options) {
3672 case PATHINFO_DIRNAME:
3673 case 'dirname':
3674 return $ret['dirname'];
3675 case PATHINFO_BASENAME:
3676 case 'basename':
3677 return $ret['basename'];
3678 case PATHINFO_EXTENSION:
3679 case 'extension':
3680 return $ret['extension'];
3681 case PATHINFO_FILENAME:
3682 case 'filename':
3683 return $ret['filename'];
3684 default:
3685 return $ret;
3686 }
3687 }
if(!is_array($argv)) $options

References $options, $path, and $ret.

Referenced by filenameToType().

+ Here is the caller graph for this function:

◆ msgHTML()

PHPMailer::msgHTML (   $message,
  $basedir = '',
  $advanced = false 
)

Create a message body from an HTML string.

Automatically inlines images and creates a plain-text version by converting the HTML, overwriting any existing values in Body and AltBody. Do not source $message content from user input! $basedir is prepended when handling relative URLs, e.g. and must not be empty will look for an image file in $basedir/images/a.png and convert it to inline. If you don't provide a $basedir, relative paths will be left untouched (and thus probably break in email) If you don't want to apply these transformations to your HTML, just set Body and AltBody directly. @access public

Parameters
string$messageHTML message string
string$basedirAbsolute path to a base directory to prepend to relative paths to images
boolean | callable$advancedWhether to use the internal HTML to text converter or your own custom converter
See also
PHPMailer::html2text()
Returns
string $message The transformed message Body

Definition at line 3403 of file class.phpmailer.php.

3404 {
3405 preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
3406 if (array_key_exists(2, $images)) {
3407 if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
3408 // Ensure $basedir has a trailing /
3409 $basedir .= '/';
3410 }
3411 foreach ($images[2] as $imgindex => $url) {
3412 // Convert data URIs into embedded images
3413 if (preg_match('#^data:(image[^;,]*)(;base64)?,#', $url, $match)) {
3414 $data = substr($url, strpos($url, ','));
3415 if ($match[2]) {
3416 $data = base64_decode($data);
3417 } else {
3418 $data = rawurldecode($data);
3419 }
3420 $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
3421 if ($this->addStringEmbeddedImage($data, $cid, 'embed' . $imgindex, 'base64', $match[1])) {
3422 $message = str_replace(
3423 $images[0][$imgindex],
3424 $images[1][$imgindex] . '="cid:' . $cid . '"',
3425 $message
3426 );
3427 }
3428 continue;
3429 }
3430 if (
3431 // Only process relative URLs if a basedir is provided (i.e. no absolute local paths)
3432 !empty($basedir)
3433 // Ignore URLs containing parent dir traversal (..)
3434 && (strpos($url, '..') === false)
3435 // Do not change urls that are already inline images
3436 && substr($url, 0, 4) !== 'cid:'
3437 // Do not change absolute URLs, including anonymous protocol
3438 && !preg_match('#^[a-z][a-z0-9+.-]*:?//#i', $url)
3439 ) {
3440 $filename = basename($url);
3441 $directory = dirname($url);
3442 if ($directory == '.') {
3443 $directory = '';
3444 }
3445 $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
3446 if (strlen($directory) > 1 && substr($directory, -1) != '/') {
3447 $directory .= '/';
3448 }
3449 if ($this->addEmbeddedImage(
3450 $basedir . $directory . $filename,
3451 $cid,
3452 $filename,
3453 'base64',
3454 self::_mime_types((string)self::mb_pathinfo($filename, PATHINFO_EXTENSION))
3455 )
3456 ) {
3457 $message = preg_replace(
3458 '/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui',
3459 $images[1][$imgindex] . '="cid:' . $cid . '"',
3460 $message
3461 );
3462 }
3463 }
3464 }
3465 }
3466 $this->isHTML(true);
3467 // Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
3468 $this->Body = $this->normalizeBreaks($message);
3469 $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
3470 if (!$this->alternativeExists()) {
3471 $this->AltBody = 'To view this email message, open it in a program that understands HTML!' .
3472 self::CRLF . self::CRLF;
3473 }
3474 return $this->Body;
3475 }
alternativeExists()
Check if this message has an alternative body set.
const CRLF
SMTP RFC standard line ending.
addStringEmbeddedImage( $string, $cid, $name='', $encoding='base64', $type='', $disposition='inline')
Add an embedded stringified attachment.
html2text($html, $advanced=false)
Convert an HTML string into plain text.
addEmbeddedImage($path, $cid, $name='', $encoding='base64', $type='', $disposition='inline')
Add an embedded (inline) attachment from a file.
isHTML($isHtml=true)
Sets message type to HTML or plain.
static normalizeBreaks($text, $breaktype="\r\n")
Normalize line breaks in a string.
$data
$url
Definition: shib_logout.php:72

References $Body, $data, $filename, $url, addEmbeddedImage(), addStringEmbeddedImage(), alternativeExists(), CRLF, html2text(), isHTML(), and normalizeBreaks().

+ Here is the call graph for this function:

◆ normalizeBreaks()

static PHPMailer::normalizeBreaks (   $text,
  $breaktype = "\r\n" 
)
static

Normalize line breaks in a string.

Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format. Defaults to CRLF (for message bodies) and preserves consecutive breaks.

Parameters
string$text
string$breaktypeWhat kind of line break to use, defaults to CRLF
Returns
string @access public

Definition at line 3735 of file class.phpmailer.php.

3736 {
3737 return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
3738 }

References $text.

Referenced by msgHTML().

+ Here is the caller graph for this function:

◆ parseAddresses()

PHPMailer::parseAddresses (   $addrstr,
  $useimap = true 
)

Parse and validate a string containing one or more RFC822-style comma-separated email addresses of the form "display name <address>" into an array of name/address pairs.

Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. Note that quotes in the name part are removed.

Parameters
string$addrstrThe address list string
bool$useimapWhether to use the IMAP extension to parse the list
Returns
array A more careful implementation

Definition at line 964 of file class.phpmailer.php.

965 {
966 $addresses = array();
967 if ($useimap and function_exists('imap_rfc822_parse_adrlist')) {
968 //Use this built-in parser if it's available
969 $list = imap_rfc822_parse_adrlist($addrstr, '');
970 foreach ($list as $address) {
971 if ($address->host != '.SYNTAX-ERROR.') {
972 if ($this->validateAddress($address->mailbox . '@' . $address->host)) {
973 $addresses[] = array(
974 'name' => (property_exists($address, 'personal') ? $address->personal : ''),
975 'address' => $address->mailbox . '@' . $address->host
976 );
977 }
978 }
979 }
980 } else {
981 //Use this simpler parser
982 $list = explode(',', $addrstr);
983 foreach ($list as $address) {
984 $address = trim($address);
985 //Is there a separate name part?
986 if (strpos($address, '<') === false) {
987 //No separate name, just use the whole thing
988 if ($this->validateAddress($address)) {
989 $addresses[] = array(
990 'name' => '',
991 'address' => $address
992 );
993 }
994 } else {
995 list($name, $email) = explode('<', $address);
996 $email = trim(str_replace('>', '', $email));
997 if ($this->validateAddress($email)) {
998 $addresses[] = array(
999 'name' => trim(str_replace(array('"', "'"), '', $name)),
1000 'address' => $email
1001 );
1002 }
1003 }
1004 }
1005 }
1006 return $addresses;
1007 }

References validateAddress().

+ Here is the call graph for this function:

◆ postSend()

PHPMailer::postSend ( )

Actually send a message.

Send the email via the selected mechanism

Exceptions
phpmailerException
Returns
boolean

Definition at line 1332 of file class.phpmailer.php.

1333 {
1334 try {
1335 // Choose the mailer and send through it
1336 switch ($this->Mailer) {
1337 case 'sendmail':
1338 case 'qmail':
1339 return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
1340 case 'smtp':
1341 return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
1342 case 'mail':
1343 return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
1344 default:
1345 $sendMethod = $this->Mailer.'Send';
1346 if (method_exists($this, $sendMethod)) {
1347 return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
1348 }
1349
1350 return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
1351 }
1352 } catch (phpmailerException $exc) {
1353 $this->setError($exc->getMessage());
1354 $this->edebug($exc->getMessage());
1355 if ($this->exceptions) {
1356 throw $exc;
1357 }
1358 }
1359 return false;
1360 }
mailSend($header, $body)
Send mail using the PHP mail() function.
smtpSend($header, $body)
Send mail via SMTP.
sendmailSend($header, $body)
Send mail using the $Sendmail program.

References edebug(), mailSend(), sendmailSend(), setError(), and smtpSend().

Referenced by send().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ preSend()

PHPMailer::preSend ( )

Prepare a message for sending.

Exceptions
phpmailerException
Returns
boolean

Definition at line 1235 of file class.phpmailer.php.

1236 {
1237 try {
1238 $this->error_count = 0; // Reset errors
1239 $this->mailHeader = '';
1240
1241 // Dequeue recipient and Reply-To addresses with IDN
1242 foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) {
1243 $params[1] = $this->punyencodeAddress($params[1]);
1244 call_user_func_array(array($this, 'addAnAddress'), $params);
1245 }
1246 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
1247 throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
1248 }
1249
1250 // Validate From, Sender, and ConfirmReadingTo addresses
1251 foreach (array('From', 'Sender', 'ConfirmReadingTo') as $address_kind) {
1252 $this->$address_kind = trim($this->$address_kind);
1253 if (empty($this->$address_kind)) {
1254 continue;
1255 }
1256 $this->$address_kind = $this->punyencodeAddress($this->$address_kind);
1257 if (!$this->validateAddress($this->$address_kind)) {
1258 $error_message = $this->lang('invalid_address') . ' (punyEncode) ' . $this->$address_kind;
1259 $this->setError($error_message);
1260 $this->edebug($error_message);
1261 if ($this->exceptions) {
1262 throw new phpmailerException($error_message);
1263 }
1264 return false;
1265 }
1266 }
1267
1268 // Set whether the message is multipart/alternative
1269 if ($this->alternativeExists()) {
1270 $this->ContentType = 'multipart/alternative';
1271 }
1272
1273 $this->setMessageType();
1274 // Refuse to send an empty message unless we are specifically allowing it
1275 if (!$this->AllowEmpty and empty($this->Body)) {
1276 throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
1277 }
1278
1279 // Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
1280 $this->MIMEHeader = '';
1281 $this->MIMEBody = $this->createBody();
1282 // createBody may have added some headers, so retain them
1283 $tempheaders = $this->MIMEHeader;
1284 $this->MIMEHeader = $this->createHeader();
1285 $this->MIMEHeader .= $tempheaders;
1286
1287 // To capture the complete message when using mail(), create
1288 // an extra header list which createHeader() doesn't fold in
1289 if ($this->Mailer == 'mail') {
1290 if (count($this->to) > 0) {
1291 $this->mailHeader .= $this->addrAppend('To', $this->to);
1292 } else {
1293 $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
1294 }
1295 $this->mailHeader .= $this->headerLine(
1296 'Subject',
1297 $this->encodeHeader($this->secureHeader(trim($this->Subject)))
1298 );
1299 }
1300
1301 // Sign with DKIM if enabled
1302 if (!empty($this->DKIM_domain)
1303 && !empty($this->DKIM_selector)
1304 && (!empty($this->DKIM_private_string)
1305 || (!empty($this->DKIM_private) && file_exists($this->DKIM_private))
1306 )
1307 ) {
1308 $header_dkim = $this->DKIM_Add(
1309 $this->MIMEHeader . $this->mailHeader,
1310 $this->encodeHeader($this->secureHeader($this->Subject)),
1311 $this->MIMEBody
1312 );
1313 $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
1314 str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
1315 }
1316 return true;
1317 } catch (phpmailerException $exc) {
1318 $this->setError($exc->getMessage());
1319 if ($this->exceptions) {
1320 throw $exc;
1321 }
1322 return false;
1323 }
1324 }
setMessageType()
Set the message type.
DKIM_Add($headers_line, $subject, $body)
Create the DKIM header and body in a new message header.
createBody()
Assemble the message body.
punyencodeAddress($address)
Converts IDN in given email address to its ASCII form, also known as punycode, if possible.
createHeader()
Assemble message headers.

References $MIMEHeader, $params, addrAppend(), alternativeExists(), createBody(), createHeader(), CRLF, DKIM_Add(), edebug(), encodeHeader(), headerLine(), lang(), punyencodeAddress(), secureHeader(), setError(), setMessageType(), and validateAddress().

Referenced by send().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ punyencodeAddress()

PHPMailer::punyencodeAddress (   $address)

Converts IDN in given email address to its ASCII form, also known as punycode, if possible.

Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet. This function silently returns unmodified address if:

  • No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form)
  • Conversion to punycode is impossible (e.g. required PHP functions are not available) or fails for any reason (e.g. domain has characters not allowed in an IDN)
    See also
    PHPMailer::$CharSet
    Parameters
    string$addressThe email address to convert
    Returns
    string The encoded address in ASCII form

Definition at line 1187 of file class.phpmailer.php.

1188 {
1189 // Verify we have required functions, CharSet, and at-sign.
1190 if ($this->idnSupported() and
1191 !empty($this->CharSet) and
1192 ($pos = strrpos($address, '@')) !== false) {
1193 $domain = substr($address, ++$pos);
1194 // Verify CharSet string is a valid one, and domain properly encoded in this CharSet.
1195 if ($this->has8bitChars($domain) and @mb_check_encoding($domain, $this->CharSet)) {
1196 $domain = mb_convert_encoding($domain, 'UTF-8', $this->CharSet);
1197 if (($punycode = defined('INTL_IDNA_VARIANT_UTS46') ?
1198 idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) :
1199 idn_to_ascii($domain)) !== false) {
1200 return substr($address, 0, $pos) . $punycode;
1201 }
1202 }
1203 }
1204 return $address;
1205 }

References has8bitChars(), and idnSupported().

Referenced by preSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rfcDate()

static PHPMailer::rfcDate ( )
static

Return an RFC 822 formatted date.

@access public

Returns
string

Definition at line 3276 of file class.phpmailer.php.

3277 {
3278 // Set the time zone to whatever the default is to avoid 500 errors
3279 // Will default to UTC if it's not set properly in php.ini
3280 date_default_timezone_set(@date_default_timezone_get());
3281 return date('D, j M Y H:i:s O');
3282 }

Referenced by createHeader().

+ Here is the caller graph for this function:

◆ secureHeader()

PHPMailer::secureHeader (   $str)

Strip newlines to prevent header injection.

@access public

Parameters
string$str
Returns
string

Definition at line 3720 of file class.phpmailer.php.

3721 {
3722 return trim(str_replace(array("\r", "\n"), '', $str));
3723 }

Referenced by addrFormat(), attachAll(), createHeader(), mailPassthru(), and preSend().

+ Here is the caller graph for this function:

◆ send()

PHPMailer::send ( )

Create a message and send it.

Uses the sending method specified by $Mailer.

Exceptions
phpmailerException
Returns
boolean false on error - See the ErrorInfo property for details of the error.

Definition at line 1213 of file class.phpmailer.php.

1214 {
1215 try {
1216 if (!$this->preSend()) {
1217 return false;
1218 }
1219 return $this->postSend();
1220 } catch (phpmailerException $exc) {
1221 $this->mailHeader = '';
1222 $this->setError($exc->getMessage());
1223 if ($this->exceptions) {
1224 throw $exc;
1225 }
1226 return false;
1227 }
1228 }
postSend()
Actually send a message.
preSend()
Prepare a message for sending.

References postSend(), preSend(), and setError().

+ Here is the call graph for this function:

◆ sendmailSend()

PHPMailer::sendmailSend (   $header,
  $body 
)
protected

Send mail using the $Sendmail program.

Parameters
string$headerThe message headers
string$bodyThe message body
See also
PHPMailer::$Sendmail
Exceptions
phpmailerException@access protected
Returns
boolean

Definition at line 1371 of file class.phpmailer.php.

1372 {
1373 // CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped.
1374 if (!empty($this->Sender) and self::isShellSafe($this->Sender)) {
1375 if ($this->Mailer == 'qmail') {
1376 $sendmailFmt = '%s -f%s';
1377 } else {
1378 $sendmailFmt = '%s -oi -f%s -t';
1379 }
1380 } else {
1381 if ($this->Mailer == 'qmail') {
1382 $sendmailFmt = '%s';
1383 } else {
1384 $sendmailFmt = '%s -oi -t';
1385 }
1386 }
1387
1388 // TODO: If possible, this should be changed to escapeshellarg. Needs thorough testing.
1389 $sendmail = sprintf($sendmailFmt, escapeshellcmd($this->Sendmail), $this->Sender);
1390
1391 if ($this->SingleTo) {
1392 foreach ($this->SingleToArray as $toAddr) {
1393 if (!@$mail = popen($sendmail, 'w')) {
1394 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1395 }
1396 fputs($mail, 'To: ' . $toAddr . "\n");
1397 fputs($mail, $header);
1398 fputs($mail, $body);
1399 $result = pclose($mail);
1400 $this->doCallback(
1401 ($result == 0),
1402 array($toAddr),
1403 $this->cc,
1404 $this->bcc,
1405 $this->Subject,
1406 $body,
1407 $this->From
1408 );
1409 if ($result != 0) {
1410 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1411 }
1412 }
1413 } else {
1414 if (!@$mail = popen($sendmail, 'w')) {
1415 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1416 }
1417 fputs($mail, $header);
1418 fputs($mail, $body);
1419 $result = pclose($mail);
1420 $this->doCallback(
1421 ($result == 0),
1422 $this->to,
1423 $this->cc,
1424 $this->bcc,
1425 $this->Subject,
1426 $body,
1427 $this->From
1428 );
1429 if ($result != 0) {
1430 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
1431 }
1432 }
1433 return true;
1434 }

References $header, $result, doCallback(), and lang().

Referenced by postSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serverHostname()

PHPMailer::serverHostname ( )
protected

Get the server hostname.

Returns 'localhost.localdomain' if unknown. @access protected

Returns
string

Definition at line 3290 of file class.phpmailer.php.

3291 {
3292 $result = 'localhost.localdomain';
3293 if (!empty($this->Hostname)) {
3295 } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
3296 $result = $_SERVER['SERVER_NAME'];
3297 } elseif (function_exists('gethostname') && gethostname() !== false) {
3298 $result = gethostname();
3299 } elseif (php_uname('n') !== false) {
3300 $result = php_uname('n');
3301 }
3302 return $result;
3303 }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

References $_SERVER, $Hostname, and $result.

Referenced by createHeader(), PHPMailerOAuth\smtpConnect(), and smtpConnect().

+ Here is the caller graph for this function:

◆ set()

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

Set or reset instance properties.

You should avoid this function - it's more verbose, less efficient, more error-prone and harder to debug than setting properties directly. Usage Example: ‘$mail->set('SMTPSecure’, 'tls');` is the same as: ‘$mail->SMTPSecure = 'tls’;` @access public

Parameters
string$nameThe property name to set
mixed$valueThe value to set the property to
Returns
boolean @TODO Should this not be using the __set() magic function?

Definition at line 3703 of file class.phpmailer.php.

3704 {
3705 if (property_exists($this, $name)) {
3706 $this->$name = $value;
3707 return true;
3708 } else {
3709 $this->setError($this->lang('variable_set') . $name);
3710 return false;
3711 }
3712 }

References lang(), and setError().

+ Here is the call graph for this function:

◆ setError()

PHPMailer::setError (   $msg)
protected

Add an error message to the error container.

@access protected

Parameters
string$msg
Returns
void

Definition at line 3249 of file class.phpmailer.php.

3250 {
3251 $this->error_count++;
3252 if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
3253 $lasterror = $this->smtp->getError();
3254 if (!empty($lasterror['error'])) {
3255 $msg .= $this->lang('smtp_error') . $lasterror['error'];
3256 if (!empty($lasterror['detail'])) {
3257 $msg .= ' Detail: '. $lasterror['detail'];
3258 }
3259 if (!empty($lasterror['smtp_code'])) {
3260 $msg .= ' SMTP code: ' . $lasterror['smtp_code'];
3261 }
3262 if (!empty($lasterror['smtp_code_ex'])) {
3263 $msg .= ' Additional SMTP info: ' . $lasterror['smtp_code_ex'];
3264 }
3265 }
3266 }
3267 $this->ErrorInfo = $msg;
3268 }

References lang().

Referenced by addAnAddress(), addAttachment(), addEmbeddedImage(), addOrEnqueueAnAddress(), encodeFile(), encodeString(), postSend(), preSend(), send(), set(), setFrom(), and smtpSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFrom()

PHPMailer::setFrom (   $address,
  $name = '',
  $auto = true 
)

Set the From and FromName properties.

Parameters
string$address
string$name
boolean$autoWhether to also set the Sender address, defaults to true
Exceptions
phpmailerException
Returns
boolean

Definition at line 1017 of file class.phpmailer.php.

1018 {
1019 $address = trim($address);
1020 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
1021 // Don't validate now addresses with IDN. Will be done in send().
1022 if (($pos = strrpos($address, '@')) === false or
1023 (!$this->has8bitChars(substr($address, ++$pos)) or !$this->idnSupported()) and
1024 !$this->validateAddress($address)) {
1025 $error_message = $this->lang('invalid_address') . " (setFrom) $address";
1026 $this->setError($error_message);
1027 $this->edebug($error_message);
1028 if ($this->exceptions) {
1029 throw new phpmailerException($error_message);
1030 }
1031 return false;
1032 }
1033 $this->From = $address;
1034 $this->FromName = $name;
1035 if ($auto) {
1036 if (empty($this->Sender)) {
1037 $this->Sender = $address;
1038 }
1039 }
1040 return true;
1041 }

References edebug(), has8bitChars(), idnSupported(), lang(), setError(), and validateAddress().

+ Here is the call graph for this function:

◆ setLanguage()

PHPMailer::setLanguage (   $langcode = 'en',
  $lang_path = '' 
)

Set the language for error messages.

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

Parameters
string$langcodeISO 639-1 2-character language code (e.g. French is "fr")
string$lang_pathPath to the language file directory, with trailing separator (slash)
Returns
boolean @access public

Definition at line 1742 of file class.phpmailer.php.

1743 {
1744 // Backwards compatibility for renamed language codes
1745 $renamed_langcodes = array(
1746 'br' => 'pt_br',
1747 'cz' => 'cs',
1748 'dk' => 'da',
1749 'no' => 'nb',
1750 'se' => 'sv',
1751 );
1752
1753 if (isset($renamed_langcodes[$langcode])) {
1754 $langcode = $renamed_langcodes[$langcode];
1755 }
1756
1757 // Define full set of translatable strings in English
1758 $PHPMAILER_LANG = array(
1759 'authenticate' => 'SMTP Error: Could not authenticate.',
1760 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
1761 'data_not_accepted' => 'SMTP Error: data not accepted.',
1762 'empty_message' => 'Message body empty',
1763 'encoding' => 'Unknown encoding: ',
1764 'execute' => 'Could not execute: ',
1765 'file_access' => 'Could not access file: ',
1766 'file_open' => 'File Error: Could not open file: ',
1767 'from_failed' => 'The following From address failed: ',
1768 'instantiate' => 'Could not instantiate mail function.',
1769 'invalid_address' => 'Invalid address: ',
1770 'mailer_not_supported' => ' mailer is not supported.',
1771 'provide_address' => 'You must provide at least one recipient email address.',
1772 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
1773 'signing' => 'Signing Error: ',
1774 'smtp_connect_failed' => 'SMTP connect() failed.',
1775 'smtp_error' => 'SMTP server error: ',
1776 'variable_set' => 'Cannot set or reset variable: ',
1777 'extension_missing' => 'Extension missing: '
1778 );
1779 if (empty($lang_path)) {
1780 // Calculate an absolute path so it can work if CWD is not here
1781 $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
1782 }
1783 //Validate $langcode
1784 if (!preg_match('/^[a-z]{2}(?:_[a-zA-Z]{2})?$/', $langcode)) {
1785 $langcode = 'en';
1786 }
1787 $foundlang = true;
1788 $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
1789 // There is no English translation file
1790 if ($langcode != 'en') {
1791 // Make sure language file path is readable
1792 if (!is_readable($lang_file)) {
1793 $foundlang = false;
1794 } else {
1795 // Overwrite language-specific strings.
1796 // This way we'll never have missing translation keys.
1797 $foundlang = include $lang_file;
1798 }
1799 }
1800 $this->language = $PHPMAILER_LANG;
1801 return (boolean)$foundlang; // Returns false if language not found
1802 }
$PHPMAILER_LANG['authenticate']

References $PHPMAILER_LANG.

Referenced by lang().

+ Here is the caller graph for this function:

◆ setMessageType()

PHPMailer::setMessageType ( )
protected

Set the message type.

PHPMailer only supports some preset message types, not arbitrary MIME structures. @access protected

Returns
void

Definition at line 2457 of file class.phpmailer.php.

2458 {
2459 $type = array();
2460 if ($this->alternativeExists()) {
2461 $type[] = 'alt';
2462 }
2463 if ($this->inlineImageExists()) {
2464 $type[] = 'inline';
2465 }
2466 if ($this->attachmentExists()) {
2467 $type[] = 'attach';
2468 }
2469 $this->message_type = implode('_', $type);
2470 if ($this->message_type == '') {
2471 //The 'plain' message_type refers to the message having a single body element, not that it is plain-text
2472 $this->message_type = 'plain';
2473 }
2474 }
attachmentExists()
Check if an attachment (non-inline) is present.
inlineImageExists()
Check if an inline attachment is present.

References alternativeExists(), attachmentExists(), and inlineImageExists().

Referenced by preSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setWordWrap()

PHPMailer::setWordWrap ( )

Apply word wrapping to the message body.

Wraps the message body to the number of chars set in the WordWrap property. You should only do this to plain-text bodies as wrapping HTML tags may break them. This is called automatically by createBody(), so you don't need to call it yourself. @access public

Returns
void

Definition at line 2005 of file class.phpmailer.php.

2006 {
2007 if ($this->WordWrap < 1) {
2008 return;
2009 }
2010
2011 switch ($this->message_type) {
2012 case 'alt':
2013 case 'alt_inline':
2014 case 'alt_attach':
2015 case 'alt_inline_attach':
2016 $this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
2017 break;
2018 default:
2019 $this->Body = $this->wrapText($this->Body, $this->WordWrap);
2020 break;
2021 }
2022 }

References wrapText().

Referenced by createBody().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sign()

PHPMailer::sign (   $cert_filename,
  $key_filename,
  $key_pass,
  $extracerts_filename = '' 
)

Set the public and private key files and password for S/MIME signing.

@access public

Parameters
string$cert_filename
string$key_filename
string$key_passPassword for private key
string$extracerts_filenameOptional path to chain certificate

Definition at line 3748 of file class.phpmailer.php.

3749 {
3750 $this->sign_cert_file = $cert_filename;
3751 $this->sign_key_file = $key_filename;
3752 $this->sign_key_pass = $key_pass;
3753 $this->sign_extracerts_file = $extracerts_filename;
3754 }

◆ smtpClose()

PHPMailer::smtpClose ( )

Close the active SMTP session if one exists.

Returns
void

Definition at line 1723 of file class.phpmailer.php.

1724 {
1725 if (is_a($this->smtp, 'SMTP')) {
1726 if ($this->smtp->connected()) {
1727 $this->smtp->quit();
1728 $this->smtp->close();
1729 }
1730 }
1731 }

Referenced by __destruct().

+ Here is the caller graph for this function:

◆ smtpConnect()

PHPMailer::smtpConnect (   $options = null)

Initiate a connection to an SMTP server.

Returns false if the operation failed.

Parameters
array$optionsAn array of options compatible with stream_context_create() @uses SMTP @access public
Exceptions
phpmailerException
Returns
boolean

Reimplemented in PHPMailerOAuth.

Definition at line 1606 of file class.phpmailer.php.

1607 {
1608 if (is_null($this->smtp)) {
1609 $this->smtp = $this->getSMTPInstance();
1610 }
1611
1612 //If no options are provided, use whatever is set in the instance
1613 if (is_null($options)) {
1615 }
1616
1617 // Already connected?
1618 if ($this->smtp->connected()) {
1619 return true;
1620 }
1621
1622 $this->smtp->setTimeout($this->Timeout);
1623 $this->smtp->setDebugLevel($this->SMTPDebug);
1624 $this->smtp->setDebugOutput($this->Debugoutput);
1625 $this->smtp->setVerp($this->do_verp);
1626 $hosts = explode(';', $this->Host);
1627 $lastexception = null;
1628
1629 foreach ($hosts as $hostentry) {
1630 $hostinfo = array();
1631 if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
1632 // Not a valid host entry
1633 continue;
1634 }
1635 // $hostinfo[2]: optional ssl or tls prefix
1636 // $hostinfo[3]: the hostname
1637 // $hostinfo[4]: optional port number
1638 // The host string prefix can temporarily override the current setting for SMTPSecure
1639 // If it's not specified, the default value is used
1640 $prefix = '';
1641 $secure = $this->SMTPSecure;
1642 $tls = ($this->SMTPSecure == 'tls');
1643 if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
1644 $prefix = 'ssl://';
1645 $tls = false; // Can't have SSL and TLS at the same time
1646 $secure = 'ssl';
1647 } elseif ($hostinfo[2] == 'tls') {
1648 $tls = true;
1649 // tls doesn't use a prefix
1650 $secure = 'tls';
1651 }
1652 //Do we need the OpenSSL extension?
1653 $sslext = defined('OPENSSL_ALGO_SHA1');
1654 if ('tls' === $secure or 'ssl' === $secure) {
1655 //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
1656 if (!$sslext) {
1657 throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
1658 }
1659 }
1660 $host = $hostinfo[3];
1661 $port = $this->Port;
1662 $tport = (integer)$hostinfo[4];
1663 if ($tport > 0 and $tport < 65536) {
1664 $port = $tport;
1665 }
1666 if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
1667 try {
1668 if ($this->Helo) {
1669 $hello = $this->Helo;
1670 } else {
1671 $hello = $this->serverHostname();
1672 }
1673 $this->smtp->hello($hello);
1674 //Automatically enable TLS encryption if:
1675 // * it's not disabled
1676 // * we have openssl extension
1677 // * we are not already using SSL
1678 // * the server offers STARTTLS
1679 if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
1680 $tls = true;
1681 }
1682 if ($tls) {
1683 if (!$this->smtp->startTLS()) {
1684 throw new phpmailerException($this->lang('connect_host'));
1685 }
1686 // We must resend EHLO after TLS negotiation
1687 $this->smtp->hello($hello);
1688 }
1689 if ($this->SMTPAuth) {
1690 if (!$this->smtp->authenticate(
1691 $this->Username,
1692 $this->Password,
1693 $this->AuthType,
1694 $this->Realm,
1695 $this->Workstation
1696 )
1697 ) {
1698 throw new phpmailerException($this->lang('authenticate'));
1699 }
1700 }
1701 return true;
1702 } catch (phpmailerException $exc) {
1703 $lastexception = $exc;
1704 $this->edebug($exc->getMessage());
1705 // We must have connected, but then failed TLS or Auth, so close connection nicely
1706 $this->smtp->quit();
1707 }
1708 }
1709 }
1710 // If we get here, all connection attempts have failed, so close connection hard
1711 $this->smtp->close();
1712 // As we've caught all exceptions, just report whatever the last one was
1713 if ($this->exceptions and !is_null($lastexception)) {
1714 throw $lastexception;
1715 }
1716 return false;
1717 }
getSMTPInstance()
Get an instance to use for SMTP operations.

References $Helo, $options, $Port, $SMTPOptions, $SMTPSecure, edebug(), getSMTPInstance(), lang(), and serverHostname().

Referenced by smtpSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smtpSend()

PHPMailer::smtpSend (   $header,
  $body 
)
protected

Send mail via SMTP.

Returns false if there is a bad MAIL FROM, RCPT, or DATA input. Uses the PHPMailerSMTP class by default.

See also
PHPMailer::getSMTPInstance() to use a different class.
Parameters
string$headerThe message headers
string$bodyThe message body
Exceptions
phpmailerException@uses SMTP @access protected
Returns
boolean

Definition at line 1543 of file class.phpmailer.php.

1544 {
1545 $bad_rcpt = array();
1546 if (!$this->smtpConnect($this->SMTPOptions)) {
1547 throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
1548 }
1549 if (!empty($this->Sender) and $this->validateAddress($this->Sender)) {
1550 $smtp_from = $this->Sender;
1551 } else {
1552 $smtp_from = $this->From;
1553 }
1554 if (!$this->smtp->mail($smtp_from)) {
1555 $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
1556 throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
1557 }
1558
1559 // Attempt to send to all recipients
1560 foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
1561 foreach ($togroup as $to) {
1562 if (!$this->smtp->recipient($to[0])) {
1563 $error = $this->smtp->getError();
1564 $bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
1565 $isSent = false;
1566 } else {
1567 $isSent = true;
1568 }
1569 $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
1570 }
1571 }
1572
1573 // Only send the DATA command if we have viable recipients
1574 if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
1575 throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
1576 }
1577 if ($this->SMTPKeepAlive) {
1578 $this->smtp->reset();
1579 } else {
1580 $this->smtp->quit();
1581 $this->smtp->close();
1582 }
1583 //Create error message for any bad addresses
1584 if (count($bad_rcpt) > 0) {
1585 $errstr = '';
1586 foreach ($bad_rcpt as $bad) {
1587 $errstr .= $bad['to'] . ': ' . $bad['error'];
1588 }
1589 throw new phpmailerException(
1590 $this->lang('recipients_failed') . $errstr,
1591 self::STOP_CONTINUE
1592 );
1593 }
1594 return true;
1595 }
smtpConnect($options=null)
Initiate a connection to an SMTP server.

References $From, $header, $Sender, $to, doCallback(), lang(), setError(), smtpConnect(), and validateAddress().

Referenced by postSend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ textLine()

PHPMailer::textLine (   $value)

Return a formatted mail line.

@access public

Parameters
string$value
Returns
string

Definition at line 2494 of file class.phpmailer.php.

2495 {
2496 return $value . $this->LE;
2497 }

References $LE.

Referenced by createBody(), getBoundary(), and getMailMIME().

+ Here is the caller graph for this function:

◆ utf8CharBoundary()

PHPMailer::utf8CharBoundary (   $encodedText,
  $maxLength 
)

Find the last character boundary prior to $maxLength in a utf-8 quoted-printable encoded string.

Original written by Colin Brown. @access public

Parameters
string$encodedTextutf-8 QP text
integer$maxLengthFind the last character boundary prior to this length
Returns
integer

Definition at line 1960 of file class.phpmailer.php.

1961 {
1962 $foundSplitPos = false;
1963 $lookBack = 3;
1964 while (!$foundSplitPos) {
1965 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
1966 $encodedCharPos = strpos($lastChunk, '=');
1967 if (false !== $encodedCharPos) {
1968 // Found start of encoded character byte within $lookBack block.
1969 // Check the encoded byte value (the 2 chars after the '=')
1970 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
1971 $dec = hexdec($hex);
1972 if ($dec < 128) {
1973 // Single byte character.
1974 // If the encoded char was found at pos 0, it will fit
1975 // otherwise reduce maxLength to start of the encoded char
1976 if ($encodedCharPos > 0) {
1977 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
1978 }
1979 $foundSplitPos = true;
1980 } elseif ($dec >= 192) {
1981 // First byte of a multi byte character
1982 // Reduce maxLength to split at start of character
1983 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
1984 $foundSplitPos = true;
1985 } elseif ($dec < 192) {
1986 // Middle byte of a multi byte character, look further back
1987 $lookBack += 3;
1988 }
1989 } else {
1990 // No encoded character found
1991 $foundSplitPos = true;
1992 }
1993 }
1994 return $maxLength;
1995 }

Referenced by wrapText().

+ Here is the caller graph for this function:

◆ validateAddress()

static PHPMailer::validateAddress (   $address,
  $patternselect = null 
)
static

Check that a string looks like an email address.

Parameters
string$addressThe email address to check
string | callable$patternselectA selector for the validation pattern to use :
  • auto Pick best pattern automatically;
  • pcre8 Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
  • pcre Use old PCRE implementation;
  • php Use PHP built-in FILTER_VALIDATE_EMAIL;
  • html5 Use the pattern given by the HTML5 spec for 'email' type form input elements.
  • noregex Don't use a regex: super fast, really dumb. Alternatively you may pass in a callable to inject your own validator, for example: PHPMailer::validateAddress('user@.nosp@m.exam.nosp@m.ple.c.nosp@m.om', function($address) { return (strpos($address, '@') !== false); }); You can also set the PHPMailer::$validator static to a callable, allowing built-in methods to use your validator.
Returns
boolean

@access public

Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains. 2009-2010 Michael Rushton Feel free to use and redistribute this code. But please keep this copyright notice. This is the pattern used in the HTML5 spec for validation of 'email' type form input elements. http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)

Definition at line 1074 of file class.phpmailer.php.

1075 {
1076 if (is_null($patternselect)) {
1077 $patternselect = self::$validator;
1078 }
1079 if (is_callable($patternselect)) {
1080 return call_user_func($patternselect, $address);
1081 }
1082 //Reject line breaks in addresses; it's valid RFC5322, but not RFC5321
1083 if (strpos($address, "\n") !== false or strpos($address, "\r") !== false) {
1084 return false;
1085 }
1086 if (!$patternselect or $patternselect == 'auto') {
1087 //Check this constant first so it works when extension_loaded() is disabled by safe mode
1088 //Constant was added in PHP 5.2.4
1089 if (defined('PCRE_VERSION')) {
1090 //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
1091 if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
1092 $patternselect = 'pcre8';
1093 } else {
1094 $patternselect = 'pcre';
1095 }
1096 } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
1097 //Fall back to older PCRE
1098 $patternselect = 'pcre';
1099 } else {
1100 //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
1101 if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
1102 $patternselect = 'php';
1103 } else {
1104 $patternselect = 'noregex';
1105 }
1106 }
1107 }
1108 switch ($patternselect) {
1109 case 'pcre8':
1116 return (boolean)preg_match(
1117 '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
1118 '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\‍((?>(?2)' .
1119 '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\‍)))+(?2))|(?2))?)' .
1120 '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
1121 '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
1122 '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
1123 '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
1124 '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
1125 '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
1126 $address
1127 );
1128 case 'pcre':
1129 //An older regex that doesn't need a recent PCRE
1130 return (boolean)preg_match(
1131 '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
1132 '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
1133 '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
1134 '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
1135 '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
1136 '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
1137 '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
1138 '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
1139 '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
1140 '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
1141 $address
1142 );
1143 case 'html5':
1148 return (boolean)preg_match(
1149 '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
1150 '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
1151 $address
1152 );
1153 case 'noregex':
1154 //No PCRE! Do something _very_ approximate!
1155 //Check the address is 3 chars or longer and contains an @ that's not the first or last char
1156 return (strlen($address) >= 3
1157 and strpos($address, '@') >= 1
1158 and strpos($address, '@') != strlen($address) - 1);
1159 case 'php':
1160 default:
1161 return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
1162 }
1163 }
static $validator

References $validator.

Referenced by addAnAddress(), mailSend(), parseAddresses(), preSend(), setFrom(), and smtpSend().

+ Here is the caller graph for this function:

◆ wrapText()

PHPMailer::wrapText (   $message,
  $length,
  $qp_mode = false 
)

Word-wrap message.

For use with mailers that do not automatically perform wrapping and for quoted-printable encoded messages. Original written by philippe.

Parameters
string$messageThe message to wrap
integer$lengthThe line length to wrap to
boolean$qp_modeWhether to run in Quoted-Printable mode @access public
Returns
string

Definition at line 1861 of file class.phpmailer.php.

1862 {
1863 if ($qp_mode) {
1864 $soft_break = sprintf(' =%s', $this->LE);
1865 } else {
1866 $soft_break = $this->LE;
1867 }
1868 // If utf-8 encoding is used, we will need to make sure we don't
1869 // split multibyte characters when we wrap
1870 $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
1871 $lelen = strlen($this->LE);
1872 $crlflen = strlen(self::CRLF);
1873
1874 $message = $this->fixEOL($message);
1875 //Remove a trailing line break
1876 if (substr($message, -$lelen) == $this->LE) {
1877 $message = substr($message, 0, -$lelen);
1878 }
1879
1880 //Split message into lines
1881 $lines = explode($this->LE, $message);
1882 //Message will be rebuilt in here
1883 $message = '';
1884 foreach ($lines as $line) {
1885 $words = explode(' ', $line);
1886 $buf = '';
1887 $firstword = true;
1888 foreach ($words as $word) {
1889 if ($qp_mode and (strlen($word) > $length)) {
1890 $space_left = $length - strlen($buf) - $crlflen;
1891 if (!$firstword) {
1892 if ($space_left > 20) {
1893 $len = $space_left;
1894 if ($is_utf8) {
1895 $len = $this->utf8CharBoundary($word, $len);
1896 } elseif (substr($word, $len - 1, 1) == '=') {
1897 $len--;
1898 } elseif (substr($word, $len - 2, 1) == '=') {
1899 $len -= 2;
1900 }
1901 $part = substr($word, 0, $len);
1902 $word = substr($word, $len);
1903 $buf .= ' ' . $part;
1904 $message .= $buf . sprintf('=%s', self::CRLF);
1905 } else {
1906 $message .= $buf . $soft_break;
1907 }
1908 $buf = '';
1909 }
1910 while (strlen($word) > 0) {
1911 if ($length <= 0) {
1912 break;
1913 }
1914 $len = $length;
1915 if ($is_utf8) {
1916 $len = $this->utf8CharBoundary($word, $len);
1917 } elseif (substr($word, $len - 1, 1) == '=') {
1918 $len--;
1919 } elseif (substr($word, $len - 2, 1) == '=') {
1920 $len -= 2;
1921 }
1922 $part = substr($word, 0, $len);
1923 $word = substr($word, $len);
1924
1925 if (strlen($word) > 0) {
1926 $message .= $part . sprintf('=%s', self::CRLF);
1927 } else {
1928 $buf = $part;
1929 }
1930 }
1931 } else {
1932 $buf_o = $buf;
1933 if (!$firstword) {
1934 $buf .= ' ';
1935 }
1936 $buf .= $word;
1937
1938 if (strlen($buf) > $length and $buf_o != '') {
1939 $message .= $buf_o . $soft_break;
1940 $buf = $word;
1941 }
1942 }
1943 $firstword = false;
1944 }
1945 $message .= $buf . self::CRLF;
1946 }
1947
1948 return $message;
1949 }
utf8CharBoundary($encodedText, $maxLength)
Find the last character boundary prior to $maxLength in a utf-8 quoted-printable encoded string.

References $LE, CRLF, fixEOL(), and utf8CharBoundary().

Referenced by encodeHeader(), and setWordWrap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $action_function

PHPMailer::$action_function = ''

Definition at line 451 of file class.phpmailer.php.

◆ $all_recipients

PHPMailer::$all_recipients = array()
protected

Definition at line 511 of file class.phpmailer.php.

Referenced by getAllRecipientAddresses().

◆ $AllowEmpty

PHPMailer::$AllowEmpty = false

Definition at line 383 of file class.phpmailer.php.

◆ $AltBody

PHPMailer::$AltBody = ''

Definition at line 118 of file class.phpmailer.php.

◆ $attachment

PHPMailer::$attachment = array()
protected

◆ $AuthType

PHPMailer::$AuthType = ''

Definition at line 294 of file class.phpmailer.php.

◆ $bcc

PHPMailer::$bcc = array()
protected

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

Referenced by clearBCCs(), doCallback(), and getBccAddresses().

◆ $Body

PHPMailer::$Body = ''

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

Referenced by msgHTML().

◆ $boundary

PHPMailer::$boundary = array()
protected

Definition at line 568 of file class.phpmailer.php.

Referenced by attachAll(), endBoundary(), and getBoundary().

◆ $cc

PHPMailer::$cc = array()
protected

Definition at line 488 of file class.phpmailer.php.

Referenced by clearCCs(), doCallback(), and getCcAddresses().

◆ $CharSet

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

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

Referenced by createBody(), and getBoundary().

◆ $ConfirmReadingTo

PHPMailer::$ConfirmReadingTo = ''

Definition at line 190 of file class.phpmailer.php.

◆ $ContentType

PHPMailer::$ContentType = 'text/plain'

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

Referenced by getBoundary().

◆ $CustomHeader

PHPMailer::$CustomHeader = array()
protected

Definition at line 547 of file class.phpmailer.php.

Referenced by getCustomHeaders().

◆ $Debugoutput

PHPMailer::$Debugoutput = 'echo'

Definition at line 345 of file class.phpmailer.php.

◆ $DKIM_domain

PHPMailer::$DKIM_domain = ''

Definition at line 418 of file class.phpmailer.php.

◆ $DKIM_identity

PHPMailer::$DKIM_identity = ''

Definition at line 404 of file class.phpmailer.php.

◆ $DKIM_passphrase

PHPMailer::$DKIM_passphrase = ''

Definition at line 411 of file class.phpmailer.php.

◆ $DKIM_private

PHPMailer::$DKIM_private = ''

Definition at line 424 of file class.phpmailer.php.

◆ $DKIM_private_string

PHPMailer::$DKIM_private_string = ''

Definition at line 431 of file class.phpmailer.php.

◆ $DKIM_selector

PHPMailer::$DKIM_selector = ''

Definition at line 397 of file class.phpmailer.php.

◆ $do_verp

PHPMailer::$do_verp = false

Definition at line 377 of file class.phpmailer.php.

◆ $Encoding

PHPMailer::$Encoding = '8bit'

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

Referenced by createBody(), and getBoundary().

◆ $error_count

PHPMailer::$error_count = 0
protected

Definition at line 582 of file class.phpmailer.php.

◆ $ErrorInfo

PHPMailer::$ErrorInfo = ''

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

◆ $exceptions

PHPMailer::$exceptions = false
protected

Definition at line 618 of file class.phpmailer.php.

Referenced by __construct().

◆ $From

PHPMailer::$From = 'root@localhost'

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

Referenced by smtpSend().

◆ $FromName

PHPMailer::$FromName = 'Root User'

Definition at line 79 of file class.phpmailer.php.

◆ $Helo

PHPMailer::$Helo = ''

Definition at line 245 of file class.phpmailer.php.

Referenced by PHPMailerOAuth\smtpConnect(), and smtpConnect().

◆ $Host

PHPMailer::$Host = 'localhost'

Definition at line 229 of file class.phpmailer.php.

◆ $Hostname

PHPMailer::$Hostname = ''

Definition at line 199 of file class.phpmailer.php.

Referenced by serverHostname().

◆ $Ical

PHPMailer::$Ical = ''

Definition at line 128 of file class.phpmailer.php.

◆ $language

PHPMailer::$language = array()
protected

Definition at line 575 of file class.phpmailer.php.

Referenced by getTranslations().

◆ $lastMessageID

PHPMailer::$lastMessageID = ''
protected

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

Referenced by getLastMessageID().

◆ $LE

◆ $Mailer

PHPMailer::$Mailer = 'mail'

Definition at line 163 of file class.phpmailer.php.

◆ $mailHeader

PHPMailer::$mailHeader = ''
protected

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

◆ $message_type

PHPMailer::$message_type = ''
protected

Definition at line 561 of file class.phpmailer.php.

◆ $MessageDate

PHPMailer::$MessageDate = ''

Definition at line 216 of file class.phpmailer.php.

◆ $MessageID

PHPMailer::$MessageID = ''

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

Referenced by createHeader().

◆ $MIMEBody

PHPMailer::$MIMEBody = ''
protected

Definition at line 135 of file class.phpmailer.php.

Referenced by getSentMIMEMessage().

◆ $MIMEHeader

PHPMailer::$MIMEHeader = ''
protected

Definition at line 142 of file class.phpmailer.php.

Referenced by preSend().

◆ $Password

PHPMailer::$Password = ''

Definition at line 287 of file class.phpmailer.php.

◆ $PluginDir

PHPMailer::$PluginDir = ''

Definition at line 184 of file class.phpmailer.php.

◆ $Port

PHPMailer::$Port = 25

Definition at line 236 of file class.phpmailer.php.

Referenced by PHPMailerOAuth\smtpConnect(), and smtpConnect().

◆ $Priority

PHPMailer::$Priority = null

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

◆ $Realm

PHPMailer::$Realm = ''

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

◆ $RecipientsQueue

PHPMailer::$RecipientsQueue = array()
protected

Definition at line 523 of file class.phpmailer.php.

Referenced by clearQueuedAddresses().

◆ $ReplyTo

PHPMailer::$ReplyTo = array()
protected

Definition at line 502 of file class.phpmailer.php.

Referenced by getReplyToAddresses().

◆ $ReplyToQueue

PHPMailer::$ReplyToQueue = array()
protected

Definition at line 533 of file class.phpmailer.php.

◆ $ReturnPath

PHPMailer::$ReturnPath = ''

Definition at line 96 of file class.phpmailer.php.

◆ $Sender

PHPMailer::$Sender = ''

Definition at line 86 of file class.phpmailer.php.

Referenced by smtpSend().

◆ $Sendmail

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

Definition at line 169 of file class.phpmailer.php.

◆ $sign_cert_file

PHPMailer::$sign_cert_file = ''
protected

Definition at line 589 of file class.phpmailer.php.

◆ $sign_extracerts_file

PHPMailer::$sign_extracerts_file = ''
protected

Definition at line 603 of file class.phpmailer.php.

◆ $sign_key_file

PHPMailer::$sign_key_file = ''
protected

Definition at line 596 of file class.phpmailer.php.

◆ $sign_key_pass

PHPMailer::$sign_key_pass = ''
protected

Definition at line 611 of file class.phpmailer.php.

◆ $SingleTo

PHPMailer::$SingleTo = false

Definition at line 361 of file class.phpmailer.php.

◆ $SingleToArray

PHPMailer::$SingleToArray = array()

Definition at line 368 of file class.phpmailer.php.

◆ $smtp

PHPMailer::$smtp = null
protected

Definition at line 474 of file class.phpmailer.php.

Referenced by getSMTPInstance().

◆ $SMTPAuth

PHPMailer::$SMTPAuth = false

Definition at line 269 of file class.phpmailer.php.

◆ $SMTPAutoTLS

PHPMailer::$SMTPAutoTLS = true

Definition at line 260 of file class.phpmailer.php.

◆ $SMTPDebug

PHPMailer::$SMTPDebug = 0

Definition at line 329 of file class.phpmailer.php.

◆ $SMTPKeepAlive

PHPMailer::$SMTPKeepAlive = false

Definition at line 353 of file class.phpmailer.php.

◆ $SMTPOptions

PHPMailer::$SMTPOptions = array()

Definition at line 275 of file class.phpmailer.php.

Referenced by smtpConnect().

◆ $SMTPSecure

PHPMailer::$SMTPSecure = ''

Definition at line 252 of file class.phpmailer.php.

Referenced by PHPMailerOAuth\smtpConnect(), and smtpConnect().

◆ $Subject

PHPMailer::$Subject = ''

Definition at line 102 of file class.phpmailer.php.

◆ $Timeout

PHPMailer::$Timeout = 300

Definition at line 315 of file class.phpmailer.php.

◆ $to

PHPMailer::$to = array()
protected

◆ $uniqueid

PHPMailer::$uniqueid = ''
protected

Definition at line 625 of file class.phpmailer.php.

Referenced by createBody().

◆ $Username

PHPMailer::$Username = ''

Definition at line 281 of file class.phpmailer.php.

◆ $UseSendmailOptions

PHPMailer::$UseSendmailOptions = true

Definition at line 176 of file class.phpmailer.php.

◆ $validator

PHPMailer::$validator = 'auto'
static

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

Referenced by validateAddress().

◆ $Version

PHPMailer::$Version = '5.2.22'

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

◆ $WordWrap

PHPMailer::$WordWrap = 0

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

◆ $Workstation

PHPMailer::$Workstation = ''

Definition at line 308 of file class.phpmailer.php.

◆ $XMailer

PHPMailer::$XMailer = ''

Definition at line 458 of file class.phpmailer.php.

◆ CRLF

const PHPMailer::CRLF = "\r\n"

SMTP RFC standard line ending.

Definition at line 645 of file class.phpmailer.php.

Referenced by msgHTML(), preSend(), and wrapText().

◆ MAX_LINE_LENGTH

const PHPMailer::MAX_LINE_LENGTH = 998

Definition at line 651 of file class.phpmailer.php.

◆ STOP_CONTINUE

const PHPMailer::STOP_CONTINUE = 1

Error severity: message, likely ok to continue processing.

Definition at line 635 of file class.phpmailer.php.

◆ STOP_CRITICAL

const PHPMailer::STOP_CRITICAL = 2

Error severity: message, plus full stop, critical error reached.

Definition at line 640 of file class.phpmailer.php.

◆ STOP_MESSAGE

const PHPMailer::STOP_MESSAGE = 0

Error severity: message only, continue processing.

Definition at line 630 of file class.phpmailer.php.


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