/
smtps.class.php
1995 lines (1769 loc) · 57.3 KB
/
smtps.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* Copyright (C) Walter Torres <walter@torres.ws> [with a *lot* of help!]
* Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006-2011 Regis Houssin
* Copyright (C) 2016 Jonathan TISSEAU <jonathan.tisseau@86dev.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/class/smtps.class.php
* \brief Class to construct and send SMTP compliant email, even to a secure
* SMTP server, regardless of platform.
* Goals:
* - mime compliant
* - multiple Reciptiants
* - TO
* - CC
* - BCC
* - multi-part message
* - plain text
* - HTML
* - inline attachments
* - attachments
* - GPG access
* This Class is based off of 'SMTP PHP MAIL' by Dirk Paehl, http://www.paehl.de
*/
/**
* Class to construct and send SMTP compliant email, even
* to a secure SMTP server, regardless of platform.
*/
class SMTPs
{
/**
* Host Name or IP of SMTP Server to use
*/
var $_smtpsHost = 'localhost';
/**
* SMTP Server Port definition. 25 is default value
* This can be defined via a INI file or via a setter method
*/
var $_smtpsPort = '25';
/**
* Secure SMTP Server access ID
* This can be defined via a INI file or via a setter method
*/
var $_smtpsID = null;
/**
* Secure SMTP Server access Password
* This can be defined via a INI file or via a setter method
*/
var $_smtpsPW = null;
/**
* Who sent the Message
* This can be defined via a INI file or via a setter method
*/
var $_msgFrom = null;
/**
* Where are replies and errors to be sent to
* This can be defined via a INI file or via a setter method
*/
var $_msgReplyTo = null;
/**
* Who will the Message be sent to; TO, CC, BCC
* Multi-diminsional array containg addresses the message will
* be sent TO, CC or BCC
*/
var $_msgRecipients = null;
/**
* Message Subject
*/
var $_msgSubject = null;
/**
* Message Content
*/
var $_msgContent = null;
/**
* Custom X-Headers
*/
var $_msgXheader = null;
/**
* Character set
* Defaulted to 'iso-8859-1'
*/
var $_smtpsCharSet = 'iso-8859-1';
/**
* Message Sensitivity
* Defaults to ZERO - None
*/
var $_msgSensitivity = 0;
/**
* Message Sensitivity
*/
var $_arySensitivity = array ( false,
'Personal',
'Private',
'Company Confidential' );
/**
* Message Sensitivity
* Defaults to 3 - Normal
*/
var $_msgPriority = 3;
/**
* Message Priority
*/
var $_aryPriority = array ( 'Bulk',
'Highest',
'High',
'Normal',
'Low',
'Lowest' );
/**
* Content-Transfer-Encoding
* Defaulted to 0 - 7bit
*/
var $_smtpsTransEncodeType = 0;
/**
* Content-Transfer-Encoding
*/
var $_smtpsTransEncodeTypes = array( '7bit', // Simple 7-bit ASCII
'8bit', // 8-bit coding with line termination characters
'base64', // 3 octets encoded into 4 sextets with offset
'binary', // Arbitrary binary stream
'mac-binhex40', // Macintosh binary to hex encoding
'quoted-printable', // Mostly 7-bit, with 8-bit characters encoded as "=HH"
'uuencode' ); // UUENCODE encoding
/**
* Content-Transfer-Encoding
* Defaulted to '7bit'
*/
var $_smtpsTransEncode = '7bit';
/**
* Boundary String for MIME seperation
*/
var $_smtpsBoundary = null;
/**
* Related Boundary
*/
var $_smtpsRelatedBoundary = null;
/**
* Alternative Boundary
*/
var $_smtpsAlternativeBoundary = null;
/**
* Determines the method inwhich the message are to be sent.
* - 'sockets' [0] - conect via network to SMTP server - default
* - 'pipe [1] - use UNIX path to EXE
* - 'phpmail [2] - use the PHP built-in mail function
* NOTE: Only 'sockets' is implemented
*/
var $_transportType = 0;
/**
* If '$_transportType' is set to '1', then this variable is used
* to define the UNIX file system path to the sendmail execuable
*/
var $_mailPath = '/usr/lib/sendmail';
/**
* Sets the SMTP server timeout in seconds.
*/
var $_smtpTimeout = 10;
/**
* Determines whether to calculate message MD5 checksum.
*/
var $_smtpMD5 = false;
/**
* Class error codes and messages
*/
var $_smtpsErrors = null;
/**
* Defines log level
* 0 - no logging
* 1 - connectivity logging
* 2 - message generation logging
* 3 - detail logging
*/
var $_log_level = 0;
/**
* Place Class in" debug" mode
*/
var $_debug = false;
// @CHANGE LDR
var $log = '';
var $_errorsTo = '';
var $_deliveryReceipt = 0;
var $_trackId = '';
var $_moreInHeader = '';
/**
* Set delivery receipt
*
* @param int $_val Value
* @return void
*/
function setDeliveryReceipt($_val = 0)
{
$this->_deliveryReceipt = $_val;
}
/**
* get delivery receipt
*
* @return int Delivery receipt
*/
function getDeliveryReceipt()
{
return $this->_deliveryReceipt;
}
/**
* Set trackid
*
* @param string $_val Value
* @return void
*/
function setTrackId($_val = '')
{
$this->_trackId = $_val;
}
/**
* Set moreInHeader
*
* @param string $_val Value
* @return void
*/
function setMoreInHeader($_val = '')
{
$this->_moreinheader = $_val;
}
/**
* get trackid
*
* @return string Track id
*/
function getTrackId()
{
return $this->_trackId;
}
/**
* get moreInHeader
*
* @return string moreInHeader
*/
function getMoreInHeader()
{
return $this->_moreinheader;
}
/**
* Set errors to
*
* @param string $_strErrorsTo Errors to
* @return void
*/
function setErrorsTo($_strErrorsTo)
{
if ( $_strErrorsTo )
$this->_errorsTo = $this->_strip_email($_strErrorsTo);
}
/**
* Get errors to
*
* @param boolean $_part Variant
* @return string Errors to
*/
function getErrorsTo($_part = true )
{
$_retValue = '';
if ( $_part === true )
$_retValue = $this->_errorsTo;
else
$_retValue = $this->_errorsTo[$_part];
return $_retValue;
}
/**
* Set debug
*
* @param boolean $_vDebug Value for debug
* @return void
*/
function setDebug($_vDebug = false )
{
$this->_debug = $_vDebug;
}
/**
* build RECIPIENT List, all addresses who will recieve this message
*
* @return void
*/
function buildRCPTlist()
{
// Pull TO list
$_aryToList = $this->getTO();
}
/**
* Attempt a connection to mail server
*
* @return mixed $_retVal Boolean indicating success or failure on connection
*/
function _server_connect()
{
// Default return value
$_retVal = true;
// We have to make sure the HOST given is valid
// This is done here because '@fsockopen' will not give me this
// information if it failes to connect because it can't find the HOST
$host=$this->getHost();
$host=preg_replace('@tcp://@i','',$host); // Remove prefix
$host=preg_replace('@ssl://@i','',$host); // Remove prefix
// @CHANGE LDR
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
if ( (! is_ip($host)) && ((gethostbyname($host)) == $host))
{
$this->_setErr(99, $host . ' is either offline or is an invalid host name.');
$_retVal = false;
}
else
{
//See if we can connect to the SMTP server
if ($this->socket = @fsockopen(
$this->getHost(), // Host to 'hit', IP or domain
$this->getPort(), // which Port number to use
$this->errno, // actual system level error
$this->errstr, // and any text that goes with the error
$this->_smtpTimeout
)) // timeout for reading/writing data over the socket
{
// Fix from PHP SMTP class by 'Chris Ryan'
// Sometimes the SMTP server takes a little longer to respond
// so we will give it a longer timeout for the first read
// Windows still does not have support for this timeout function
if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0);
// Check response from Server
if ( $_retVal = $this->server_parse($this->socket, "220") )
$_retVal = $this->socket;
}
// This connection attempt failed.
else
{
// @CHANGE LDR
if (empty($this->errstr)) $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort();
$this->_setErr($this->errno, $this->errstr);
$_retVal = false;
}
}
return $_retVal;
}
/**
* Attempt mail server authentication for a secure connection
*
* @return boolean|null $_retVal Boolean indicating success or failure of authentication
*/
function _server_authenticate()
{
global $conf;
// Send the RFC2554 specified EHLO.
// This improvment as provided by 'SirSir' to
// accomodate both SMTP AND ESMTP capable servers
$host=$this->getHost();
$host=preg_replace('@tcp://@i','',$host); // Remove prefix
$host=preg_replace('@ssl://@i','',$host); // Remove prefix
if (!empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS))
{
$host=preg_replace('@tls://@i','',$host); // Remove prefix
$host='tls://'.$host;
}
if ( $_retVal = $this->socket_send_str('EHLO ' . $host, '250') )
{
if (!empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS))
{
/*
The following dialog illustrates how a client and server can start a TLS STARTTLS session
S: <waits for connection on TCP port 25>
C: <opens connection>
S: 220 mail.imc.org SMTP service ready
C: EHLO mail.ietf.org
S: 250-mail.imc.org offers a warm hug of welcome
S: 250 STARTTLS
C: STARTTLS
S: 220 Go ahead
C: <starts TLS negotiation>
C & S: <negotiate a TLS session>
C & S: <check result of negotiation>
// Second pass EHLO
C: EHLO client-domain.com
S: 250-server-domain.com
S: 250 AUTH LOGIN
C: <continues by sending an SMTP command
*/
if (!$_retVal = $this->socket_send_str('STARTTLS', 220))
{
$this->_setErr(131, 'STARTTLS connection is not supported.');
return $_retVal;
}
if (!stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
{
$this->_setErr(132, 'STARTTLS connection failed.');
return $_retVal;
}
// Most server servers expect a 2nd pass of EHLO after TLS is established to get another time
// the answer with list of supported AUTH methods. They may differs between non STARTTLS and with STARTTLS.
if (!$_retVal = $this->socket_send_str('EHLO '.$host, '250'))
{
$this->_setErr(126, '"' . $host . '" does not support authenticated connections.');
return $_retVal;
}
}
// Send Authentication to Server
// Check for errors along the way
$this->socket_send_str('AUTH LOGIN', '334');
// User name will not return any error, server will take anything we give it.
$this->socket_send_str(base64_encode($this->_smtpsID), '334');
// The error here just means the ID/password combo doesn't work.
// There is not a method to determine which is the problem, ID or password
if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') )
$this->_setErr(130, 'Invalid Authentication Credentials.');
}
else
{
$this->_setErr(126, '"' . $host . '" does not support authenticated connections.');
}
return $_retVal;
}
/**
* Now send the message
*
* @param boolean $_bolTestMsg whether to run this method in 'Test' mode.
* @param boolean $_bolDebug whether to log all communication between this Class and the Mail Server.
* @return boolean|null void
* $_strMsg If this is run in 'Test' mode, the actual message structure will be returned
*/
function sendMsg($_bolTestMsg = false, $_bolDebug = false)
{
/**
* Default return value
*/
$_retVal = false;
// Connect to Server
if ( $this->socket = $this->_server_connect() )
{
// If a User ID *and* a password is given, assume Authentication is desired
if( !empty($this->_smtpsID) && !empty($this->_smtpsPW) )
{
// Send the RFC2554 specified EHLO.
$_retVal = $this->_server_authenticate();
}
// This is a "normal" SMTP Server "handshack"
else
{
// Send the RFC821 specified HELO.
$host=$this->getHost();
$host=preg_replace('@tcp://@i','',$host); // Remove prefix
$host=preg_replace('@ssl://@i','',$host); // Remove prefix
$_retVal = $this->socket_send_str('HELO ' . $host, '250');
}
// Well, did we get to the server?
if ( $_retVal )
{
// From this point onward most server response codes should be 250
// Specify who the mail is from....
// This has to be the raw email address, strip the "name" off
$this->socket_send_str('MAIL FROM: ' . $this->getFrom('addr'), '250');
// 'RCPT TO:' must be given a single address, so this has to loop
// through the list of addresses, regardless of TO, CC or BCC
// and send it out "single file"
foreach ( $this->get_RCPT_list() as $_address )
{
/* Note:
* BCC email addresses must be listed in the RCPT TO command list,
* but the BCC header should not be printed under the DATA command.
* http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server
*/
/*
* TODO
* After each 'RCPT TO:' is sent, we need to make sure it was kosher,
* if not, the whole message will fail
* If any email address fails, we will need to RESET the connection,
* mark the last address as "bad" and start the address loop over again.
* If any address fails, the entire message fails.
*/
$this->socket_send_str('RCPT TO: <' . $_address . '>', '250');
}
// Tell the server we are ready to start sending data
// with any custom headers...
// This is the last response code we look for until the end of the message.
$this->socket_send_str('DATA', '354');
// Now we are ready for the message...
// Ok, all the ingredients are mixed in let's cook this puppy...
$this->socket_send_str($this->getHeader().$this->getBodyContent() . "\r\n" . '.', '250');
// Now tell the server we are done and close the socket...
fputs($this->socket, 'QUIT');
fclose($this->socket);
}
}
return $_retVal;
}
// =============================================================
// ** Setter & Getter methods
// ** Basic System configuration
/**
* setConfig() is used to populate select class properties from either
* a user defined INI file or the systems 'php.ini' file
*
* If a user defined INI is to be used, the files complete path is passed
* as the method single parameter. The INI can define any class and/or
* user properties. Only properties defined within this file will be setter
* and/or orverwritten
*
* If the systems 'php.ini' file is to be used, the method is called without
* parameters. In this case, only HOST, PORT and FROM properties will be set
* as they are the only properties that are defined within the 'php.ini'.
*
* If secure SMTP is to be used, the user ID and Password can be defined with
* the user INI file, but the properties are not defined with the systems
* 'php.ini'file, they must be defined via their setter methods
*
* This method can be called twice, if desired. Once without a parameter to
* load the properties as defined within the systems 'php.ini' file, and a
* second time, with a path to a user INI file for other properties to be
* defined.
*
* @param mixed $_strConfigPath path to config file or VOID
* @return boolean
*/
function setConfig($_strConfigPath = null)
{
/**
* Returns constructed SELECT Object string or boolean upon failure
* Default value is set at TRUE
*/
$_retVal = true;
// if we have a path...
if ( ! empty ($_strConfigPath) )
{
// If the path is not valid, this will NOT generate an error,
// it will simply return FALSE.
if ( ! @include ( $_strConfigPath ) )
{
$this->_setErr(110, '"' . $_strConfigPath . '" is not a valid path.');
$_retVal = false;
}
}
// Read the Systems php.ini file
else
{
// Set these properties ONLY if they are set in the php.ini file.
// Otherwise the default values will be used.
if ( $_host = ini_get('SMTPs') )
$this->setHost($_host);
if ( $_port = ini_get('smtp_port') )
$this->setPort($_port);
if ( $_from = ini_get('sendmail_from') )
$this->setFrom($_from);
}
// Send back what we have
return $_retVal;
}
/**
* Determines the method inwhich the messages are to be sent.
* - 'sockets' [0] - conect via network to SMTP server
* - 'pipe [1] - use UNIX path to EXE
* - 'phpmail [2] - use the PHP built-in mail function
*
* @param int $_type Interger value representing Mail Transport Type
* @return void
*/
function setTransportType($_type = 0)
{
if ( ( is_numeric($_type) ) &&
( ( $_type >= 0 ) && ( $_type <= 3 ) ) )
$this->_transportType = $_type;
}
/**
* Return the method inwhich the message is to be sent.
* - 'sockets' [0] - conect via network to SMTP server
* - 'pipe [1] - use UNIX path to EXE
* - 'phpmail [2] - use the PHP built-in mail function
*
* @return int $_strHost Host Name or IP of the Mail Server to use
*/
function getTransportType()
{
return $this->_transportType;
}
/**
* Path to the sendmail execuable
*
* @param string $_path Path to the sendmail execuable
* @return boolean
*
*/
function setMailPath($_path)
{
// This feature is not yet implemented
return true;
//if ( $_path ) $this->_mailPath = $_path;
}
/**
* Defines the Host Name or IP of the Mail Server to use.
* This is defaulted to 'localhost'
* This is used only with 'socket' based mail transmission
*
* @param string $_strHost Host Name or IP of the Mail Server to use
* @return void
*/
function setHost($_strHost)
{
if ( $_strHost )
$this->_smtpsHost = $_strHost;
}
/**
* Retrieves the Host Name or IP of the Mail Server to use
* This is used only with 'socket' based mail transmission
*
* @return string $_strHost Host Name or IP of the Mail Server to use
*/
function getHost()
{
return $this->_smtpsHost;
}
/**
* Defines the Port Number of the Mail Server to use
* This is defaulted to '25'
* This is used only with 'socket' based mail transmission
*
* @param int $_intPort Port Number of the Mail Server to use
* @return void
*/
function setPort($_intPort)
{
if ( ( is_numeric($_intPort) ) &&
( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) )
$this->_smtpsPort = $_intPort;
}
/**
* Retrieves the Port Number of the Mail Server to use
* This is used only with 'socket' based mail transmission
*
* @return string Port Number of the Mail Server to use
*/
function getPort()
{
return $this->_smtpsPort;
}
/**
* User Name for authentication on Mail Server
*
* @param string $_strID User Name for authentication on Mail Server
* @return void
*/
function setID($_strID)
{
$this->_smtpsID = $_strID;
}
/**
* Retrieves the User Name for authentication on Mail Server
*
* @return string User Name for authentication on Mail Server
*/
function getID()
{
return $this->_smtpsID;
}
/**
* User Password for authentication on Mail Server
*
* @param string $_strPW User Password for authentication on Mail Server
* @return void
*/
function setPW($_strPW)
{
$this->_smtpsPW = $_strPW;
}
/**
* Retrieves the User Password for authentication on Mail Server
*
* @return string User Password for authentication on Mail Server
*/
function getPW()
{
return $this->_smtpsPW;
}
/**
* Character set used for current message
* Character set is defaulted to 'iso-8859-1';
*
* @param string $_strCharSet Character set used for current message
* @return void
*/
function setCharSet($_strCharSet)
{
if ( $_strCharSet )
$this->_smtpsCharSet = $_strCharSet;
}
/**
* Retrieves the Character set used for current message
*
* @return string $_smtpsCharSet Character set used for current message
*/
function getCharSet()
{
return $this->_smtpsCharSet;
}
/**
* Content-Transfer-Encoding, Defaulted to '7bit'
* This can be changed for 2byte characers sets
* Known Encode Types
* - 7bit Simple 7-bit ASCII
* - 8bit 8-bit coding with line termination characters
* - base64 3 octets encoded into 4 sextets with offset
* - binary Arbitrary binary stream
* - mac-binhex40 Macintosh binary to hex encoding
* - quoted-printable Mostly 7-bit, with 8-bit characters encoded as "=HH"
* - uuencode UUENCODE encoding
*
* @param string $_strTransEncode Content-Transfer-Encoding
* @return void
*/
function setTransEncode($_strTransEncode)
{
if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes))
$this->_smtpsTransEncode = $_strTransEncode;
}
/**
* Retrieves the Content-Transfer-Encoding
*
* @return string $_smtpsTransEncode Content-Transfer-Encoding
*/
function getTransEncode()
{
return $this->_smtpsTransEncode;
}
/**
* Content-Transfer-Encoding, Defaulted to '0' [ZERO]
* This can be changed for 2byte characers sets
* Known Encode Types
* - [0] 7bit Simple 7-bit ASCII
* - [1] 8bit 8-bit coding with line termination characters
* - [2] base64 3 octets encoded into 4 sextets with offset
* - [3] binary Arbitrary binary stream
* - [4] mac-binhex40 Macintosh binary to hex encoding
* - [5] quoted-printable Mostly 7-bit, with 8-bit characters encoded as "=HH"
* - [6] uuencode UUENCODE encoding
*
* @param string $_strTransEncodeType Content-Transfer-Encoding
* @return void
*
*/
function setTransEncodeType($_strTransEncodeType)
{
if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes))
$this->_smtpsTransEncodeType = $_strTransEncodeType;
}
/**
* Retrieves the Content-Transfer-Encoding
*
* @return string Content-Transfer-Encoding
*/
function getTransEncodeType()
{
return $this->_smtpsTransEncodeTypes[$this->_smtpsTransEncodeType];
}
// ** Message Construction
/**
* FROM Address from which mail will be sent
*
* @param string $_strFrom Address from which mail will be sent
* @return void
*/
function setFrom($_strFrom)
{
if ( $_strFrom )
$this->_msgFrom = $this->_strip_email($_strFrom);
}
/**
* Retrieves the Address from which mail will be sent
*
* @param boolean $_part To "strip" 'Real name' from address
* @return string Address from which mail will be sent
*/
function getFrom($_part = true)
{
$_retValue = '';
if ( $_part === true )
$_retValue = $this->_msgFrom;
else
$_retValue = $this->_msgFrom[$_part];
return $_retValue;
}
/**
* Reply-To Address from which mail will be the reply-to
*
* @param string $_strReplyTo Address from which mail will be the reply-to
* @return void
*/
function setReplyTo($_strReplyTo)
{
if ( $_strReplyTo )
$this->_msgReplyTo = $this->_strip_email($_strReplyTo);
}
/**
* Retrieves the Address from which mail will be the reply-to
*
* @param boolean $_part To "strip" 'Real name' from address
* @return string Address from which mail will be the reply-to
*/
function getReplyTo($_part = true)
{
$_retValue = '';
if ( $_part === true )
$_retValue = $this->_msgReplyTo;
else
$_retValue = $this->_msgReplyTo[$_part];
return $_retValue;
}
/**
* Inserts given addresses into structured format.
* This method takes a list of given addresses, via an array
* or a COMMA delimted string, and inserts them into a highly
* structured array. This array is designed to remove duplicate
* addresses and to sort them by Domain.
*
* @param string $_type TO, CC, or BCC lists to add addrresses into
* @param mixed $_addrList Array or COMMA delimited string of addresses
* @return void
*
*/
function _buildAddrList($_type, $_addrList)
{
// Pull existing list
$aryHost = $this->_msgRecipients;
// Only run this if we have something
if ( !empty ($_addrList ))
{
// $_addrList can be a STRING or an array
if ( is_string($_addrList) )
{
// This could be a COMMA delimited string
if ( strstr($_addrList, ',') )
// "explode "list" into an array
$_addrList = explode(',', $_addrList);
// Stick it in an array
else
$_addrList = array($_addrList);
}
// take the array of addresses and split them further
foreach ( $_addrList as $_strAddr )
{
// Strip off the end '>'
$_strAddr = str_replace('>', '', $_strAddr);
// Seperate "Real Name" from eMail address
$_tmpaddr = null;
$_tmpaddr = explode('<', $_strAddr);
// We have a "Real Name" and eMail address
if ( count($_tmpaddr) == 2 )
{
$_tmpHost = explode('@', $_tmpaddr[1]);
$_tmpaddr[0] = trim($_tmpaddr[0], ' ">');
$aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = $_tmpaddr[0];
}
// We only have an eMail address
else
{
// Strip off the beggining '<'
$_strAddr = str_replace('<', '', $_strAddr);
$_tmpHost = explode('@', $_strAddr);
$_tmpHost[0] = trim($_tmpHost[0]);
$_tmpHost[1] = trim($_tmpHost[1]);
$aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = '';
}
}
}
// replace list
$this->_msgRecipients = $aryHost;
}
/**
* Returns an array of the various parts of an email address
* This assumes a well formed address:
* - "Real name" <username@domain.tld>
* - "Real Name" is optional
* - if "Real Name" does not exist, the angle brackets are optional
* This will split an email address into 4 or 5 parts.
* - $_aryEmail[org] = orignal string