Email
						
						
						
							in package
							
						
					
					
					
					
					The email class
This class is a tool to send mails
Table of Contents
Properties
- $altBody : string|null
 - The alternative body
 - $attachedFiles : array<string|int, mixed>
 - Attached files to mail as list of filename
 - $headers : array<string|int, mixed>
 - The email headers
 - $htmlBody : string|null
 - The HTML body
 - $mimeBoundary : array<string|int, mixed>
 - The mime boundary
 - $subject : string
 - The mail subject
 - $textBody : string|null
 - The text body
 
Methods
- __construct() : mixed
 - Constructor
 - addFile() : static
 - Add a file to the files list
 - containsFile() : bool
 - Check if this file is in the files list
 - containsFiles() : bool
 - Check if the file list contains any file
 - escape() : string
 - Escape the string for mails
 - escapeB64() : string
 - Escape the string using base64 encoding
 - getBoundary() : string
 - Get a boundary
 - getMimeType() : string
 - Get the mime type of file
 - hasMultiplesContents() : bool
 - Check if this mail contains multiple contents
 - is_email() : bool
 - Check if the given mail address is valid
 - isAlternative() : bool
 - Check if this mail is an alternative mail
 - isHtml() : bool
 - Check if this mail is a HTML mail
 - isText() : bool
 - Check if this mail is a TEXT mail
 - removeFile() : static
 - Remove a file from the files list
 - send() : void
 - Send the mail to the given address You can pass an array of address to send it to multiple recipients.
 - setAltBody() : static
 - Set the alternative body of the mail
 - setHeader() : static
 - Set the value of a header
 - setHtmlBody() : static
 - Set the html body of the mail
 - setReplyTo() : static
 - Set the ReplyTo value of the mail
 - setSender() : static
 - Set the Sender value of the mail.
 - setSubject() : static
 - Set the subject of the mail
 - setText() : static
 - Set the mail content to the html text
 - setTextBody() : static
 - Set the text body of the mail
 - formatHtmlBody() : string
 - Convert body to email-compliant HTML
 - initialize() : void
 - Initialize the object
 
Properties
$altBody
The alternative body
								private
								string|null
								$altBody
								= null
						
						
						$attachedFiles
Attached files to mail as list of filename
								private
								array<string|int, mixed>
								$attachedFiles
								= []
						
						
						$headers
The email headers
								private
								array<string|int, mixed>
								$headers
								= [
    'MIME-Version' => '',
    'Content-Type' => 'text/plain, charset=UTF-8',
    'Content-Transfer-Encoding' => '',
    //'Content-Transfer-Encoding' => '7bit',
    'Date' => '',
    //See init()
    'From' => 'no-reply@nodomain.com',
    //Override PHP's default
    'Sender' => '',
    'X-Sender' => '',
    'Reply-To' => '',
    'Return-Path' => '',
    'Organization' => '',
    'Bcc' => '',
]
						
						
						$htmlBody
The HTML body
								private
								string|null
								$htmlBody
								= null
						
						
						$mimeBoundary
The mime boundary
								private
								array<string|int, mixed>
								$mimeBoundary
								= []
						
						
						$subject
The mail subject
								private
								string
								$subject
							
						
						
						$textBody
The text body
								private
								string|null
								$textBody
								= null
						
						
						Methods
__construct()
Constructor
								public
								__construct([string $subject = '' ][, string $text = '' ]) : mixed
							
							Parameters
- $subject : string = ''
 - 
									
The subject of the mail. Default value is an empty string.
 - $text : string = ''
 - 
									
The body of the message, used as text and html. Default value is an empty string.
 
addFile()
Add a file to the files list
								public
								addFile(string $filename) : static
							
							Parameters
- $filename : string
 - 
									
The file name
 
Return values
staticcontainsFile()
Check if this file is in the files list
								public
								containsFile(string $filename) : bool
							
							Parameters
- $filename : string
 - 
									
The file name
 
Return values
bool —True if this file is in the attached files list
containsFiles()
Check if the file list contains any file
								public
								containsFiles() : bool
							
							Return values
bool —True if the file list is not empty
escape()
Escape the string for mails
								public
								static escape(string $string) : string
							
							Parameters
- $string : string
 - 
									
The string to escape (converted to string)
 
Return values
string —The escaped string for mails
escapeB64()
Escape the string using base64 encoding
								public
								static escapeB64(mixed $string) : string
							
							Parameters
- $string : mixed
 - 
									
The string to escape (converted to string)
 
Return values
string —The escaped string in base64
getBoundary()
Get a boundary
								public
								getBoundary([int $boundaryInd = 0 ]) : string
							
							Parameters
- $boundaryInd : int = 0
 - 
									
The index of the boundary to get. Default value is 0.
 
Return values
string —The value of the boundary.
getMimeType()
Get the mime type of file
								public
								static getMimeType(string $filename) : string
							
							Parameters
- $filename : string
 - 
									
The file name
 
Return values
string —The mime type of the file
hasMultiplesContents()
Check if this mail contains multiple contents
								public
								hasMultiplesContents() : bool
							
							Return values
bool —True if this object contains multiple contents
is_email()
Check if the given mail address is valid
								public
								static is_email(string $email) : bool
							
							Parameters
- $email : string
 - 
									
The email address
 
Return values
bool —True if this email is valid
isAlternative()
Check if this mail is an alternative mail
								public
								isAlternative() : bool
							
							Return values
bool —True if this object has an alternative message
isHtml()
Check if this mail is a HTML mail
								public
								isHtml() : bool
							
							Return values
bool —True if this object has an HTML message
isText()
Check if this mail is a TEXT mail
								public
								isText() : bool
							
							Return values
bool —True if this object has a TEXT message
removeFile()
Remove a file from the files list
								public
								removeFile(string $filename) : static
							
							Parameters
- $filename : string
 - 
									
The file name
 
Return values
staticsend()
Send the mail to the given address You can pass an array of address to send it to multiple recipients.
								public
								send(string|array<string|int, mixed> $toAddress) : void
							
							Parameters
- $toAddress : string|array<string|int, mixed>
 - 
									
The email address to send this mail
 
setAltBody()
Set the alternative body of the mail
								public
								setAltBody(string $body) : static
							
							Parameters
- $body : string
 - 
									
The new body.
 
Return values
staticsetHeader()
Set the value of a header
								public
								setHeader(string $key, string $value) : static
							
							Parameters
- $key : string
 - 
									
The key of the header to set.
 - $value : string
 - 
									
The new value of the header.
 
Return values
staticsetHtmlBody()
Set the html body of the mail
								public
								setHtmlBody(string $body) : static
							
							Parameters
- $body : string
 - 
									
The new body
 
Return values
staticsetReplyTo()
Set the ReplyTo value of the mail
								public
								setReplyTo(string $email) : static
							
							Parameters
- $email : string
 - 
									
The email address to send this mail
 
Return values
staticsetSender()
Set the Sender value of the mail.
								public
								setSender(string $senderEmail[, string|null $senderName = null ][, bool $allowReply = true ]) : static
							
							This function also sets the ReplyTo value if undefined. If a sender name is provided, it sets the "From" header to NOM <EMAIL>
Parameters
- $senderEmail : string
 - 
									
The email address to send this mail
 - $senderName : string|null = null
 - 
									
The email address to send this mail. Default value is null.
 - $allowReply : bool = true
 - 
									
True to use this address as reply address. Default value is true.
 
Return values
staticsetSubject()
Set the subject of the mail
								public
								setSubject(string $subject) : static
							
							Parameters
- $subject : string
 - 
									
The new subject
 
Return values
staticsetText()
Set the mail content to the html text
								public
								setText(string $text) : static
							
							Parameters
- $text : string
 - 
									
The new text for the mail contents
 
Return values
staticsetTextBody()
Set the text body of the mail
								public
								setTextBody(string $body) : static
							
							Parameters
- $body : string
 - 
									
The new body
 
Return values
staticformatHtmlBody()
Convert body to email-compliant HTML
								protected
								static formatHtmlBody(string $body) : string
							
							Parameters
- $body : string
 
Return values
stringinitialize()
Initialize the object
								private
								initialize() : void