class CMailFile (View source)

Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile->sendfile();

Properties

string $sendcontext
string $sendmode
mixed deprecated $sendsetup
string $subject
string $addr_from
string $reply_to
string $errors_to
string $addr_to
string $addr_cc
string $addr_bcc
string $trackid
string $mixed_boundary
$related_boundary
string $alternative_boundary
int<0, 1> $deliveryreceipt
?int<1, 1> $atleastonefile
string $msg
string $eol
string $eol2
string $error
string[] $errors
SMTPS $smtps
Swift_Mailer $mailer
Swift_SmtpTransport $transport
Swift_Plugins_Loggers_ArrayLogger $logger
string|array<string, string> $css
?string $styleCSS
?string $bodyCSS
string $msgid
string $in_reply_to
string $references
string $headers
string|Swift_Message $message
?string[] $filename_list
?string[] $mimetype_list
?string[] $mimefilename_list
?string[] $cid_list
string $html
int<0, 1> $msgishtml
string $image_boundary
int<0, 1> $atleastoneimage
array<array{type: string, fullpath: string, content_type?: string, name: string, cid: string}> $html_images
array<array{name: string, fullpath: string, content_type: string, cid: string, image_encoded: string}> $images_encoded
$image_types

Methods

__construct(string $subject, string $to, string $from, string $msg, ?string[] $filename_list = array(), ?string[] $mimetype_list = array(), ?string[] $mimefilename_list = array(), string $addr_cc = "", string $addr_bcc = "", int<0, 1> $deliveryreceipt = 0, int<-1, 1> $msgishtml = 0, string $errors_to = '', string|array<string, string> $css = '', string $trackid = '', $moreinheader = '', $sendcontext = 'standard', $replyto = '', $upload_dir_tmp = '', $in_reply_to = '', $references = '')

CMailFile

bool
sendfile()

Send mail that was prepared by constructor.

static string
encodetorfc2822(string $stringtoencode)

Encode subject according to RFC 2822 - http://en.wikipedia.org/wiki/MIME#Encoded-Word

void
dump_mail()

Write content of a SMTP request into a dump file (mode = all) Used for debugging.

void
save_dump_mail_in_err($message = '')

Save content if mail is in error Used for debugging.

string
checkIfHTML(string $msg)

Correct an incomplete html string

void
buildCSS()

Build a css style (mode = all) into this->styleCSS and this->bodyCSS

string
write_smtpheaders()

Create SMTP headers (mode = 'mail')

string
write_mimeheaders(?string[] $filename_list, ?string[] $mimefilename_list)

Create header MIME (mode = 'mail')

string
write_body(string $msgtext)

Return email content (mode = 'mail')

string
write_images(array<array{name: string, fullpath: string, content_type: string, cid: string, image_encoded: string}> $images_list)

Attach an image to email (mode = 'mail')

int
check_server_port(string $host, int $port)

Try to create a socket connection

bool
server_parse(resource $socket, string $response)

This function has been modified as provided by SirSir to allow multiline responses when using SMTP Extensions.

static string
getValidAddress(string $address, int $format, int $encode = 0, int $maxnumberofemail = 0)

Return a formatted address string for SMTP protocol

static array<string, ?string>
getArrayAddress(string $address)

Return a formatted array of address string for SMTP protocol

Details

__construct(string $subject, string $to, string $from, string $msg, ?string[] $filename_list = array(), ?string[] $mimetype_list = array(), ?string[] $mimefilename_list = array(), string $addr_cc = "", string $addr_bcc = "", int<0, 1> $deliveryreceipt = 0, int<-1, 1> $msgishtml = 0, string $errors_to = '', string|array<string, string> $css = '', string $trackid = '', $moreinheader = '', $sendcontext = 'standard', $replyto = '', $upload_dir_tmp = '', $in_reply_to = '', $references = '')

CMailFile

Parameters

string $subject

Topic/Subject of mail

string $to

Recipients emails (RFC 2822: "Name firstname [, ...]" or "email[, ...]" or "[, ...]"). Note: the keyword 'SUPERVISOREMAIL' is not allowed here and must be replaced by caller.

string $from

Sender email (RFC 2822: "Name firstname [, ...]" or "email[, ...]" or "[, ...]")

string $msg Message
?string[] $filename_list

List of files to attach (full path of filename on file system)

?string[] $mimetype_list

List of MIME type of attached files

?string[] $mimefilename_list

List of attached file name in message

string $addr_cc

Email cc (Example: '[email protected], [email protected]')

string $addr_bcc

Email bcc (Note: This is autocompleted with MAIN_MAIL_AUTOCOPY_TO if defined)

int<0, 1> $deliveryreceipt

Ask a delivery receipt

int<-1, 1> $msgishtml

1=String IS already html, 0=String IS NOT html, -1=Unknown make autodetection (with fast mode, not reliable)

string $errors_to

Email for errors-to

string|array<string, string> $css

Css option (should be array, legacy: empty string if none)

string $trackid

Tracking string (contains type and id of related element) @param string $moreinheader More in header. $moreinheader must contains the "\r\n" at end of each line @param string $sendcontext 'standard', 'emailing', 'ticket', 'password', ... (used to define which sending mode and parameters to use) @param string $replyto Reply-to email (will be set to the same value than From by default if not provided) @param string $upload_dir_tmp Temporary directory (used to convert images embedded as img src=data:image) @param string $in_reply_to Message-ID of the message we reply to @param string $references String with list of Message-ID of the thread ('<123> <456> ...')

$moreinheader
$sendcontext
$replyto
$upload_dir_tmp
$in_reply_to
$references

bool sendfile()

Send mail that was prepared by constructor.

Return Value

bool

True if mail sent, false otherwise. Negative int if error in hook. String if incorrect send mode.

static string encodetorfc2822(string $stringtoencode)

Encode subject according to RFC 2822 - http://en.wikipedia.org/wiki/MIME#Encoded-Word

Parameters

string $stringtoencode

String to encode

Return Value

string

string encoded

void dump_mail()

Write content of a SMTP request into a dump file (mode = all) Used for debugging.

Note that to see full SMTP protocol, you can use tcpdump -w /tmp/smtp -s 2000 port 25"

Return Value

void

void save_dump_mail_in_err($message = '')

Save content if mail is in error Used for debugging.

@param string $message Add also a message

Parameters

$message

Return Value

void

string checkIfHTML(string $msg)

Correct an incomplete html string

Parameters

string $msg String

Return Value

string

Completed string

void buildCSS()

Build a css style (mode = all) into this->styleCSS and this->bodyCSS

Return Value

void

string write_smtpheaders()

Create SMTP headers (mode = 'mail')

Return Value

string headers

string write_mimeheaders(?string[] $filename_list, ?string[] $mimefilename_list)

Create header MIME (mode = 'mail')

Parameters

?string[] $filename_list

Array of filenames

?string[] $mimefilename_list

Array of mime types

Return Value

string

mime headers

string write_body(string $msgtext)

Return email content (mode = 'mail')

Parameters

string $msgtext

Message string

Return Value

string

String content

string write_images(array<array{name: string, fullpath: string, content_type: string, cid: string, image_encoded: string}> $images_list)

Attach an image to email (mode = 'mail')

Parameters

array<array{name: string, fullpath: string, content_type: string, cid: string, image_encoded: string}> $images_list

Array of array image

Return Value

string

Chaine images encodees

int check_server_port(string $host, int $port)

Try to create a socket connection

Parameters

string $host

Add ssl:// for SSL/TLS.

int $port

Example: 25, 465

Return Value

int

Socket id if ok, 0 if KO

bool server_parse(resource $socket, string $response)

This function has been modified as provided by SirSir to allow multiline responses when using SMTP Extensions.

Parameters

resource $socket Socket
string $response

Response string

Return Value

bool

true if success

static string getValidAddress(string $address, int $format, int $encode = 0, int $maxnumberofemail = 0)

Return a formatted address string for SMTP protocol

Parameters

string $address

Example: 'John Doe [email protected], Alan Smith [email protected]' or '[email protected], [email protected]'

int $format

Set to 0 = auto, 1 = emails with <>, 2 = emails without <>, 3 = auto + label between "", 4 label or email, 5 mailto link

int $encode

Set to 0 = No encode name, 1 = Encode name to RFC2822

int $maxnumberofemail

Set to 0 = No limit. Otherwise, maximum number of emails returned ($address may contains several email separated with ','). Add '...' if there is more.

Return Value

string

If format 0: '[email protected]' or 'John Doe [email protected]' or '=?UTF-8?B?Sm9obiBEb2U=?= [email protected]' If format 1: '[email protected]' If format 2: '[email protected]' If format 3: '[email protected]' or '"John Doe" [email protected]' or '"=?UTF-8?B?Sm9obiBEb2U=?=" [email protected]' If format 4: 'John Doe' or '[email protected]' if no label exists If format 5: John Doe or [email protected] if no label exists

See also

getArrayAddress()

static array<string, ?string> getArrayAddress(string $address)

Return a formatted array of address string for SMTP protocol

Parameters

string $address

Example: 'John Doe [email protected], Alan Smith [email protected]' or '[email protected], [email protected]'

Return Value

array<string, ?string>

array(email => name)

See also

getValidAddress()