abstract class MailSender

Base class for an email sending strategy (PHP Mail function, SMTP, etc.)

Constants

EMLFILE

PHPMAIL

SMTP

VIRTUAL

CALLBACK_LOG

CALLBACK_LOG_DATA

Properties

protected string[] $params

Methods

static MailSender
factory(string $concreteSenderName, string[]|NULL $params = NULL)

Create an object instance for the strategy

_acknowledgeMailSent()

Callback to the caller when email sent (if needed)

__construct(string[]|NULL $params = NULL)

Constructor

bool|string
doSend(string $to, string $subject, string $mail, string $headers)

Send the email (to be implemented in child classes)

bool
handleBcc(string $to, string $subject, string $mail, string $headers)

Handle Bcc

bool|string
handleSend(string $to, string $subject, string $mail, string $headers)

Prepare for sending the email (we handle here the Bcc case)

handleHeaders_ToSubject(string $to, string $subject, string $mail, string $headers)

Add the To and Subject headers to the headers string

handleHeaders_Priority(string $to, string $subject, string $mail, string $headers)

Handle priority ; we always set high priorty at the moment

handleHeaders(string $to, string $subject, string $mail, string $headers)

Handle headers modifications (to/subject/priority)

bool|string
send(string $to, string $subject, string $mail, string $headers)

Send the email

bool
ready()

Is the sending strategy ready (all required parameters set) ?

destruct()

Destruct strategy (do housecleaning stuff such as closing SMTP connections)

string
getMessage()

Get an error message explaining why the strategy is not ready

Details

at line 49
static MailSender factory(string $concreteSenderName, string[]|NULL $params = NULL)

Create an object instance for the strategy

Parameters

string $concreteSenderName Set this parameter to one of the constants declared in MailSender : EMLFILE, PHPMAIL, SMTP or VIRTUAL
string[]|NULL $params Array of parameters to pass to the strategy constructor

Return Value

MailSender Returns a sending strategy

at line 67
protected _acknowledgeMailSent()

Callback to the caller when email sent (if needed)

at line 80
__construct(string[]|NULL $params = NULL)

Constructor

Parameters

string[]|NULL $params Array of parameters for the sending strategy

at line 98
abstract bool|string doSend(string $to, string $subject, string $mail, string $headers)

Send the email (to be implemented in child classes)

Parameters

string $to Recipient
string $subject Subject ; must be encoded if necessary
string $mail String containing the email data
string $headers Email headers

Return Value

bool|string Returns FALSE if sending is done (no error), or an error string if an error occured

at line 114
bool handleBcc(string $to, string $subject, string $mail, string $headers)

Handle Bcc

With a BCC header, we must do specific things. SMTP does not handle Bcc. When having a Bcc header, we must send a 'normal' email to this Bcc recipient (and removing Bcc header, which the recipient must not see). If multiple recipients, we must send as many emails. When using Php Mail function, it processes Bcc headers that way.

Parameters

string $to Recipient
string $subject Subject ; must be encoded if necessary
string $mail String containing the email data
string $headers Email headers

Return Value

bool Always returns FALSE (no error)

at line 141
bool|string handleSend(string $to, string $subject, string $mail, string $headers)

Prepare for sending the email (we handle here the Bcc case)

Parameters

string $to Recipient
string $subject Subject ; must be encoded if necessary
string $mail String containing the email data
string $headers Email headers

Return Value

bool|string Returns FALSE if sending is done (no error), or an error string if an error occured

at line 159
handleHeaders_ToSubject(string $to, string $subject, string $mail, string $headers)

Add the To and Subject headers to the headers string

Parameters

string $to Recipient
string $subject Subject ; must be encoded if necessary
string $mail String containing the email data
string $headers Email headers

at line 174
handleHeaders_Priority(string $to, string $subject, string $mail, string $headers)

Handle priority ; we always set high priorty at the moment

Parameters

string $to Recipient
string $subject Subject ; must be encoded if necessary
string $mail String containing the email data
string $headers Email headers

at line 190
handleHeaders(string $to, string $subject, string $mail, string $headers)

Handle headers modifications (to/subject/priority)

Parameters

string $to Recipient
string $subject Subject ; must be encoded if necessary
string $mail String containing the email data
string $headers Email headers

at line 206
bool|string send(string $to, string $subject, string $mail, string $headers)

Send the email

Parameters

string $to Recipient
string $subject Subject ; must be encoded if necessary
string $mail String containing the email data
string $headers Email headers

Return Value

bool|string Returns FALSE if sending is done (no error), or an error string if an error occured

at line 233
bool ready()

Is the sending strategy ready (all required parameters set) ?

Return Value

bool Returns TRUE if strategy if ready

at line 239
destruct()

Destruct strategy (do housecleaning stuff such as closing SMTP connections)

at line 247
string getMessage()

Get an error message explaining why the strategy is not ready

Return Value

string Error message