noalyss Version-9
Public Member Functions | Protected Attributes
Sendmail_Core Class Reference

Description of Sendmail. More...

+ Inheritance diagram for Sendmail_Core:
+ Collaboration diagram for Sendmail_Core:

Public Member Functions

 __construct ()
 
 add_file (FileToSend $file)
 Add file to the message. More...
 
 add_supplemental_header ()
 Function to override if supplemental header are needed. More...
 
 compose ()
 create the message before sending More...
 
 mailto ($p_mailto)
 set the recipient More...
 
 send ()
 Send email. More...
 
 set_from ($p_from)
 set the from More...
 
 set_message ($p_message)
 body of the message (utf8) More...
 
 set_subject ($p_subject)
 
 verify ()
 verify that the message is ready to go More...
 

Protected Attributes

 $afile
 
 $content
 
 $from
 
 $header
 
 $mailto
 
 $message
 
 $subject
 

Detailed Description

Description of Sendmail.

API for sending email.

Author
dany

Definition at line 38 of file sendmail_core.class.php.

Constructor & Destructor Documentation

◆ __construct()

Sendmail_Core::__construct ( )

Definition at line 49 of file sendmail_core.class.php.

50 {
51 }

Member Function Documentation

◆ add_file()

Sendmail_Core::add_file ( FileToSend  $file)

Add file to the message.

Parameters
FileToSend$filefile to add to the message

Definition at line 94 of file sendmail_core.class.php.

95 {
96 $this->afile[] = $file;
97 }

References $file.

◆ add_supplemental_header()

Sendmail_Core::add_supplemental_header ( )

Function to override if supplemental header are needed.

Returns
string

Definition at line 121 of file sendmail_core.class.php.

122 {
123 return '';
124 }

Referenced by compose().

◆ compose()

Sendmail_Core::compose ( )

create the message before sending

Definition at line 128 of file sendmail_core.class.php.

129 {
130 $this->verify();
131 $this->header="";
132 $this->content="";
133
134 // a random hash will be necessary to send mixed content
135 $separator = md5(time());
136
137 // carriage return type (we use a PHP end of line constant)
138 $eol = PHP_EOL;
139
140 // main header (multipart mandatory)
141 $this->header = "From: " . $this->from . $eol;
142 $this->header .= "MIME-Version: 1.0" . $eol;
143 $this->header .= $this->add_supplemental_header();
144 $this->header .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" ;
145
146 // message
147 $this->content .= "--" . $separator . $eol;
148 $this->content .= "Content-Type: text/plain; charset=\"utf-8\"" . $eol;
149 $this->content .= "Content-Transfer-Encoding: 7bit" . $eol.$eol ;
150 $this->content .= $this->message . $eol ;
151 if ( ! empty($this->afile ) )
152 {
153 // attachment
154 for ($i = 0; $i < count($this->afile); $i++)
155 {
156
157 $file = $this->afile[$i];
158 $file_size = filesize($file->full_name);
159 $handle = fopen($file->full_name, "r");
160 if ( $handle == false ){
161 \record_log("SC159 ".var_export($file,true));
162 throw new Exception ('SC159 email not send file not added'.$file->full_name);
163 }
164 $content = fread($handle, $file_size);
165 fclose($handle);
166 $content = chunk_split(base64_encode($content));
167 $this->content .= "--" . $separator . $eol;
168 $this->content .= "Content-Type: " . $file->type . "; name=\"" . $file->filename . "\"" . $eol;
169 $this->content .= "Content-Disposition: attachment; filename=\"" . $file->filename . "\"" . $eol;
170 $this->content .= "Content-Transfer-Encoding: base64" . $eol;
171 $this->content.=$eol;
172 $this->content .= $content . $eol ;
173 }
174 }
175 if ( empty ($this->afile) ) $this->content.=$eol;
176
177 $this->content .= "--" . $separator . "--";
178 }
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
$anc_grandlivre from
else $card content[$j]['j_montant']
add_supplemental_header()
Function to override if supplemental header are needed.
verify()
verify that the message is ready to go

References $content, $file, $i, add_supplemental_header(), content, from, record_log(), and verify().

+ Here is the call graph for this function:

◆ mailto()

Sendmail_Core::mailto (   $p_mailto)

set the recipient

Parameters
type$p_mailtohas the form name email.nosp@m.@ema.nosp@m.il.co.nosp@m.m

Definition at line 75 of file sendmail_core.class.php.

76 {
77 $this->mailto = $p_mailto;
78 }
mailto($p_mailto)
set the recipient

References mailto().

Referenced by mailto(), Sendmail\send(), and send().

+ Here is the call graph for this function:

◆ send()

Sendmail_Core::send ( )

Send email.

Exceptions
Exception

Reimplemented in Sendmail.

Definition at line 184 of file sendmail_core.class.php.

185 {
186 try {
187 $this->verify();
188
189 } catch (Exception $e) {
190 throw $e;
191 }
192
193 if (!mail($this->mailto, $this->subject, $this->content,$this->header))
194 {
195 throw new Exception('send failed');
196 }
197 }

References $e, content, mailto(), and verify().

+ Here is the call graph for this function:

◆ set_from()

Sendmail_Core::set_from (   $p_from)

set the from

Parameters
$p_fromhas the form name info@.nosp@m.phpc.nosp@m.ompta.nosp@m..eu

Definition at line 57 of file sendmail_core.class.php.

58 {
59 $this->from = $p_from;
60 }

References from.

◆ set_message()

Sendmail_Core::set_message (   $p_message)

body of the message (utf8)

Parameters
type$p_message

Definition at line 84 of file sendmail_core.class.php.

85 {
86 // $this->message =wordwrap($p_message,70,"\r\n");
87 $this->message =$p_message;
88 }

◆ set_subject()

Sendmail_Core::set_subject (   $p_subject)
Parameters
$p_subjectset the subject

Definition at line 66 of file sendmail_core.class.php.

67 {
68 $this->subject = $p_subject;
69 }

◆ verify()

Sendmail_Core::verify ( )

verify that the message is ready to go

Exceptions
Exception

Reimplemented in Sendmail.

Definition at line 103 of file sendmail_core.class.php.

104 {
105 $array = explode(",", "from,subject,mailto,message");
106 for ($i = 0; $i < count($array); $i++)
107 {
108 $name = $array[$i];
109 if (trim($this->$name??"") == "")
110 {
111 throw new Exception( sprintf(_("%s est vide"),$name),EXC_INVALID);
112 }
113 }
114 }
const EXC_INVALID
Definition: constant.php:346

References $array, $i, $name, and EXC_INVALID.

Referenced by compose(), and send().

Field Documentation

◆ $afile

Sendmail_Core::$afile
protected

Definition at line 42 of file sendmail_core.class.php.

◆ $content

Sendmail_Core::$content
protected

Definition at line 46 of file sendmail_core.class.php.

Referenced by compose().

◆ $from

Sendmail_Core::$from
protected

Definition at line 45 of file sendmail_core.class.php.

◆ $header

Sendmail_Core::$header
protected

Definition at line 47 of file sendmail_core.class.php.

◆ $mailto

Sendmail_Core::$mailto
protected

Definition at line 41 of file sendmail_core.class.php.

◆ $message

Sendmail_Core::$message
protected

Definition at line 44 of file sendmail_core.class.php.

◆ $subject

Sendmail_Core::$subject
protected

Definition at line 43 of file sendmail_core.class.php.


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