dolibarr  7.0.0-beta
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
CMailFile Class Reference

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); $mailfile->sendfile();. More...

Public Member Functions

 __construct ($subject, $to, $from, $msg, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=0, $errors_to='', $css='', $trackid='', $moreinheader='', $sendcontext='standard')
 CMailFile. More...
 
 sendfile ()
 Send mail that was prepared by constructor. More...
 
 _encode_file ($sourcefile)
 Read a file on disk and return encoded content for emails (mode = 'mail') More...
 
 dump_mail ()
 Write content of a SMTP request into a dump file (mode = all) Used for debugging. More...
 
 checkIfHTML ($msg)
 Correct an uncomplete html string. More...
 
 buildCSS ()
 Build a css style (mode = all) into this->styleCSS and this->bodyCSS. More...
 
 write_smtpheaders ()
 Create SMTP headers (mode = 'mail') More...
 
 write_mimeheaders ($filename_list, $mimefilename_list)
 Create header MIME (mode = 'mail') More...
 
 write_body ($msgtext)
 Return email content (mode = 'mail') More...
 
 write_files ($filename_list, $mimetype_list, $mimefilename_list)
 Attach file to email (mode = 'mail') More...
 
 write_images ($images_list)
 Attach an image to email (mode = 'mail') More...
 
 check_server_port ($host, $port)
 Try to create a socket connection. More...
 
 server_parse ($socket, $response)
 This function has been modified as provided by SirSir to allow multiline responses when using SMTP Extensions. More...
 
 findHtmlImages ($images_dir)
 Seearch images into html message and init array this->images_encoded if found. More...
 
 getArrayAddress ($address)
 Return a formatted array of address string for SMTP protocol. More...
 

Static Public Member Functions

static encodetorfc2822 ($stringtoencode)
 Encode subject according to RFC 2822 - http://en.wikipedia.org/wiki/MIME#Encoded-Word. More...
 
static getValidAddress ($address, $format, $encode=0, $maxnumberofemail=0)
 Return a formatted address string for SMTP protocol. More...
 

Public Attributes

 $styleCSS
 Defined css style for body background.
 
 $bodyCSS
 Defined background directly in body tag.
 

Detailed Description

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); $mailfile->sendfile();.

Definition at line 37 of file CMailFile.class.php.

Constructor & Destructor Documentation

CMailFile::__construct (   $subject,
  $to,
  $from,
  $msg,
  $filename_list = array(),
  $mimetype_list = array(),
  $mimefilename_list = array(),
  $addr_cc = "",
  $addr_bcc = "",
  $deliveryreceipt = 0,
  $msgishtml = 0,
  $errors_to = '',
  $css = '',
  $trackid = '',
  $moreinheader = '',
  $sendcontext = 'standard' 
)

CMailFile.

Parameters
string$subjectTopic/Subject of mail
string$toRecipients emails (RFC 2822: "Name firstname <email>[, ...]" or "email[, ...]" or "<email>[, ...]"). Note: the keyword 'SUPERVISOREMAIL' is not allowed here and must be replaced by caller.
string$fromSender email (RFC 2822: "Name firstname <email>[, ...]" or "email[, ...]" or "<email>[, ...]")
string$msgMessage
array$filename_listList of files to attach (full path of filename on file system)
array$mimetype_listList of MIME type of attached files
array$mimefilename_listList of attached file name in message
string$addr_ccEmail cc
string$addr_bccEmail bcc (Note: This is autocompleted with MAIN_MAIL_AUTOCOPY_TO if defined)
int$deliveryreceiptAsk a delivery receipt
int$msgishtml1=String IS already html, 0=String IS NOT html, -1=Unknown make autodetection (with fast mode, not reliable)
string$errors_toEmail for errors-to
string$cssCss option
string$trackidTracking string (contains type and id of related element)
string$moreinheaderMore in header. $moreinheader must contains the "\r\n" (TODO not supported for other MAIL_SEND_MODE different than 'phpmail' and 'smtps' for the moment)
string$sendcontext'standard', 'emailing', ...

Definition at line 113 of file CMailFile.class.php.

References buildCSS(), checkIfHTML(), dol_syslog(), dol_textishtml(), encodetorfc2822(), findHtmlImages(), getArrayAddress(), getValidAddress(), if, write_body(), write_files(), write_mimeheaders(), and write_smtpheaders().

Member Function Documentation

CMailFile::_encode_file (   $sourcefile)

Read a file on disk and return encoded content for emails (mode = 'mail')

Parameters
string$sourcefilePath to file to encode
Returns
int <0 if KO, encoded string if OK

Definition at line 800 of file CMailFile.class.php.

References dol_osencode(), and dol_syslog().

Referenced by write_files().

CMailFile::buildCSS ( )

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

Returns
css

Definition at line 888 of file CMailFile.class.php.

Referenced by __construct().

CMailFile::check_server_port (   $host,
  $port 
)

Try to create a socket connection.

Parameters
string$hostAdd ssl:// for SSL/TLS.
int$portExample: 25, 465
Returns
int Socket id if ok, 0 if KO

Definition at line 1186 of file CMailFile.class.php.

References dol_syslog(), server_parse(), and utf8_check().

CMailFile::checkIfHTML (   $msg)

Correct an uncomplete html string.

Parameters
string$msgString
Returns
string Completed string

Definition at line 863 of file CMailFile.class.php.

References $bodyCSS, and $styleCSS.

Referenced by __construct(), and write_body().

CMailFile::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"

Returns
void

Definition at line 826 of file CMailFile.class.php.

Referenced by sendfile().

static CMailFile::encodetorfc2822 (   $stringtoencode)
static

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

Parameters
string$stringtoencodeString to encode
Returns
string string encoded

Definition at line 788 of file CMailFile.class.php.

Referenced by __construct(), and sendfile().

CMailFile::findHtmlImages (   $images_dir)

Seearch images into html message and init array this->images_encoded if found.

Parameters
string$images_dirLocation of physical images files
Returns
int >0 if OK, <0 if KO

Definition at line 1279 of file CMailFile.class.php.

References dol_hash().

Referenced by __construct().

CMailFile::getArrayAddress (   $address)

Return a formatted array of address string for SMTP protocol.

Parameters
string$addressExample: 'John Doe john@.nosp@m.doe..nosp@m.com, Alan Smith alan@.nosp@m.smit.nosp@m.h.com' or 'john@.nosp@m.doe..nosp@m.com, alan@.nosp@m.smit.nosp@m.h.com'
Returns
array array of email => name

Definition at line 1448 of file CMailFile.class.php.

Referenced by __construct().

static CMailFile::getValidAddress (   $address,
  $format,
  $encode = 0,
  $maxnumberofemail = 0 
)
static

Return a formatted address string for SMTP protocol.

Parameters
string$addressExample: 'John Doe john@.nosp@m.doe..nosp@m.com, Alan Smith alan@.nosp@m.smit.nosp@m.h.com' or 'john@.nosp@m.doe..nosp@m.com, alan@.nosp@m.smit.nosp@m.h.com'
int$format0=auto, 1=emails with <>, 2=emails without <>, 3=auto + label between "
int$encode0=No encode name, 1=Encode name to RFC2822
int$maxnumberofemail0=No limit. Otherwise, maximum number of emails returned ($address may contains several email separated with ','). Add '...' if there is more.
Returns
string If format 0: 'john@.nosp@m.doe..nosp@m.com' or 'John Doe john@.nosp@m.doe..nosp@m.com' or '=?UTF-8?B?Sm9obiBEb2U=?= john@.nosp@m.doe..nosp@m.com' If format 1: 'john@.nosp@m.doe..nosp@m.com' If format 2: 'john@.nosp@m.doe..nosp@m.com' If format 3: 'john@.nosp@m.doe..nosp@m.com' or '"John Doe" john@.nosp@m.doe..nosp@m.com' or '"=?UTF-8?B?Sm9obiBEb2U=?=" john@.nosp@m.doe..nosp@m.com' If format 4: 'John Doe' or 'john@.nosp@m.doe..nosp@m.com' if no label exists

Definition at line 1381 of file CMailFile.class.php.

Referenced by __construct(), and sendfile().

CMailFile::sendfile ( )

Send mail that was prepared by constructor.

Returns
boolean True if mail sent, false otherwise

Definition at line 489 of file CMailFile.class.php.

References dol_syslog(), dump_mail(), encodetorfc2822(), and getValidAddress().

CMailFile::server_parse (   $socket,
  $response 
)

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

Parameters
Socket$socketSocket
string$responseResponse string
Returns
boolean true if success

Definition at line 1250 of file CMailFile.class.php.

Referenced by check_server_port().

CMailFile::write_body (   $msgtext)

Return email content (mode = 'mail')

Parameters
string$msgtextMessage string
Returns
string String content

Definition at line 1009 of file CMailFile.class.php.

References checkIfHTML(), and write_images().

Referenced by __construct().

CMailFile::write_files (   $filename_list,
  $mimetype_list,
  $mimefilename_list 
)

Attach file to email (mode = 'mail')

Parameters
array$filename_listTableau
array$mimetype_listTableau
array$mimefilename_listTableau
Returns
string Chaine fichiers encodes

Definition at line 1109 of file CMailFile.class.php.

References _encode_file(), and dol_syslog().

Referenced by __construct().

CMailFile::write_images (   $images_list)

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

Parameters
array$images_listTableau
Returns
string Chaine images encodees

Definition at line 1154 of file CMailFile.class.php.

References dol_syslog().

Referenced by write_body().

CMailFile::write_mimeheaders (   $filename_list,
  $mimefilename_list 
)

Create header MIME (mode = 'mail')

Parameters
array$filename_listArray of filenames
array$mimefilename_listArray of mime types
Returns
string mime headers

Definition at line 981 of file CMailFile.class.php.

References dol_syslog().

Referenced by __construct().

CMailFile::write_smtpheaders ( )

Create SMTP headers (mode = 'mail')

Returns
string headers

Definition at line 917 of file CMailFile.class.php.

References dol_syslog().

Referenced by __construct().


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