noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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.
 
 add_supplemental_header ()
 Function to override if supplemental header are needed.
 
 compose ()
 create the message before sending
 
 get_format ()
 
 mailto ($p_mailto)
 set the recipient
 
 send ()
 Send email.
 
 set_format ($format)
 format is either HTML or PLAIN
 
 set_from ($p_from)
 set the from
 
 set_message ($p_message)
 body of the message (utf8)
 
 set_subject ($p_subject)
 
 verify ()
 verify that the message is ready to go
 

Protected Attributes

 $afile
 
 $content
 
 $format
 
 $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 $this->format='PLAIN';
52 }

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 111 of file sendmail_core.class.php.

112 {
113 $this->afile[] = $file;
114 }

References $file.

◆ add_supplemental_header()

Sendmail_Core::add_supplemental_header ( )

Function to override if supplemental header are needed.

Returns
string

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

139 {
140 return '';
141 }

Referenced by compose().

◆ compose()

Sendmail_Core::compose ( )

create the message before sending

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

146 {
147 $this->verify();
148 $this->header="";
149 $this->content="";
150
151 // a random hash will be necessary to send mixed content
152 $separator = md5(time());
153
154 // carriage return type (we use a PHP end of line constant)
155 $eol = PHP_EOL;
156
157 // main header (multipart mandatory)
158 $this->header = "From: " . $this->from . $eol;
159 $this->header .= "MIME-Version: 1.0" . $eol;
160 $this->header .= $this->add_supplemental_header();
161 if ($this->format == 'PLAIN')
162 {
163 $this->header .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" ;
164 // message PLAIN
165 $this->content .= "--" . $separator . $eol;
166 $this->content .= "Content-Type: text/plain; charset=UTF-8" . $eol;
167 $this->content .= "Content-Transfer-Encoding: 8bit" . $eol.$eol ;
168 $this->content .= $this->message . $eol ;
169 } elseif ($this->format == 'HTML') {
170 $separator_second=md5(rand());
171
172 $this->header .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" .$eol ;
173 // message PLAIN
174 $this->content .= "--" . $separator . $eol;
175 $this->content .= "Content-Type: multipart/alternative; boundary=\"" . $separator_second . "\"".$eol ;
176 $this->content.= "--$separator_second".$eol;
177 $this->content .= "Content-Type: text/plain; charset=UTF-8; format=flowed".$eol;
178 $this->content .= "Content-Transfer-Encoding: 8bit" . $eol.$eol ;
179 $this->content .= strip_tags($this->message) . $eol ;
180 $this->content.=$eol;
181 $this->content.=$eol;
182 $this->content.=$eol;
183 // message HTML
184 $this->content .= "--" . $separator_second.$eol;
185 $this->content .= "Content-Type: text/html; charset=UTF-8" . $eol;
186 $this->content .= "Content-Transfer-Encoding: 8bit" . $eol.$eol ;
187 $this->content .=<<<eof
188<!DOCTYPE html>{$eol}
189<html>{$eol}
190<head>{$eol}
191
192<meta http-equiv="content-type" content="text/html; charset=UTF-8">{$eol}
193</head>{$eol}
194<body>
195{$eol}
196{$eol}
197{$eol}
198eof;
199 $this->content .= $this->message. $eol ;
200 $this->content .=" </body> </html>".$eol;
201 $this->content .= "--" . $separator_second."--" . $eol;
202
203 }else {
204 throw new \Exception('SC172 : unknow format ');
205 }
206
207 if ( ! empty($this->afile ) )
208 {
209 // attachment
210 for ($i = 0; $i < count($this->afile); $i++)
211 {
212
213 $file = $this->afile[$i];
214 $file_size = filesize($file->full_name);
215 $mimetype=( $file->type=="")?mime_content_type($file->full_name):$file->type;
216 $handle = fopen($file->full_name, "r");
217 if ( $handle == false ){
218 \record_log("SC159 ".var_export($file,true));
219 throw new Exception ('SC159 email not send file not added'.$file->full_name);
220 }
221 $content = fread($handle, $file_size);
222 fclose($handle);
223 $content = chunk_split(base64_encode($content));
224 $this->content .= "--" . $separator . $eol;
225 $this->content .= "Content-Type: " . $mimetype . "; name=\"" . $file->filename . "\"" . $eol;
226 $this->content .= "Content-Disposition: attachment; filename=\"" . $file->filename . "\"" . $eol;
227 $this->content .= "Content-Transfer-Encoding: base64" . $eol;
228 $this->content.=$eol;
229 $this->content .= $content . $eol ;
230 }
231 }
232 if ( empty ($this->afile) ) $this->content.=$eol;
233
234 $this->content .= "--" . $separator . "--";
235 }
$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
if( $delta< 0) elseif( $delta==0)

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

+ Here is the call graph for this function:

◆ get_format()

Sendmail_Core::get_format ( )

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

54 {
55 return $this->format;
56 }

References $format.

◆ 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 92 of file sendmail_core.class.php.

93 {
94 $this->mailto = $p_mailto;
95 }
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 241 of file sendmail_core.class.php.

242 {
243 try {
244 $this->verify();
245
246 } catch (Exception $e) {
247 throw $e;
248 }
249
250 if (!mail($this->mailto, $this->subject, $this->content,$this->header))
251 {
252 throw new Exception('send failed');
253 }
254 }

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

+ Here is the call graph for this function:

◆ set_format()

Sendmail_Core::set_format ( $format)

format is either HTML or PLAIN

Parameters
type$formatHTML or PLAIN
Returns
Sendmail_Core

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

62 {
63 if ( in_array($format,['PLAIN','HTML'] ) == false) {
64 throw new \Exception('SC64 : unknow format ');
65 }
66 $this->format = $format;
67 return $this;
68 }

References $format.

◆ 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 74 of file sendmail_core.class.php.

75 {
76 $this->from = $p_from;
77 }

References from.

◆ set_message()

Sendmail_Core::set_message ( $p_message)

body of the message (utf8)

Parameters
type$p_message

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

102 {
103 // $this->message =wordwrap($p_message,70,"\r\n");
104 $this->message =$p_message;
105 }

◆ set_subject()

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

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

84 {
85 $this->subject = $p_subject;
86 }

◆ verify()

Sendmail_Core::verify ( )

verify that the message is ready to go

Exceptions
Exception

Reimplemented in Sendmail.

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

121 {
122 $array = explode(",", "from,subject,mailto,message");
123 for ($i = 0; $i < count($array); $i++)
124 {
125 $name = $array[$i];
126 if (trim($this->$name??"") == "")
127 {
128 throw new Exception( sprintf(_("%s est vide"),$name),EXC_INVALID);
129 }
130 }
131 }
_("actif, passif,charge,...")
const EXC_INVALID
Definition constant.php:358

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().

◆ $format

Sendmail_Core::$format
protected

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

Referenced by get_format(), and set_format().

◆ $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: