Project
category Email Transport
package SMTPMailer (formerly MailSend)
author Andy Prevost
copyright 2004-2023 (C) Andy Prevost - All Rights Reserved
version 1.1.0
license MIT - Distributed under the MIT License
namespace codeworxtech\SMTPMailer;
class SMTPMailer
const
scope property default value comments
const VERSION '1.1.0'  
const CRLF "\r\n"  
const EOL "\n";  
const MAILSEP ", "  
const TIMEVAL 30;  
private
scope property default value comments
private $addparams  
private $attachments []  
private $bcc  
private $boundary []  
private $charset utf-8  
private $cc  
private $confirm_read  
private $custom_hdr []  
private $date_rfc2060  
private $encode_hdr base64  
private $encode_msg 8bit  
private $messageType  
private $messageProtocol [imap,mail,popen,proc,smtp]  
private $num_inline 0  
private $recipients  
private $recipients_rt  
private $replyTo  
private $sender  
private $sendmailPath  
private $total_attach []  
private $wraplen 70  
private $timeStart  
private $SMTP_err  
private $SMTP_errstr  
private $SMTP_Stream 0  
public
scope property default value comments
public $useIMAP false  
public $useSMTP true  
public $Debug NULL debug has a cap
public $imapAddToSent false  
public $imapHost  
public $imapPort 143/imap/notls  
public $imapUsername  
public $imapPassword  
public $MessageICal  
public $MessageHTML  
public $MessageText  
public $mimeMail  
public $priority 0  
public $subject  
public $SMTP_Account []  
public $SMTP_Debug false  
public $SMTP_Domain  
public $SMTP_From  
public $SMTP_Host  
public $SMTP_KeepAlive false  
public $SMTP_Options [];  
public $SMTP_Password  
public $SMTP_Port  
public $SMTP_Username  
public $SMTP_Useverp false  
Methods
scope function params comments
public AddAttachment $path, $name='', $encoding='base64', $type='' Adds an attachment from a path on the filesystem.
Returns false if the file could not be found
or accessed.
@param string $path Path to the attachment.
@param string $name Overrides the attachment name.
@param string $encoding File encoding (see $Encoding).
@param string $type File extension (MIME) type.
@return bool
public AddBCC $param Add a BCC
@param string $bcc
public AddCC $param Add a CC
@param string $cc
public AddCustomHeader $custom_header Adds a custom header
private AddEmbeddedImage $path, $cid, $name='', $encoding='base64', $type='' Adds an embedded attachment. This can include images (backgrounds,etc).
@param string $path Path (location) of attachment.
@param string $cid Content ID of the attachment. Use to identify
the Id for accessing the image in an HTML doc.
@param string $name Overrides the attachment name.
@param string $encoding Mime encoding.
@param string $type File extension.
@return bool
public AddMessageToSent $message="",$folder="INBOX.Sent",$options=null Adds email message to IMAP INBOX.Sent
@param string $message (optional)
@param string $folder (optional)
@param string $options (optional)
public AddRecipient $param Add a recipient
@param string $email
public AddStringAttachment $string, $filename, $encoding='base64', $type='' Adds a string or binary attachment (non-filesystem) to the list.
This method can be used to attach ascii or binary data,
such as a BLOB record from a database.
@param string $string String attachment data.
@param string $filename Name of the attachment.
@param string $encoding File encoding (see $Encoding).
@param string $type File extension (MIME) type.
@return void
private BuildAttachment $attachment='',$bkey='wrap'  
private BuildBody Builds the message body
@return string All parts of the body (text, HTML, attachments)
private BuildHeader $type='proc' Builds email header
@return string
private Data2HTML $content, $basedir = '' Sets the HTML message and returns modifications for inline images and backgrounds
will also set text message if it does not exist (can over ride)
@param string $content content of the HTML message
@param string $basedir directory to the location of the images (relative to file)
private Email_CleanList $data accepts string or array containing email addresses (separated by
comma) in almost any format - can be single address or multiple
with or without correct spacing, quote marks
removes items without emails
@var string or array
@return string
private Email_Extract $str extracts email address from a string
@var string
@return string
private Email_FilterEmail $email clean (shell safe) email addresses
@var string
@return string
private Email_FilterName $name clean (shell safe) name (from email address)
@var string
@return string
private Email_Format_RFC $arr,$str='' structured array containing email address, mailbox, host, name
@var array
@return string
private Email_GetName $str accepts string
@var string
@return string
private Email_Str2Array $str accepts string containing email addresses in almost any format
@var array
@return string
private GetBoundary $type,$end='' Creates the boundary line / end boundary line
@param string $type = wrap, body, spec, none
@param string $end (optional, triggers adding two dashes at end)
@return string (boundary line)
private GetContentTypeBody $type,$charset,$encoding,$cid='' Creates the Content-Type directive for the body
@param string $type = multipart/mixed / multipart/related / multipart/alternative
@param string $charset
@param string $encoding
@param string $cid (optional)
@return string (content type line)
private GetContentTypeHdr $type,$bkey Creates the Content-Type directive for the header
type = multipart/mixed / multipart/related / multipart/alternative
bkey = boundary (wrap / body / spec)
@return string (content type line)
private GetIcsPart $boundary,$hdr='' Builds ICS/iCalendar portion of message
@return string
private GetMailServer $url='',$validate='no_test' dual use method
1- with only $url passed, either a host or path (string) and returns the MX record domain name
2- with a fully qualified mail server passed, returns true/false if an MX record matches
@param string $url
@param string $validate
@return string (mail server) (if $validate is 'no_test' and mail server found)
@return bool (if no mail server found)
private static GetMimeType $resource,$type='file' Gets MIME type of file or string
if file: USE ONLY AFTER VERIFYING FILE EXISTS
if string: designed for file data read in as string, will not properly detect html vs text
returns 'application/octet-stream' if not found (or file encoded)
@param string $resource (filename or string)
@param string $type ('string' or 'file', defaults to 'file')
@return string
protected GetMsgPart $bkey Builds plain text and HTML portion of message
@return string
protected getMsgType $type='' Gets email message type
@return string
protected static IsExploitPath $path Check file path for possible exploits and vulnerabilities.
- exploits: LFI/File manipulation, Directory traversal, File disclosure, Encoding, RCE
@param string $path Relative or absolute path to a file
@return bool
private IsMultibyte $str Checks string for multibyte characters
@param $str string
@return bool (true if multibyte)
protected static IsPathSafe $path Check if file path is safe (real, accessible, not executable).
@param string $path Relative or absolute path to a file
@return bool
protected static IsShellSafe $str Prevent attacks by disallowing unsafe shell characters.
Modified version (Thanks to Paul Buonopane )
@param string $string (the string to be tested for shell safety)
@return bool
private MbEncode $str,$len=70 Encodes and wraps long multibyte strings for mail headers
without breaking lines within a character
validates $str as multibyte
@param string $str multi-byte string to encode
@return string
private SafeStr $str Filter data (ascii and url-encoded) to prevent header injection
@param string $str String
@return string (trimmed)
public Send Send the email
@return bool
protected TransportIMAP $body,$hdr Security to ALL the data and email addresses
must occur BEFORE calling this function
@return bool
protected TransportSendmail $body Security to ALL the data and email addresses
must occur BEFORE calling this function
@return bool
protected TransportSMTP $body,$hdr Security to ALL the data and email addresses
must occur BEFORE calling this function
@return bool
public SetAddParams $params Set additional parameter for mail() function
@param string $parameter
@return void
public SetBodyText $content Set plain text
@param string $content
public SetConfirmRead $param Set email address for confirm email is read
@param string $email The email address
public SetConfirmReceipt $param Set email address for confirm email is received
@param string $email The email address
public SetPriority $param Set priority
@param integer $param - from 1 (highest) to 5 (lowest)
@return bool
public SetReplyTo $param Set replyTo
@param string $email
@return bool
public SetSender $param Set sender
@param mixed (string or array) $email/$name
public SetSubject $subject Set subject
@param string $subject The subject of the email
public useSMTP $param=true Uses SMTP transport by default, set to false to use Sendmail as default
@param bool
public useIMAP $param=true Uses SMTP transport by default, set to false to use Sendmail as default
@param bool
public SetSMTPAccount $array Sets SMTP Account (Username and password)
@return mixed
public SetSMTPhost $param Set SMTP host
@param string $param
public SetSMTPport $param Set SMTP port
@param integer $param
public SetSMTPpass $param Set SMTP password
@param string $param
public SetSMTPuser $param Set SMTP username
@param string $param
private SMTP_Connect Connect to the server
return code: 220 success
@return bool
private SMTP_Data $hdr,$body Sends header and message to SMTP Server
return code: 250 success (possible 251, have to allow for this)
@return bool
private SMTP_Envelope Send envelope to SMTP Server
@return bool
private SMTP_GetResponse $expected,$desc='' Get response code returned by SMTP server
@return string $code
private SMTP_IsStreamConnected $error_msg='Not connected to SMTP server, aborting.' Returns true if connected to a server otherwise false
@access public
@return bool
private SMTP_Quit Sends QUIT to SMTP Server then closes the stream
return code: 221 success
@return bool
private SMTP_Reset Implements RFC 821: RSET
return code 250 success
@return bool
private StrSplitUnicode $str, $length = 998 splits a string into an array of max length $l
@return array
public ThrowResponse $code,$desc,$data,$success=true