PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
← All changes | site/class/smtp_message.php +574 -0 1.6.3 → 1.8.16 View file →
@@ -1,0 +1,574 @@
1 +<?php
2 +/**
3 + * @package VikBooking
4 + * @subpackage com_vikbooking
5 + * @author Alessio Gaggii - e4j - Extensionsforjoomla.com
6 + * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved.
7 + * @license GNU General Public License version 2 or later; see LICENSE
8 + * @link https://vikwp.com
9 + */
10 +
11 +defined('ABSPATH') or die('No script kiddies please!');
12 +
13 +class smtp_message_class extends email_message_class
14 +{
15 + /* Private variables */
16 +
17 + var $smtp;
18 + var $line_break="\r\n";
19 + var $delivery = 0;
20 +
21 + /* Public variables */
22 +
23 +/*
24 +{metadocument}
25 + <variable>
26 + <name>localhost</name>
27 + <type>STRING</type>
28 + <value></value>
29 + <documentation>
30 + <purpose>Specify the domain name of the computer sending the
31 + message.</purpose>
32 + <usage>This value is used to identify the sending machine to the
33 + SMTP server. When using the direct delivery mode, if this variable
34 + is set to a non-empty string it used to generate the
35 + <tt>Recieved</tt> header to show that the message passed by the
36 + specified host address. To prevent confusing directly delivered
37 + messages with spam, it is strongly recommended that you set this
38 + variable to you server host name.</usage>
39 + </documentation>
40 + </variable>
41 +{/metadocument}
42 +*/
43 + var $localhost="";
44 +
45 +/*
46 +{metadocument}
47 + <variable>
48 + <name>smtp_host</name>
49 + <type>STRING</type>
50 + <value></value>
51 + <documentation>
52 + <purpose>Specify the address of the SMTP server.</purpose>
53 + <usage>Set to the address of the SMTP server that will relay the
54 + messages. This variable is not used in direct delivery mode.</usage>
55 + </documentation>
56 + </variable>
57 +{/metadocument}
58 +*/
59 + var $smtp_host="localhost";
60 +
61 +/*
62 +{metadocument}
63 + <variable>
64 + <name>smtp_port</name>
65 + <type>INTEGER</type>
66 + <value>25</value>
67 + <documentation>
68 + <purpose>Specify the TCP/IP port of SMTP server to connect.</purpose>
69 + <usage>Most servers work on port 25 . Certain e-mail services use
70 + alternative ports to avoid firewall blocking. Gmail uses port
71 + <integervalue>465</integervalue>.</usage>
72 + </documentation>
73 + </variable>
74 +{/metadocument}
75 +*/
76 + var $smtp_port=25;
77 +
78 +/*
79 +{metadocument}
80 + <variable>
81 + <name>smtp_ssl</name>
82 + <type>BOOLEAN</type>
83 + <value>0</value>
84 + <documentation>
85 + <purpose>Specify whether it should use secure connections with SSL
86 + to connect to the SMTP server.</purpose>
87 + <usage>Certain e-mail services like Gmail require SSL connections.</usage>
88 + </documentation>
89 + </variable>
90 +{/metadocument}
91 +*/
92 + var $smtp_ssl=0;
93 +
94 +/*
95 +{metadocument}
96 + <variable>
97 + <name>smtp_start_tls</name>
98 + <type>BOOLEAN</type>
99 + <value>0</value>
100 + <documentation>
101 + <purpose>Specify whether it should use secure connections starting
102 + TLS protocol after connecting to the SMTP server.</purpose>
103 + <usage>Certain e-mail services like Hotmail require starting TLS
104 + protocol after the connection to the SMTP server is already
105 + established.</usage>
106 + </documentation>
107 + </variable>
108 +{/metadocument}
109 +*/
110 + var $smtp_start_tls=0;
111 +
112 +/*
113 +{metadocument}
114 + <variable>
115 + <name>smtp_direct_delivery</name>
116 + <type>BOOLEAN</type>
117 + <value>0</value>
118 + <documentation>
119 + <purpose>Boolean flag that indicates whether the message should be
120 + sent in direct delivery mode.</purpose>
121 + <usage>Set this to <tt><booleanvalue>1</booleanvalue></tt> if you
122 + want to send urgent messages directly to the recipient domain SMTP
123 + server.</usage>
124 + </documentation>
125 + </variable>
126 +{/metadocument}
127 +*/
128 + var $smtp_direct_delivery=0;
129 +
130 +/*
131 +{metadocument}
132 + <variable>
133 + <name>smtp_getmxrr</name>
134 + <type>STRING</type>
135 + <value>getmxrr</value>
136 + <documentation>
137 + <purpose>Specify the name of the function that is called to determine
138 + the SMTP server address of a given domain.</purpose>
139 + <usage>Change this to a working replacement of the PHP
140 + <tt>getmxrr()</tt> function if this is not working in your system
141 + and you want to send messages in direct delivery mode.</usage>
142 + </documentation>
143 + </variable>
144 +{/metadocument}
145 +*/
146 + var $smtp_getmxrr="getmxrr";
147 +
148 +/*
149 +{metadocument}
150 + <variable>
151 + <name>smtp_exclude_address</name>
152 + <type>STRING</type>
153 + <value></value>
154 + <documentation>
155 + <purpose>Specify an address that should be considered invalid
156 + when resolving host name addresses.</purpose>
157 + <usage>In some networks any domain name that does not exist is
158 + resolved as a sub-domain of the default local domain. If the DNS is
159 + configured in such way that it always resolves any sub-domain of
160 + the default local domain to a given address, it is hard to
161 + determine whether a given domain does not exist.<paragraphbreak />
162 + If your network is configured this way, you may set this variable
163 + to the address that all sub-domains of the default local domain
164 + resolves, so the class can assume that such address is invalid.</usage>
165 + </documentation>
166 + </variable>
167 +{/metadocument}
168 +*/
169 + var $smtp_exclude_address="";
170 +
171 +/*
172 +{metadocument}
173 + <variable>
174 + <name>smtp_user</name>
175 + <type>STRING</type>
176 + <value></value>
177 + <documentation>
178 + <purpose>Specify the user name for authentication.</purpose>
179 + <usage>Set this variable if you need to authenticate before sending
180 + a message.</usage>
181 + </documentation>
182 + </variable>
183 +{/metadocument}
184 +*/
185 + var $smtp_user="";
186 +
187 +/*
188 +{metadocument}
189 + <variable>
190 + <name>smtp_realm</name>
191 + <type>STRING</type>
192 + <value></value>
193 + <documentation>
194 + <purpose>Specify the user authentication realm.</purpose>
195 + <usage>Set this variable if you need to authenticate before sending
196 + a message.</usage>
197 + </documentation>
198 + </variable>
199 +{/metadocument}
200 +*/
201 + var $smtp_realm="";
202 +
203 +/*
204 +{metadocument}
205 + <variable>
206 + <name>smtp_workstation</name>
207 + <type>STRING</type>
208 + <value></value>
209 + <documentation>
210 + <purpose>Specify the user authentication workstation needed when
211 + using the <tt>NTLM</tt> authentication (Windows or Samba).</purpose>
212 + <usage>Set this variable if you need to authenticate before sending
213 + a message.</usage>
214 + </documentation>
215 + </variable>
216 +{/metadocument}
217 +*/
218 + var $smtp_workstation="";
219 +
220 +/*
221 +{metadocument}
222 + <variable>
223 + <name>smtp_authentication_mechanism</name>
224 + <type>STRING</type>
225 + <value></value>
226 + <documentation>
227 + <purpose>Specify the user authentication mechanism that should be
228 + used when authenticating with the SMTP server.</purpose>
229 + <usage>Set this variable if you need to force the SMTP connection to
230 + authenticate with a specific authentication mechanism. Leave this
231 + variable with an empty string if you want the authentication
232 + mechanism be determined automatically from the list of mechanisms
233 + supported by the server.</usage>
234 + </documentation>
235 + </variable>
236 +{/metadocument}
237 +*/
238 + var $smtp_authentication_mechanism="";
239 +
240 +/*
241 +{metadocument}
242 + <variable>
243 + <name>smtp_password</name>
244 + <type>STRING</type>
245 + <value></value>
246 + <documentation>
247 + <purpose>Specify the user authentication password.</purpose>
248 + <usage>Set this variable if you need to authenticate before sending
249 + a message.</usage>
250 + </documentation>
251 + </variable>
252 +{/metadocument}
253 +*/
254 + var $smtp_password="";
255 +
256 +/*
257 +{metadocument}
258 + <variable>
259 + <name>smtp_pop3_auth_host</name>
260 + <type>STRING</type>
261 + <value></value>
262 + <documentation>
263 + <purpose>Specify the server address for POP3 based authentication.</purpose>
264 + <usage>Set this variable to the address of the POP3 server if the
265 + SMTP server requires POP3 based authentication.</usage>
266 + </documentation>
267 + </variable>
268 +{/metadocument}
269 +*/
270 + var $smtp_pop3_auth_host="";
271 +
272 +/*
273 +{metadocument}
274 + <variable>
275 + <name>smtp_debug</name>
276 + <type>BOOLEAN</type>
277 + <value>0</value>
278 + <documentation>
279 + <purpose>Specify whether it is necessary to output SMTP connection
280 + debug information.</purpose>
281 + <usage>Set this variable to
282 + <tt><booleanvalue>1</booleanvalue></tt> if you need to see
283 + the progress of the SMTP connection and protocol dialog when you
284 + need to understand the reason for delivery problems.</usage>
285 + </documentation>
286 + </variable>
287 +{/metadocument}
288 +*/
289 + var $smtp_debug=0;
290 +
291 +/*
292 +{metadocument}
293 + <variable>
294 + <name>smtp_html_debug</name>
295 + <type>BOOLEAN</type>
296 + <value>0</value>
297 + <documentation>
298 + <purpose>Specify whether the debug information should be outputted in
299 + HTML format.</purpose>
300 + <usage>Set this variable to
301 + <tt><booleanvalue>1</booleanvalue></tt> if you need to see
302 + the debug output in a Web page.</usage>
303 + </documentation>
304 + </variable>
305 +{/metadocument}
306 +*/
307 + var $smtp_html_debug=0;
308 +
309 +/*
310 +{metadocument}
311 + <variable>
312 + <name>esmtp</name>
313 + <type>BOOLEAN</type>
314 + <value>1</value>
315 + <documentation>
316 + <purpose>Specify whether the class should try to use Enhanced SMTP
317 + protocol features.</purpose>
318 + <usage>It is recommended to leave this variable set to
319 + <tt><booleanvalue>1</booleanvalue></tt> so the class can take
320 + advantage of Enhanced SMTP protocol features.</usage>
321 + </documentation>
322 + </variable>
323 +{/metadocument}
324 +*/
325 + var $esmtp=1;
326 +
327 +/*
328 +{metadocument}
329 + <variable>
330 + <name>timeout</name>
331 + <type>INTEGER</type>
332 + <value>25</value>
333 + <documentation>
334 + <purpose>Specify the connection timeout period in seconds.</purpose>
335 + <usage>Change this value if for some reason the timeout period seems
336 + insufficient or otherwise it seems too long.</usage>
337 + </documentation>
338 + </variable>
339 +{/metadocument}
340 +*/
341 + var $timeout=55;
342 +
343 +/*
344 +{metadocument}
345 + <variable>
346 + <name>invalid_recipients</name>
347 + <type>ARRAY</type>
348 + <value></value>
349 + <documentation>
350 + <purpose>Return the list of recipient addresses that were not
351 + accepted by the SMTP server.</purpose>
352 + <usage>Check this variable after attempting to send a message to
353 + figure whether there were any recipients that were rejected by the
354 + SMTP server.</usage>
355 + </documentation>
356 + </variable>
357 +{/metadocument}
358 +*/
359 + var $invalid_recipients=array();
360 +
361 +/*
362 +{metadocument}
363 + <variable>
364 + <name>mailer_delivery</name>
365 + <value>smtp $Revision: 1.34 $</value>
366 + <documentation>
367 + <purpose>Specify the text that is used to identify the mail
368 + delivery class or sub-class. This text is appended to the
369 + <tt>X-Mailer</tt> header text defined by the
370 + mailer variable.</purpose>
371 + <usage>Do not change this variable.</usage>
372 + </documentation>
373 + </variable>
374 +{/metadocument}
375 +*/
376 + var $mailer_delivery='smtp $Revision: 1.34 $';
377 +
378 +/*
379 +{metadocument}
380 + <variable>
381 + <name>maximum_bulk_deliveries</name>
382 + <type>INTEGER</type>
383 + <value>100</value>
384 + <documentation>
385 + <purpose>Specify the number of consecutive bulk mail deliveries
386 + without disconnecting.</purpose>
387 + <usage>Lower this value if you have enabled the bulk mail mode but
388 + the SMTP server does not accept sending more than a number of
389 + messages within the same SMTP connection.<paragraphbreak />
390 + Set this value to <integervalue>0</integervalue> to never
391 + disconnect during bulk mail mode unless an error occurs.</usage>
392 + </documentation>
393 + </variable>
394 +{/metadocument}
395 +*/
396 + var $maximum_bulk_deliveries=100;
397 +
398 + Function SetRecipients(&$recipients,&$valid_recipients)
399 + {
400 + for($valid_recipients=$recipient=0,Reset($recipients);$recipient<count($recipients);Next($recipients),$recipient++)
401 + {
402 + $address=Key($recipients);
403 + if($this->smtp->SetRecipient($address))
404 + $valid_recipients++;
405 + else
406 + $this->invalid_recipients[$address]=$this->smtp->error;
407 + }
408 + return(1);
409 + }
410 +
411 + Function ResetConnection($error)
412 + {
413 + if(IsSet($this->smtp))
414 + {
415 + if(!$this->smtp->Disconnect()
416 + && strlen($error) == 0)
417 + $error = $this->smtp->error;
418 + UnSet($this->smtp);
419 + }
420 + if(strlen($error))
421 + $this->OutputError($error);
422 + return($error);
423 + }
424 +
425 + Function StartSendingMessage()
426 + {
427 + if(function_exists("class_exists")
428 + && !class_exists("smtp_class"))
429 + return("the smtp_class class was not included");
430 + if(IsSet($this->smtp))
431 + return("");
432 + $this->smtp=new smtp_class;
433 + $this->smtp->localhost=$this->localhost;
434 + $this->smtp->host_name=$this->smtp_host;
435 + $this->smtp->host_port=$this->smtp_port;
436 + $this->smtp->ssl=$this->smtp_ssl;
437 + $this->smtp->start_tls=$this->smtp_start_tls;
438 + $this->smtp->timeout=$this->timeout;
439 + $this->smtp->debug=$this->smtp_debug;
440 + $this->smtp->html_debug=$this->smtp_html_debug;
441 + $this->smtp->direct_delivery=$this->smtp_direct_delivery;
442 + $this->smtp->getmxrr=$this->smtp_getmxrr;
443 + $this->smtp->exclude_address=$this->smtp_exclude_address;
444 + $this->smtp->pop3_auth_host=$this->smtp_pop3_auth_host;
445 + $this->smtp->user=$this->smtp_user;
446 + $this->smtp->realm=$this->smtp_realm;
447 + $this->smtp->workstation=$this->smtp_workstation;
448 + $this->smtp->authentication_mechanism=$this->smtp_authentication_mechanism;
449 + $this->smtp->password=$this->smtp_password;
450 + $this->smtp->esmtp=$this->esmtp;
451 + if($this->smtp->Connect())
452 + {
453 + $this->delivery = 0;
454 + return("");
455 + }
456 + return($this->ResetConnection($this->smtp->error));
457 + }
458 +
459 + Function SendMessageHeaders($headers)
460 + {
461 + $header_data="";
462 + $date=date("D, d M Y H:i:s T");
463 + if($this->smtp_direct_delivery
464 + && strlen($this->localhost))
465 + {
466 + $local_ip=gethostbyname($this->localhost);
467 + $header_data.=$this->FormatHeader("Received","FROM ".$this->localhost." ([".$local_ip."]) BY ".$this->localhost." ([".$local_ip."]) WITH SMTP; ".$date)."\r\n";
468 + }
469 + for($message_id_set=$date_set=0,$header=0,$return_path=$from=$to=$recipients=array(),Reset($headers);$header<count($headers);$header++,Next($headers))
470 + {
471 + $header_name=Key($headers);
472 + switch(strtolower($header_name))
473 + {
474 + case "return-path":
475 + $return_path[$headers[$header_name]]=1;
476 + break;
477 + case "from":
478 + $error=$this->GetRFC822Addresses($headers[$header_name],$from);
479 + break;
480 + case "to":
481 + $error=$this->GetRFC822Addresses($headers[$header_name],$to);
482 + break;
483 + case "cc":
484 + case "bcc":
485 + $this->GetRFC822Addresses($headers[$header_name],$recipients);
486 + break;
487 + case "date":
488 + $date_set=1;
489 + break;
490 + case "message-id":
491 + $message_id_set=1;
492 + break;
493 + }
494 + if(strcmp($error,""))
495 + return($this->ResetConnection($error));
496 + if(strtolower($header_name)=="bcc")
497 + continue;
498 + $header_data.=$this->FormatHeader($header_name,$headers[$header_name])."\r\n";
499 + }
500 + if(count($from)==0)
501 + return($this->ResetConnection("it was not specified a valid From header"));
502 + Reset($return_path);
503 + Reset($from);
504 + $this->invalid_recipients=array();
505 + if(!$this->smtp->MailFrom(count($return_path) ? Key($return_path) : Key($from)))
506 + return($this->ResetConnection($this->smtp->error));
507 + $r = 0;
508 + if(count($to))
509 + {
510 + if(!$this->SetRecipients($to,$valid_recipients))
511 + return($this->ResetConnection($this->smtp->error));
512 + $r += $valid_recipients;
513 + }
514 + if(!$date_set)
515 + $header_data.="Date: ".$date."\r\n";
516 + if(!$message_id_set
517 + && $this->auto_message_id)
518 + {
519 + $sender=(count($return_path) ? Key($return_path) : Key($from));
520 + $header_data.=$this->GenerateMessageID($sender)."\r\n";
521 + }
522 + if(count($recipients))
523 + {
524 + if(!$this->SetRecipients($recipients,$valid_recipients))
525 + return($this->ResetConnection($this->smtp->error));
526 + $r += $valid_recipients;
527 + }
528 + if($r==0)
529 + return($this->ResetConnection("it were not specified any valid recipients"));
530 + if(!$this->smtp->StartData()
531 + || !$this->smtp->SendData($header_data."\r\n"))
532 + return($this->ResetConnection($this->smtp->error));
533 + return("");
534 + }
535 +
536 + Function SendMessageBody($data)
537 + {
538 + return($this->smtp->SendData($this->smtp->PrepareData($data)) ? "" : $this->ResetConnection($this->smtp->error));
539 + }
540 +
541 + Function EndSendingMessage()
542 + {
543 + return($this->smtp->EndSendingData() ? "" : $this->ResetConnection($this->smtp->error));
544 + }
545 +
546 + Function StopSendingMessage()
547 + {
548 + ++$this->delivery;
549 + if($this->bulk_mail
550 + && !$this->smtp_direct_delivery
551 + && ($this->maximum_bulk_deliveries == 0
552 + || $this->delivery < $this->maximum_bulk_deliveries))
553 + return("");
554 + return($this->ResetConnection(''));
555 + }
556 +
557 + Function ChangeBulkMail($on)
558 + {
559 + if($on
560 + || !IsSet($this->smtp))
561 + return(1);
562 + return($this->smtp->Disconnect() ? "" : $this->ResetConnection($this->smtp->error));
563 + }
564 +};
565 +
566 +/*
567 +
568 +{metadocument}
569 +</class>
570 +{/metadocument}
571 +
572 +*/
573 +
574 +?>