· 6 years ago · Oct 31, 2019, 12:22 AM
1<?php
2
3/////error_reporting(0);
4@set_time_limit(ini_get('0'));
5//INIT VARS
6$message_base="";$action="";$message="";$emaillist="";$from="";$reconnect="0";$epriority="";$my_smtp="";$ssl_port="25";$encodety="";$replyto="";$subject="";$realname="";$subject_base="";$realname_base="";$contenttype="";$isbcc="";$nbcc="100";$default_system="";$from_base="";$debg="0";$pause=0;$pemails=0;$nm=0;$nopose=true;$nrotat=0;$curentsmtp=0;$canrotat=false;$allsmtps="";$lase="";$reading=false;$repaslog=false;$uploadfile="";
7
8if(!empty($_POST))
9{
10 $debg=lrtrim($_POST['dbg']);
11 if(!empty($_POST['from']))
12 {
13 $from=lrtrim($_POST['from']);
14 $from_base =$from;
15 }
16 $action=lrtrim($_POST['action']);
17 $message=lrtrim($_POST['message']);
18 $message_base=lrtrim($_POST['message']);
19 $emaillist=lrtrim($_POST['emaillist']);
20 $reconnect=lrtrim($_POST['reconnect']);
21 $epriority=lrtrim($_POST['epriority']);
22 $my_smtp=lrtrim($_POST['my_smtp']);
23 $subject=lrtrim($_POST['subject']);
24 $realname=lrtrim($_POST['realname']);
25 $subject_base=lrtrim($_POST['subject']);
26 $realname_base=lrtrim($_POST['realname']);
27 $contenttype=lrtrim($_POST['contenttype']);
28 $encodety=$_POST['encodety'];
29 if(!empty($_POST['pause']))
30 $pause=$_POST['pause'];
31 if(!empty($_POST['replyto']))
32 $replyto=lrtrim($_POST['replyto']);
33 if(!empty($_POST['nrotat']))
34 $nrotat=$_POST['nrotat'];
35 if(!empty($_POST['pemails']))
36 $pemails=$_POST['pemails'];
37 if(!empty($_POST['lase']))
38 $lase=true;
39 if(!empty($_POST['nbcc']))
40 $nbcc=lrtrim($_POST['nbcc']);
41 $allsmtps = preg_split("/\\r\\n|\\r|\\n/", $my_smtp);
42 if(!empty($_POST['readingconf']))
43 $reading=true;
44 if(!empty($_POST['repaslog']))
45 $repaslog=true;
46}
47?>
48<html>
49
50<head>
51<title>PHP Mailer</title>
52<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
53<script
54 src="https://code.jquery.com/jquery-3.1.1.min.js"
55 integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
56 crossorigin="anonymous"></script>
57<style type="text/css">
58<!--
59.style1 {
60 font-family: Geneva, Arial, Helvetica, sans-serif;
61 font-size: 12px;
62}
63-->
64</style>
65<style type="text/css">
66<!--
67.style1 {
68 font-size: 10px;
69 font-family: Geneva, Arial, Helvetica, sans-serif;
70}
71-->
72.td1 {
73 width:150px;
74}
75</style>
76</head>
77<body text="#000000">
78<script>
79$(document).ready(function(){
80 $("#patb").click(function(){
81 if($("#az").prop( "checked" ) || $("#AZ").prop( "checked" ) || $("#09").prop( "checked" ) && $("#len").val() != "")
82 {
83 $("#patval").val("");
84 $("#patval").val($("#patval").val() + "!!");
85 if($("#az").prop( "checked" ))
86 {
87 $("#patval").val($("#patval").val() + "az-");
88 }
89 if($("#AZ").prop( "checked" ))
90 {
91 $("#patval").val($("#patval").val() + "AZ-");
92 }
93 if($("#09").prop( "checked" ))
94 {
95 $("#patval").val($("#patval").val() + "09-");
96 }
97 if($("#len").val() != "")
98 {
99 $("#patval").val($("#patval").val() + "{"+$("#len").val()+ "}");
100 }
101 $("#patval").val($("#patval").val() + "!!");
102
103 }
104 else $("#patval").val("");
105 });
106 $("#add").click(function(){
107 if($('#my_smtp').html()=="")
108 $('#my_smtp').html($('#ip').val()+':'+$('#ssl_port').val()+':'+$('#user').val()+':'+$('#pass').val()+":"+$('input[name=SSLTLS]:checked').val());
109 else
110 $('#my_smtp').html($('#my_smtp').html()+$('#ip').val()+':'+$('#ssl_port').val()+':'+$('#user').val()+':'+$('#pass').val()+":"+$('input[name=SSLTLS]:checked').val());
111 if($('input[name=isbcc]').prop('checked')) $('#my_smtp').html($('#my_smtp').html()+':BCC');
112 else $('#my_smtp').html($('#my_smtp').html()+':NOBCC');
113 $('#my_smtp').html($('#my_smtp').html()+'\n');
114 $('#user').val("");
115 $('#pass').val("");
116 $('input[name=SSLTLS]').prop('checked', false);
117 });
118 $("#reset").click(function(){
119 $('#my_smtp').html('');
120 });
121 $("input[name=lase]").click(function(){
122 if($('input[name=lase]').prop('checked'))
123 {
124 $('input[name=from]').attr('disabled','disabled');
125 $('input[name=from]').val('');
126 }
127 else
128 $('input[name=from]').removeAttr('disabled');
129 });
130 $("input[name=repaslog]").click(function(){
131 if($('input[name=repaslog]').prop('checked'))
132 {
133 $('input[name=replyto]').attr('disabled','disabled');
134 $('input[name=replyto]').val('');
135 }
136 else
137 $('input[name=replyto]').removeAttr('disabled');
138 });
139});
140</script>
141<p align="center"><font size="5" face="Bauhaus 93">MAILER INBOX SENDING</font><font color="#FFFFFF" size="5" face="Bauhaus 93">RFX</font></p>
142<form name="form1" method="post" action="" enctype="multipart/form-data">
143
144 <br>
145
146 <table width="100%" border="0" height="407">
147
148 <tr>
149
150 <td width="100%" colspan="4" bgcolor="#666666" height="36">
151
152 <b>
153
154 <font face="Arial" size="2" color="#FFFFFF"> SERVER SETUP</font> <font face="Arial" size="2" color="red">DEBUG LVL</font>
155 <select name="dbg">
156 <option value="0" <?php echo ($debg == "0") ? 'selected=selected':''; ?>>OFF</option>
157 <option value="1" <?php echo ($debg == "1") ? 'selected=selected':''; ?>>1</option>
158 <option value="2" <?php echo ($debg == "2") ? 'selected=selected':''; ?>>2</option>
159 <option value="3" <?php echo ($debg == "3") ? 'selected=selected':''; ?>>3</option>
160 <option value="4" <?php echo ($debg == "4") ? 'selected=selected':''; ?>>4</option>
161 </select></b></td>
162
163 </tr>
164
165 <tr>
166
167 <td height="22" bgcolor="#E8E8E8" class="td1">
168
169 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
170 SMTP IP:</font></div>
171
172 </td>
173
174 <td height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
175
176 <input type="text" id="ip" name="ip" value="" size="30">
177
178 </font></td>
179
180 <td height="22" bgcolor="#E8E8E8" rowspan="2">
181
182 <div align="right">
183 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SMTP CONFIG:</font></div>
184 </td>
185
186 <td height="22" bgcolor="#E8E8E8" rowspan="2">
187
188 <textarea type="text" id="my_smtp" name="my_smtp" cols="45" rows="3" style="float:left;"><?php echo $my_smtp;?></textarea><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"><SPAN style="display:block;float:left;"> Every </span><input name="nrotat" type="text" style="width:50px;float:left;" value="<?php echo $nrotat;?>"> EMAIL'S
189
190 </font><br><br><br><input type="button" name="reset" id="reset" value="reset"></td>
191
192 </tr>
193 <tr>
194
195 <td class="td1" height="22" bgcolor="#E8E8E8">
196
197 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
198 SMTP LOGIN:</font></div>
199
200 </td>
201
202 <td height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
203
204 <input type="text" id="user" name="user" value="" size="30"><br>
205 <input type="password" id="pass" name="pass" value="" size="30"><BR>
206
207
208 </font></td>
209 <td height="22" bgcolor="#E8E8E8">
210
211 </td>
212
213 </tr>
214 <tr>
215
216 <td class="td1" height="22" bgcolor="#E8E8E8">
217
218 <div align="right">
219 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Port :</font></div>
220
221 </td>
222
223 <td height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
224
225 <input type="text" name="ssl_port" id="ssl_port" value="<?php echo $ssl_port;?>" size="5"> <input type="button" name="add" id="add" value="add smtp"></font></td>
226
227 <td height="22" bgcolor="#E8E8E8">
228
229 <div align="right">
230 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SEND PAUSE:</font></div>
231
232 </td>
233 <td width="41%" height="22" bgcolor="#E8E8E8" ><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
234
235 <input type="text" name="pause" value="<?php echo $pause;?>" style="width:50px;"/> sec evrey <input type="text" name="pemails" value="<?php echo $pemails;?>" style="width:50px;"/> email's <span style="color:red;">(1 bcc = 1 email)<span>
236
237 </font></td>
238
239 </tr>
240 <tr>
241
242 <td class="td1" height="22" bgcolor="#E8E8E8">
243
244 <p align="right">
245 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SSL Server:</font></td>
246
247 <td height="22" bgcolor="#E8E8E8">
248 <input type="radio" name="SSLTLS" value="SSL"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(SSL)</font>
249 <input type="radio" name="SSLTLS" value="TLS"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(TLS)</font>
250 <input type="radio" name="SSLTLS" value="NON"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(NON)</font>
251 </td>
252
253 <td height="22" bgcolor="#E8E8E8">
254
255 <p align="right">
256 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">RECONNECT
257 AFTER:</font></td>
258
259 <td height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
260
261 <input type="text" name="reconnect" value="<?php echo $reconnect;?>" size="5">
262 EMAILS</font></td>
263
264 </tr>
265 <tr>
266
267 <td class="td1" height="22" bgcolor="#E8E8E8">
268
269 <p align="right">
270 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">IS BCC:</font>
271 </td>
272
273 <td height="22" bgcolor="#E8E8E8">
274 <input type="checkbox" name="isbcc" value="true" <?php if($isbcc=="true") echo "checked"; ?> ><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(yes)</font></td>
275
276 <td height="22" bgcolor="#E8E8E8">
277
278 <p align="right">
279 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">NUM OF EMAIL IN BCC :</font></td>
280
281 <td height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
282
283 <input type="text" name="nbcc" value="<?php echo $nbcc;?>" size="5">
284 EMAIL'S</font></td>
285
286 </tr>
287 <tr>
288
289 <td width="100%" height="39" bgcolor="#E8E8E8" colspan="4">
290
291 <p align="center">
292 <font face="Arial" style="font-size: 9pt" color="#800000"><b>"</b> IF
293 YOU DON'T HAVE SMTP LOGIN INFORMATION'S, LEAVE BLANK TO SEND WITH LOCALHOST <b>"</b></font></td>
294
295 </tr>
296
297 <tr>
298
299 <td class="td1" height="19">
300
301 </td>
302
303 <td height="19"> </td>
304
305 <td width="31%" height="19">
306
307 </td>
308
309 <td width="41%" height="19"> </td>
310
311 </tr>
312
313 <tr>
314
315 <td width="100%" colspan="4" bgcolor="#666666" height="36">
316
317 <b>
318
319 <font face="Arial" size="2" color="#FFFFFF"> MESSAGE SETUP</font></b></td>
320
321 </tr>
322
323 <tr>
324
325 <td class="td1" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
326
327 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
328 Your Email:</font></div>
329
330 </td>
331
332 <td height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
333
334 <input type="text" name="from" value="<?php if(!$lase) echo $from_base;?>" size="30" <?php if($lase) echo "disabled"?> >
335 <input type="checkbox" name="lase" value="true" <?php if($lase) echo "checked"; ?> >EMAIL as LOGIN
336 </font></td>
337
338 <td width="31%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
339
340 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
341 Your Name:</font></div>
342
343 </td>
344
345 <td width="41%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
346
347 <input type="text" name="realname" value="<?php echo $realname_base;?>" size="30">
348
349 </font></td>
350
351 </tr>
352 <tr>
353
354 <td class="td1" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
355
356 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
357 Reply-To:</font></div>
358
359 </td>
360
361 <td height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
362
363 <input type="text" name="replyto" value="<?php if(!$repaslog) echo $replyto;?>" size="30" <?php if($repaslog) echo "disabled";?>><input type="checkbox" name="repaslog" value="true" <?php if($repaslog) echo "checked"; ?> >REPLY as LOGIN
364 <input type="checkbox" name="readingconf" value="true" <?php if($reading) echo "checked"; ?> >CONFIRM READING
365 </font></td>
366
367 <td width="31%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
368
369 <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
370 Email Priority:</font></td>
371
372 <td width="41%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
373
374 </font><select name="epriority" id="listMethod" onchange="showHideListConfig()">
375 <option value="" <?php if(strlen($epriority)< 1){print "selected";} ?> >
376 NO PRIORITY</option>
377 <option value="1" <?php if($epriority == "1"){print "selected";} ?> >HIGH</option>
378 <option value="3" <?php if($epriority == "3"){print "selected";} ?> >NORMAL</option>
379 <option value="5" <?php if($epriority == "5"){print "selected";} ?> >LOW</option>
380 </select></td>
381
382 </tr>
383
384 <tr>
385
386 <td class="td1" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
387
388 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
389 Subject:</font></div>
390
391 </td>
392
393 <td height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
394
395 <input type="text" name="subject" value="<?php echo $subject_base;?>" size="90">
396
397 </font></td><td width="31%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
398
399 <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
400 <font size="-3" face="Verdana, Arial, Helvetica, sans-serif" color="#FF0000">
401 ENCODE SENDING </font>/ CHARSET :</font></td><td width="41%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
402
403 </font><select size="1" name="encodety">
404 <option value="no" <?php if($encodety == "no"){print "selected";} ?>>NO</option>
405 <option value="8bit" <?php if($encodety == "8bit"){print "selected";} ?>>8bit</option>
406 <option value="7bit" <?php if($encodety == "7bit"){print "selected";} ?>>7bit</option>
407 <option value="binary" <?php if($encodety == "binary"){print "selected";} ?>>binary</option>
408 <option value="base64" <?php if($encodety == "base64"){print "selected";} ?>>base64</option>
409 <option value="quoted-printable" <?php if($encodety == "quoted-printable"){print "selected";} ?>>quoted-printable</option>
410 </select><select name="epriority" id="listMethod" onchange="showHideListConfig()">
411 <option value="" selected="">NO CHARSET</option>
412 <option value="us-ascii">Unicode -> us-ascii</option>
413 <option value="utf-7">Unicode -> utf-7</option>
414 <option value="utf-8">Unicode -> utf-8</option>
415 <option value="iso-10646-ucs-2">Unicode -> iso-10646-ucs-2</option>
416 <option value="iso-8859-6">Arabic -> iso-8859-6</option>
417 <option value="x-mac-arabic">Arabic -> x-mac-arabic</option>
418 <option value="windows-1256">Arabic -> windows-1256</option>
419 <option value="iso-8859-4">Baltic -> iso-8859-4</option>
420 <option value="windows-1257">Baltic -> windows-1257</option>
421 <option value="iso-8859-2">Central European -> iso-8859-2</option>
422 <option value="x-mac-ce">Central European -> x-mac-ce</option>
423 <option value="windows-1250">Central European -> windows-1250</option>
424 <option value="euc-cn">Chinese -> euc-cn</option>
425 <option value="gb2312">Chinese -> gb2312</option>
426 <option value="hz-gb-2312">Chinese -> hz-gb-2312 </option>
427 <option value="x-mac-chinesesimp">Chinese -> x-mac-chinesesimp</option>
428 <option value="cp-936">Chinese -> cp-936</option>
429 <option value="big5">Chinese -> big5</option>
430 <option value="x-mac-chinesetrad">Chinese -> x-mac-chinesetrad</option>
431 <option value="cp-950">Chinese -> cp-950</option>
432 <option value="cp-932">Chinese -> cp-932</option>
433 <option value="euc-tw">Chinese -> euc-tw</option>
434 </select></td>
435
436 </tr>
437
438 <tr>
439
440 <td class="td1" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
441
442 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
443 Generateur:</font></div></td>
444
445 <td width="35%" colspan="" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
446 (a-z)<input type="checkbox" name="az" id="az">
447 (A-Z)<input type="checkbox" name="AZ" id="AZ">
448 (0-9)<input type="checkbox" name="09" id="09">
449 (LENHGT)<input type="text" maxlength=2 size=1 name="len" id="len">
450 (#PATTERN)<input type="text" name="patval" id="patval">
451 <input type="button" value="GET PATTERN" id="patb" name="patb">
452 </td>
453 <td width="31%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
454
455 <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
456 <font size="-3" face="Verdana, Arial, Helvetica, sans-serif" >
457 ATTACH :</font>
458 </td>
459 <td width="41%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"></font><input name="userfile" type="file"></td>
460 </tr>
461
462 <tr valign="top">
463
464<td colspan="3" height="190" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
465
466 <textarea name="message" value=""cols="60" rows="10"><?php echo $message_base;?></textarea>
467
468 <br>
469
470 <input type="radio" name="contenttype" value="plain" >
471
472 TEXT
473
474 <input type="radio" name="contenttype" value="html" checked>
475
476 HTML
477
478 <input type="hidden" name="action" value="send">
479
480 <input type="submit" value="Send Message">
481
482 </font></td>
483
484 <td width="41%" height="190" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
485
486 <textarea name="emaillist" value="" cols="30" rows="10"><?php echo $emaillist;?></textarea>
487
488 </font></td>
489
490 </tr>
491
492 </table>
493
494</form>
495
496<?php print "<p class=\"style1\">PHP Mailer © 2017, <b><font color=\"#800000\">BY RFX</font><span style=\"color:red\"> SKYPE: KIMONO238<br></span></b></p>"; ?>
497 </body>
498</html>
499
500
501<?php
502
503
504
505class SMTP
506{
507 /**
508 * The PHPMailer SMTP version number.
509 * @var string
510 */
511 const VERSION = '5.2.17';
512 /**
513 * SMTP line break constant.
514 * @var string
515 */
516 const CRLF = "\r\n";
517 /**
518 * The SMTP port to use if one is not specified.
519 * @var integer
520 */
521 const DEFAULT_SMTP_PORT = 25;
522 /**
523 * The maximum line length allowed by RFC 2822 section 2.1.1
524 * @var integer
525 */
526 const MAX_LINE_LENGTH = 998;
527 /**
528 * Debug level for no output
529 */
530 const DEBUG_OFF = 0;
531 /**
532 * Debug level to show client -> server messages
533 */
534 const DEBUG_CLIENT = 1;
535 /**
536 * Debug level to show client -> server and server -> client messages
537 */
538 const DEBUG_SERVER = 2;
539 /**
540 * Debug level to show connection status, client -> server and server -> client messages
541 */
542 const DEBUG_CONNECTION = 3;
543 /**
544 * Debug level to show all messages
545 */
546 const DEBUG_LOWLEVEL = 4;
547 /**
548 * The PHPMailer SMTP Version number.
549 * @var string
550 * @deprecated Use the `VERSION` constant instead
551 * @see SMTP::VERSION
552 */
553 public $Version = '5.2.17';
554 /**
555 * SMTP server port number.
556 * @var integer
557 * @deprecated This is only ever used as a default value, so use the `DEFAULT_SMTP_PORT` constant instead
558 * @see SMTP::DEFAULT_SMTP_PORT
559 */
560 public $SMTP_PORT = 25;
561 /**
562 * SMTP reply line ending.
563 * @var string
564 * @deprecated Use the `CRLF` constant instead
565 * @see SMTP::CRLF
566 */
567 public $CRLF = "\r\n";
568 /**
569 * Debug output level.
570 * Options:
571 * * self::DEBUG_OFF (`0`) No debug output, default
572 * * self::DEBUG_CLIENT (`1`) Client commands
573 * * self::DEBUG_SERVER (`2`) Client commands and server responses
574 * * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status
575 * * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages
576 * @var integer
577 */
578 public $do_debug = self::DEBUG_OFF;
579 /**
580 * How to handle debug output.
581 * Options:
582 * * `echo` Output plain-text as-is, appropriate for CLI
583 * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
584 * * `error_log` Output to error log as configured in php.ini
585 *
586 * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
587 * <code>
588 * $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
589 * </code>
590 * @var string|callable
591 */
592 public $Debugoutput = 'echo';
593 /**
594 * Whether to use VERP.
595 * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
596 * @link http://www.postfix.org/VERP_README.html Info on VERP
597 * @var boolean
598 */
599 public $do_verp = false;
600 /**
601 * The timeout value for connection, in seconds.
602 * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
603 * This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure.
604 * @link http://tools.ietf.org/html/rfc2821#section-4.5.3.2
605 * @var integer
606 */
607 public $Timeout = 300;
608 /**
609 * How long to wait for commands to complete, in seconds.
610 * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
611 * @var integer
612 */
613 public $Timelimit = 300;
614 /**
615 * @var array patterns to extract smtp transaction id from smtp reply
616 * Only first capture group will be use, use non-capturing group to deal with it
617 * Extend this class to override this property to fulfil your needs.
618 */
619 protected $smtp_transaction_id_patterns = array(
620 'exim' => '/[0-9]{3} OK id=(.*)/',
621 'sendmail' => '/[0-9]{3} 2.0.0 (.*) Message/',
622 'postfix' => '/[0-9]{3} 2.0.0 Ok: queued as (.*)/'
623 );
624 /**
625 * The socket for the server connection.
626 * @var resource
627 */
628 protected $smtp_conn;
629 /**
630 * Error information, if any, for the last SMTP command.
631 * @var array
632 */
633 protected $error = array(
634 'error' => '',
635 'detail' => '',
636 'smtp_code' => '',
637 'smtp_code_ex' => ''
638 );
639 /**
640 * The reply the server sent to us for HELO.
641 * If null, no HELO string has yet been received.
642 * @var string|null
643 */
644 protected $helo_rply = null;
645 /**
646 * The set of SMTP extensions sent in reply to EHLO command.
647 * Indexes of the array are extension names.
648 * Value at index 'HELO' or 'EHLO' (according to command that was sent)
649 * represents the server name. In case of HELO it is the only element of the array.
650 * Other values can be boolean TRUE or an array containing extension options.
651 * If null, no HELO/EHLO string has yet been received.
652 * @var array|null
653 */
654 protected $server_caps = null;
655 /**
656 * The most recent reply received from the server.
657 * @var string
658 */
659 protected $last_reply = '';
660 /**
661 * Output debugging info via a user-selected method.
662 * @see SMTP::$Debugoutput
663 * @see SMTP::$do_debug
664 * @param string $str Debug string to output
665 * @param integer $level The debug level of this message; see DEBUG_* constants
666 * @return void
667 */
668 protected function edebug($str, $level = 0)
669 {
670 if ($level > $this->do_debug) {
671 return;
672 }
673 //Avoid clash with built-in function names
674 if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
675 call_user_func($this->Debugoutput, $str, $level);
676 return;
677 }
678 switch ($this->Debugoutput) {
679 case 'error_log':
680 //Don't output, just log
681 error_log($str);
682 break;
683 case 'html':
684 //Cleans up output a bit for a better looking, HTML-safe output
685 echo htmlentities(
686 preg_replace('/[\r\n]+/', '', $str),
687 ENT_QUOTES,
688 'UTF-8'
689 )
690 . "<br>\n";
691 break;
692 case 'echo':
693 default:
694 //Normalize line breaks
695 $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
696 echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
697 "\n",
698 "\n \t ",
699 trim($str)
700 )."\n";
701 }
702 }
703 /**
704 * Connect to an SMTP server.
705 * @param string $host SMTP server IP or host name
706 * @param integer $port The port number to connect to
707 * @param integer $timeout How long to wait for the connection to open
708 * @param array $options An array of options for stream_context_create()
709 * @access public
710 * @return boolean
711 */
712 public function connect($host, $port = null, $timeout = 30, $options = array())
713 {
714 if(count($options)==0)
715 {
716 $options["ssl"]=array("verify_peer"=>false,"verify_peer_name"=>false,"allow_self_signed"=>true);
717 }
718 static $streamok;
719 //This is enabled by default since 5.0.0 but some providers disable it
720 //Check this once and cache the result
721 if (is_null($streamok)) {
722 $streamok = function_exists('stream_socket_client');
723 }
724 // Clear errors to avoid confusion
725 $this->setError('');
726 // Make sure we are __not__ connected
727 if ($this->connected()) {
728 // Already connected, generate error
729 $this->setError('Already connected to a server');
730 return false;
731 }
732 if (empty($port)) {
733 $port = self::DEFAULT_SMTP_PORT;
734 }
735 // Connect to the SMTP server
736 $this->edebug(
737 "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true),
738 self::DEBUG_CONNECTION
739 );
740 $errno = 0;
741 $errstr = '';
742 if ($streamok) {
743 $socket_context = stream_context_create($options);
744 set_error_handler(array($this, 'errorHandler'));
745 $this->smtp_conn = stream_socket_client(
746 $host . ":" . $port,
747 $errno,
748 $errstr,
749 $timeout,
750 STREAM_CLIENT_CONNECT,
751 $socket_context
752 );
753 restore_error_handler();
754 } else {
755 //Fall back to fsockopen which should work in more places, but is missing some features
756 $this->edebug(
757 "Connection: stream_socket_client not available, falling back to fsockopen",
758 self::DEBUG_CONNECTION
759 );
760 set_error_handler(array($this, 'errorHandler'));
761 $this->smtp_conn = fsockopen(
762 $host,
763 $port,
764 $errno,
765 $errstr,
766 $timeout
767 );
768 restore_error_handler();
769 }
770 // Verify we connected properly
771 if (!is_resource($this->smtp_conn)) {
772 $this->setError(
773 'Failed to connect to server',
774 $errno,
775 $errstr
776 );
777 $this->edebug(
778 'SMTP ERROR: ' . $this->error['error']
779 . ": $errstr ($errno)",
780 self::DEBUG_CLIENT
781 );
782 return false;
783 }
784 $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
785 // SMTP server can take longer to respond, give longer timeout for first read
786 // Windows does not have support for this timeout function
787 if (substr(PHP_OS, 0, 3) != 'WIN') {
788 $max = ini_get('max_execution_time');
789 // Don't bother if unlimited
790 if ($max != 0 && $timeout > $max) {
791 @set_time_limit($timeout);
792 }
793 stream_set_timeout($this->smtp_conn, $timeout, 0);
794 }
795 // Get any announcement
796 $announce = $this->get_lines();
797 $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
798 return true;
799 }
800 /**
801 * Initiate a TLS (encrypted) session.
802 * @access public
803 * @return boolean
804 */
805 public function startTLS()
806 {
807 if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
808 return false;
809 }
810 //Allow the best TLS version(s) we can
811 $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
812 //PHP 5.6.7 dropped inclusion of TLS 1.1 and 1.2 in STREAM_CRYPTO_METHOD_TLS_CLIENT
813 //so add them back in manually if we can
814 if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
815 $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
816 $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
817 }
818 // Begin encrypted connection
819 if (!stream_socket_enable_crypto(
820 $this->smtp_conn,
821 true,
822 $crypto_method
823 )) {
824 return false;
825 }
826 return true;
827 }
828 /**
829 * Perform SMTP authentication.
830 * Must be run after hello().
831 * @see hello()
832 * @param string $username The user name
833 * @param string $password The password
834 * @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2)
835 * @param string $realm The auth realm for NTLM
836 * @param string $workstation The auth workstation for NTLM
837 * @param null|OAuth $OAuth An optional OAuth instance (@see PHPMailerOAuth)
838 * @return bool True if successfully authenticated.* @access public
839 */
840 public function authenticate(
841 $username,
842 $password,
843 $authtype = null,
844 $realm = '',
845 $workstation = '',
846 $OAuth = null
847 ) {
848 if (!$this->server_caps) {
849 $this->setError('Authentication is not allowed before HELO/EHLO');
850 return false;
851 }
852 if (array_key_exists('EHLO', $this->server_caps)) {
853 // SMTP extensions are available. Let's try to find a proper authentication method
854 if (!array_key_exists('AUTH', $this->server_caps)) {
855 $this->setError('Authentication is not allowed at this stage');
856 // 'at this stage' means that auth may be allowed after the stage changes
857 // e.g. after STARTTLS
858 return false;
859 }
860 self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
861 self::edebug(
862 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']),
863 self::DEBUG_LOWLEVEL
864 );
865 if (empty($authtype)) {
866 foreach (array('CRAM-MD5', 'LOGIN', 'PLAIN', 'NTLM', 'XOAUTH2') as $method) {
867 if (in_array($method, $this->server_caps['AUTH'])) {
868 $authtype = $method;
869 break;
870 }
871 }
872 if (empty($authtype)) {
873 $this->setError('No supported authentication methods found');
874 return false;
875 }
876 self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL);
877 }
878 if (!in_array($authtype, $this->server_caps['AUTH'])) {
879 $this->setError("The requested authentication method \"$authtype\" is not supported by the server");
880 return false;
881 }
882 } elseif (empty($authtype)) {
883 $authtype = 'LOGIN';
884 }
885 switch ($authtype) {
886 case 'PLAIN':
887 // Start authentication
888 if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) {
889 return false;
890 }
891 // Send encoded username and password
892 if (!$this->sendCommand(
893 'User & Password',
894 base64_encode("\0" . $username . "\0" . $password),
895 235
896 )
897 ) {
898 return false;
899 }
900 break;
901 case 'LOGIN':
902 // Start authentication
903 if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
904 return false;
905 }
906 if (!$this->sendCommand("Username", base64_encode($username), 334)) {
907 return false;
908 }
909 if (!$this->sendCommand("Password", base64_encode($password), 235)) {
910 return false;
911 }
912 break;
913 case 'XOAUTH2':
914 //If the OAuth Instance is not set. Can be a case when PHPMailer is used
915 //instead of PHPMailerOAuth
916 if (is_null($OAuth)) {
917 return false;
918 }
919 $oauth = $OAuth->getOauth64();
920 // Start authentication
921 if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) {
922 return false;
923 }
924 break;
925 case 'NTLM':
926 /*
927 * ntlm_sasl_client.php
928 * Bundled with Permission
929 *
930 * How to telnet in windows:
931 * http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx
932 * PROTOCOL Docs http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication
933 */
934 require_once 'extras/ntlm_sasl_client.php';
935 $temp = new stdClass;
936 $ntlm_client = new ntlm_sasl_client_class;
937 //Check that functions are available
938 if (!$ntlm_client->initialize($temp)) {
939 $this->setError($temp->error);
940 $this->edebug(
941 'You need to enable some modules in your php.ini file: '
942 . $this->error['error'],
943 self::DEBUG_CLIENT
944 );
945 return false;
946 }
947 //msg1
948 $msg1 = $ntlm_client->typeMsg1($realm, $workstation); //msg1
949 if (!$this->sendCommand(
950 'AUTH NTLM',
951 'AUTH NTLM ' . base64_encode($msg1),
952 334
953 )
954 ) {
955 return false;
956 }
957 //Though 0 based, there is a white space after the 3 digit number
958 //msg2
959 $challenge = substr($this->last_reply, 3);
960 $challenge = base64_decode($challenge);
961 $ntlm_res = $ntlm_client->NTLMResponse(
962 substr($challenge, 24, 8),
963 $password
964 );
965 //msg3
966 $msg3 = $ntlm_client->typeMsg3(
967 $ntlm_res,
968 $username,
969 $realm,
970 $workstation
971 );
972 // send encoded username
973 return $this->sendCommand('Username', base64_encode($msg3), 235);
974 case 'CRAM-MD5':
975 // Start authentication
976 if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) {
977 return false;
978 }
979 // Get the challenge
980 $challenge = base64_decode(substr($this->last_reply, 4));
981 // Build the response
982 $response = $username . ' ' . $this->hmac($challenge, $password);
983 // send encoded credentials
984 return $this->sendCommand('Username', base64_encode($response), 235);
985 default:
986 $this->setError("Authentication method \"$authtype\" is not supported");
987 return false;
988 }
989 return true;
990 }
991 /**
992 * Calculate an MD5 HMAC hash.
993 * Works like hash_hmac('md5', $data, $key)
994 * in case that function is not available
995 * @param string $data The data to hash
996 * @param string $key The key to hash with
997 * @access protected
998 * @return string
999 */
1000 protected function hmac($data, $key)
1001 {
1002 if (function_exists('hash_hmac')) {
1003 return hash_hmac('md5', $data, $key);
1004 }
1005 // The following borrowed from
1006 // http://php.net/manual/en/function.mhash.php#27225
1007 // RFC 2104 HMAC implementation for php.
1008 // Creates an md5 HMAC.
1009 // Eliminates the need to install mhash to compute a HMAC
1010 // by Lance Rushing
1011 $bytelen = 64; // byte length for md5
1012 if (strlen($key) > $bytelen) {
1013 $key = pack('H*', md5($key));
1014 }
1015 $key = str_pad($key, $bytelen, chr(0x00));
1016 $ipad = str_pad('', $bytelen, chr(0x36));
1017 $opad = str_pad('', $bytelen, chr(0x5c));
1018 $k_ipad = $key ^ $ipad;
1019 $k_opad = $key ^ $opad;
1020 return md5($k_opad . pack('H*', md5($k_ipad . $data)));
1021 }
1022 /**
1023 * Check connection state.
1024 * @access public
1025 * @return boolean True if connected.
1026 */
1027 public function connected()
1028 {
1029 if (is_resource($this->smtp_conn)) {
1030 $sock_status = stream_get_meta_data($this->smtp_conn);
1031 if ($sock_status['eof']) {
1032 // The socket is valid but we are not connected
1033 $this->edebug(
1034 'SMTP NOTICE: EOF caught while checking if connected',
1035 self::DEBUG_CLIENT
1036 );
1037 $this->close();
1038 return false;
1039 }
1040 return true; // everything looks good
1041 }
1042 return false;
1043 }
1044 /**
1045 * Close the socket and clean up the state of the class.
1046 * Don't use this function without first trying to use QUIT.
1047 * @see quit()
1048 * @access public
1049 * @return void
1050 */
1051 public function close()
1052 {
1053 $this->setError('');
1054 $this->server_caps = null;
1055 $this->helo_rply = null;
1056 if (is_resource($this->smtp_conn)) {
1057 // close the connection and cleanup
1058 fclose($this->smtp_conn);
1059 $this->smtp_conn = null; //Makes for cleaner serialization
1060 $this->edebug('Connection: closed', self::DEBUG_CONNECTION);
1061 }
1062 }
1063 /**
1064 * Send an SMTP DATA command.
1065 * Issues a data command and sends the msg_data to the server,
1066 * finializing the mail transaction. $msg_data is the message
1067 * that is to be send with the headers. Each header needs to be
1068 * on a single line followed by a <CRLF> with the message headers
1069 * and the message body being separated by and additional <CRLF>.
1070 * Implements rfc 821: DATA <CRLF>
1071 * @param string $msg_data Message data to send
1072 * @access public
1073 * @return boolean
1074 */
1075 public function data($msg_data)
1076 {
1077 //This will use the standard timelimit
1078 if (!$this->sendCommand('DATA', 'DATA', 354)) {
1079 return false;
1080 }
1081 /* The server is ready to accept data!
1082 * According to rfc821 we should not send more than 1000 characters on a single line (including the CRLF)
1083 * so we will break the data up into lines by \r and/or \n then if needed we will break each of those into
1084 * smaller lines to fit within the limit.
1085 * We will also look for lines that start with a '.' and prepend an additional '.'.
1086 * NOTE: this does not count towards line-length limit.
1087 */
1088 // Normalize line breaks before exploding
1089 $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));
1090 /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field
1091 * of the first line (':' separated) does not contain a space then it _should_ be a header and we will
1092 * process all lines before a blank line as headers.
1093 */
1094 $field = substr($lines[0], 0, strpos($lines[0], ':'));
1095 $in_headers = false;
1096 if (!empty($field) && strpos($field, ' ') === false) {
1097 $in_headers = true;
1098 }
1099 foreach ($lines as $line) {
1100 $lines_out = array();
1101 if ($in_headers and $line == '') {
1102 $in_headers = false;
1103 }
1104 //Break this line up into several smaller lines if it's too long
1105 //Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len),
1106 while (isset($line[self::MAX_LINE_LENGTH])) {
1107 //Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on
1108 //so as to avoid breaking in the middle of a word
1109 $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
1110 //Deliberately matches both false and 0
1111 if (!$pos) {
1112 //No nice break found, add a hard break
1113 $pos = self::MAX_LINE_LENGTH - 1;
1114 $lines_out[] = substr($line, 0, $pos);
1115 $line = substr($line, $pos);
1116 } else {
1117 //Break at the found point
1118 $lines_out[] = substr($line, 0, $pos);
1119 //Move along by the amount we dealt with
1120 $line = substr($line, $pos + 1);
1121 }
1122 //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1
1123 if ($in_headers) {
1124 $line = "\t" . $line;
1125 }
1126 }
1127 $lines_out[] = $line;
1128 //Send the lines to the server
1129 foreach ($lines_out as $line_out) {
1130 //RFC2821 section 4.5.2
1131 if (!empty($line_out) and $line_out[0] == '.') {
1132 $line_out = '.' . $line_out;
1133 }
1134 $this->client_send($line_out . self::CRLF);
1135 }
1136 }
1137 //Message data has been sent, complete the command
1138 //Increase timelimit for end of DATA command
1139 $savetimelimit = $this->Timelimit;
1140 $this->Timelimit = $this->Timelimit * 2;
1141 $result = $this->sendCommand('DATA END', '.', 250);
1142 //Restore timelimit
1143 $this->Timelimit = $savetimelimit;
1144 return $result;
1145 }
1146 /**
1147 * Send an SMTP HELO or EHLO command.
1148 * Used to identify the sending server to the receiving server.
1149 * This makes sure that client and server are in a known state.
1150 * Implements RFC 821: HELO <SP> <domain> <CRLF>
1151 * and RFC 2821 EHLO.
1152 * @param string $host The host name or IP to connect to
1153 * @access public
1154 * @return boolean
1155 */
1156 public function hello($host = '')
1157 {
1158 //Try extended hello first (RFC 2821)
1159 return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
1160 }
1161 /**
1162 * Send an SMTP HELO or EHLO command.
1163 * Low-level implementation used by hello()
1164 * @see hello()
1165 * @param string $hello The HELO string
1166 * @param string $host The hostname to say we are
1167 * @access protected
1168 * @return boolean
1169 */
1170 protected function sendHello($hello, $host)
1171 {
1172 $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250);
1173 $this->helo_rply = $this->last_reply;
1174 if ($noerror) {
1175 $this->parseHelloFields($hello);
1176 } else {
1177 $this->server_caps = null;
1178 }
1179 return $noerror;
1180 }
1181 /**
1182 * Parse a reply to HELO/EHLO command to discover server extensions.
1183 * In case of HELO, the only parameter that can be discovered is a server name.
1184 * @access protected
1185 * @param string $type - 'HELO' or 'EHLO'
1186 */
1187 protected function parseHelloFields($type)
1188 {
1189 $this->server_caps = array();
1190 $lines = explode("\n", $this->helo_rply);
1191 foreach ($lines as $n => $s) {
1192 //First 4 chars contain response code followed by - or space
1193 $s = trim(substr($s, 4));
1194 if (empty($s)) {
1195 continue;
1196 }
1197 $fields = explode(' ', $s);
1198 if (!empty($fields)) {
1199 if (!$n) {
1200 $name = $type;
1201 $fields = $fields[0];
1202 } else {
1203 $name = array_shift($fields);
1204 switch ($name) {
1205 case 'SIZE':
1206 $fields = ($fields ? $fields[0] : 0);
1207 break;
1208 case 'AUTH':
1209 if (!is_array($fields)) {
1210 $fields = array();
1211 }
1212 break;
1213 default:
1214 $fields = true;
1215 }
1216 }
1217 $this->server_caps[$name] = $fields;
1218 }
1219 }
1220 }
1221 /**
1222 * Send an SMTP MAIL command.
1223 * Starts a mail transaction from the email address specified in
1224 * $from. Returns true if successful or false otherwise. If True
1225 * the mail transaction is started and then one or more recipient
1226 * commands may be called followed by a data command.
1227 * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
1228 * @param string $from Source address of this message
1229 * @access public
1230 * @return boolean
1231 */
1232 public function mail($from)
1233 {
1234 $useVerp = ($this->do_verp ? ' XVERP' : '');
1235 return $this->sendCommand(
1236 'MAIL FROM',
1237 'MAIL FROM:<' . $from . '>' . $useVerp,
1238 250
1239 );
1240 }
1241 /**
1242 * Send an SMTP QUIT command.
1243 * Closes the socket if there is no error or the $close_on_error argument is true.
1244 * Implements from rfc 821: QUIT <CRLF>
1245 * @param boolean $close_on_error Should the connection close if an error occurs?
1246 * @access public
1247 * @return boolean
1248 */
1249 public function quit($close_on_error = true)
1250 {
1251 $noerror = $this->sendCommand('QUIT', 'QUIT', 221);
1252 $err = $this->error; //Save any error
1253 if ($noerror or $close_on_error) {
1254 $this->close();
1255 $this->error = $err; //Restore any error from the quit command
1256 }
1257 return $noerror;
1258 }
1259 /**
1260 * Send an SMTP RCPT command.
1261 * Sets the TO argument to $toaddr.
1262 * Returns true if the recipient was accepted false if it was rejected.
1263 * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
1264 * @param string $address The address the message is being sent to
1265 * @access public
1266 * @return boolean
1267 */
1268 public function recipient($address)
1269 {
1270 return $this->sendCommand(
1271 'RCPT TO',
1272 'RCPT TO:<' . $address . '>',
1273 array(250, 251)
1274 );
1275 }
1276 /**
1277 * Send an SMTP RSET command.
1278 * Abort any transaction that is currently in progress.
1279 * Implements rfc 821: RSET <CRLF>
1280 * @access public
1281 * @return boolean True on success.
1282 */
1283 public function reset()
1284 {
1285 return $this->sendCommand('RSET', 'RSET', 250);
1286 }
1287 /**
1288 * Send a command to an SMTP server and check its return code.
1289 * @param string $command The command name - not sent to the server
1290 * @param string $commandstring The actual command to send
1291 * @param integer|array $expect One or more expected integer success codes
1292 * @access protected
1293 * @return boolean True on success.
1294 */
1295 protected function sendCommand($command, $commandstring, $expect)
1296 {
1297 if (!$this->connected()) {
1298 $this->setError("Called $command without being connected");
1299 return false;
1300 }
1301 //Reject line breaks in all commands
1302 if (strpos($commandstring, "\n") !== false or strpos($commandstring, "\r") !== false) {
1303 $this->setError("Command '$command' contained line breaks");
1304 return false;
1305 }
1306 $this->client_send($commandstring . self::CRLF);
1307 $this->last_reply = $this->get_lines();
1308 // Fetch SMTP code and possible error code explanation
1309 $matches = array();
1310 if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) {
1311 $code = $matches[1];
1312 $code_ex = (count($matches) > 2 ? $matches[2] : null);
1313 // Cut off error code from each response line
1314 $detail = preg_replace(
1315 "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m",
1316 '',
1317 $this->last_reply
1318 );
1319 } else {
1320 // Fall back to simple parsing if regex fails
1321 $code = substr($this->last_reply, 0, 3);
1322 $code_ex = null;
1323 $detail = substr($this->last_reply, 4);
1324 }
1325 $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
1326 if (!in_array($code, (array)$expect)) {
1327 $this->setError(
1328 "$command command failed",
1329 $detail,
1330 $code,
1331 $code_ex
1332 );
1333 $this->edebug(
1334 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply,
1335 self::DEBUG_CLIENT
1336 );
1337 return false;
1338 }
1339 $this->setError('');
1340 return true;
1341 }
1342 /**
1343 * Send an SMTP SAML command.
1344 * Starts a mail transaction from the email address specified in $from.
1345 * Returns true if successful or false otherwise. If True
1346 * the mail transaction is started and then one or more recipient
1347 * commands may be called followed by a data command. This command
1348 * will send the message to the users terminal if they are logged
1349 * in and send them an email.
1350 * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
1351 * @param string $from The address the message is from
1352 * @access public
1353 * @return boolean
1354 */
1355 public function sendAndMail($from)
1356 {
1357 return $this->sendCommand('SAML', "SAML FROM:$from", 250);
1358 }
1359 /**
1360 * Send an SMTP VRFY command.
1361 * @param string $name The name to verify
1362 * @access public
1363 * @return boolean
1364 */
1365 public function verify($name)
1366 {
1367 return $this->sendCommand('VRFY', "VRFY $name", array(250, 251));
1368 }
1369 /**
1370 * Send an SMTP NOOP command.
1371 * Used to keep keep-alives alive, doesn't actually do anything
1372 * @access public
1373 * @return boolean
1374 */
1375 public function noop()
1376 {
1377 return $this->sendCommand('NOOP', 'NOOP', 250);
1378 }
1379 /**
1380 * Send an SMTP TURN command.
1381 * This is an optional command for SMTP that this class does not support.
1382 * This method is here to make the RFC821 Definition complete for this class
1383 * and _may_ be implemented in future
1384 * Implements from rfc 821: TURN <CRLF>
1385 * @access public
1386 * @return boolean
1387 */
1388 public function turn()
1389 {
1390 $this->setError('The SMTP TURN command is not implemented');
1391 $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT);
1392 return false;
1393 }
1394 /**
1395 * Send raw data to the server.
1396 * @param string $data The data to send
1397 * @access public
1398 * @return integer|boolean The number of bytes sent to the server or false on error
1399 */
1400 public function client_send($data)
1401 {
1402 $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT);
1403 set_error_handler(array($this, 'errorHandler'));
1404 $result = fwrite($this->smtp_conn, $data);
1405 restore_error_handler();
1406 return $result;
1407 }
1408 /**
1409 * Get the latest error.
1410 * @access public
1411 * @return array
1412 */
1413 public function getError()
1414 {
1415 return $this->error;
1416 }
1417 /**
1418 * Get SMTP extensions available on the server
1419 * @access public
1420 * @return array|null
1421 */
1422 public function getServerExtList()
1423 {
1424 return $this->server_caps;
1425 }
1426 /**
1427 * A multipurpose method
1428 * The method works in three ways, dependent on argument value and current state
1429 * 1. HELO/EHLO was not sent - returns null and set up $this->error
1430 * 2. HELO was sent
1431 * $name = 'HELO': returns server name
1432 * $name = 'EHLO': returns boolean false
1433 * $name = any string: returns null and set up $this->error
1434 * 3. EHLO was sent
1435 * $name = 'HELO'|'EHLO': returns server name
1436 * $name = any string: if extension $name exists, returns boolean True
1437 * or its options. Otherwise returns boolean False
1438 * In other words, one can use this method to detect 3 conditions:
1439 * - null returned: handshake was not or we don't know about ext (refer to $this->error)
1440 * - false returned: the requested feature exactly not exists
1441 * - positive value returned: the requested feature exists
1442 * @param string $name Name of SMTP extension or 'HELO'|'EHLO'
1443 * @return mixed
1444 */
1445 public function getServerExt($name)
1446 {
1447 if (!$this->server_caps) {
1448 $this->setError('No HELO/EHLO was sent');
1449 return null;
1450 }
1451 // the tight logic knot ;)
1452 if (!array_key_exists($name, $this->server_caps)) {
1453 if ($name == 'HELO') {
1454 return $this->server_caps['EHLO'];
1455 }
1456 if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) {
1457 return false;
1458 }
1459 $this->setError('HELO handshake was used. Client knows nothing about server extensions');
1460 return null;
1461 }
1462 return $this->server_caps[$name];
1463 }
1464 /**
1465 * Get the last reply from the server.
1466 * @access public
1467 * @return string
1468 */
1469 public function getLastReply()
1470 {
1471 return $this->last_reply;
1472 }
1473 /**
1474 * Read the SMTP server's response.
1475 * Either before eof or socket timeout occurs on the operation.
1476 * With SMTP we can tell if we have more lines to read if the
1477 * 4th character is '-' symbol. If it is a space then we don't
1478 * need to read anything else.
1479 * @access protected
1480 * @return string
1481 */
1482 protected function get_lines()
1483 {
1484 // If the connection is bad, give up straight away
1485 if (!is_resource($this->smtp_conn)) {
1486 return '';
1487 }
1488 $data = '';
1489 $endtime = 0;
1490 stream_set_timeout($this->smtp_conn, $this->Timeout);
1491 if ($this->Timelimit > 0) {
1492 $endtime = time() + $this->Timelimit;
1493 }
1494 while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
1495 $str = @fgets($this->smtp_conn, 515);
1496 $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
1497 $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL);
1498 $data .= $str;
1499 // If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen
1500 if (!isset($str[3]) or (isset($str[3]) and $str[3] == ' ')) {
1501 break;
1502 }
1503 // Timed-out? Log and break
1504 $info = stream_get_meta_data($this->smtp_conn);
1505 if ($info['timed_out']) {
1506 $this->edebug(
1507 'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)',
1508 self::DEBUG_LOWLEVEL
1509 );
1510 break;
1511 }
1512 // Now check if reads took too long
1513 if ($endtime and time() > $endtime) {
1514 $this->edebug(
1515 'SMTP -> get_lines(): timelimit reached ('.
1516 $this->Timelimit . ' sec)',
1517 self::DEBUG_LOWLEVEL
1518 );
1519 break;
1520 }
1521 }
1522 return $data;
1523 }
1524 /**
1525 * Enable or disable VERP address generation.
1526 * @param boolean $enabled
1527 */
1528 public function setVerp($enabled = false)
1529 {
1530 $this->do_verp = $enabled;
1531 }
1532 /**
1533 * Get VERP address generation mode.
1534 * @return boolean
1535 */
1536 public function getVerp()
1537 {
1538 return $this->do_verp;
1539 }
1540 /**
1541 * Set error messages and codes.
1542 * @param string $message The error message
1543 * @param string $detail Further detail on the error
1544 * @param string $smtp_code An associated SMTP error code
1545 * @param string $smtp_code_ex Extended SMTP code
1546 */
1547 protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '')
1548 {
1549 $this->error = array(
1550 'error' => $message,
1551 'detail' => $detail,
1552 'smtp_code' => $smtp_code,
1553 'smtp_code_ex' => $smtp_code_ex
1554 );
1555 }
1556 /**
1557 * Set debug output method.
1558 * @param string|callable $method The name of the mechanism to use for debugging output, or a callable to handle it.
1559 */
1560 public function setDebugOutput($method = 'echo')
1561 {
1562 $this->Debugoutput = $method;
1563 }
1564 /**
1565 * Get debug output method.
1566 * @return string
1567 */
1568 public function getDebugOutput()
1569 {
1570 return $this->Debugoutput;
1571 }
1572 /**
1573 * Set debug output level.
1574 * @param integer $level
1575 */
1576 public function setDebugLevel($level = 0)
1577 {
1578 $this->do_debug = $level;
1579 }
1580 /**
1581 * Get debug output level.
1582 * @return integer
1583 */
1584 public function getDebugLevel()
1585 {
1586 return $this->do_debug;
1587 }
1588 /**
1589 * Set SMTP timeout.
1590 * @param integer $timeout
1591 */
1592 public function setTimeout($timeout = 0)
1593 {
1594 $this->Timeout = $timeout;
1595 }
1596 /**
1597 * Get SMTP timeout.
1598 * @return integer
1599 */
1600 public function getTimeout()
1601 {
1602 return $this->Timeout;
1603 }
1604 /**
1605 * Reports an error number and string.
1606 * @param integer $errno The error number returned by PHP.
1607 * @param string $errmsg The error message returned by PHP.
1608 */
1609 protected function errorHandler($errno, $errmsg)
1610 {
1611 $notice = 'Connection: Failed to connect to server.';
1612 $this->setError(
1613 $notice,
1614 $errno,
1615 $errmsg
1616 );
1617 $this->edebug(
1618 $notice . ' Error number ' . $errno . '. "Error notice: ' . $errmsg,
1619 self::DEBUG_CONNECTION
1620 );
1621 }
1622 /**
1623 * Will return the ID of the last smtp transaction based on a list of patterns provided
1624 * in SMTP::$smtp_transaction_id_patterns.
1625 * If no reply has been received yet, it will return null.
1626 * If no pattern has been matched, it will return false.
1627 * @return bool|null|string
1628 */
1629 public function getLastTransactionID()
1630 {
1631 $reply = $this->getLastReply();
1632 if (empty($reply)) {
1633 return null;
1634 }
1635 foreach($this->smtp_transaction_id_patterns as $smtp_transaction_id_pattern) {
1636 if(preg_match($smtp_transaction_id_pattern, $reply, $matches)) {
1637 return $matches[1];
1638 }
1639 }
1640 return false;
1641 }
1642}
1643class PHPMailer
1644{
1645 /**
1646 * The PHPMailer Version number.
1647 * @var string
1648 */
1649 public $Version = '5.2.17';
1650 /**
1651 * Email priority.
1652 * Options: null (default), 1 = High, 3 = Normal, 5 = low.
1653 * When null, the header is not set at all.
1654 * @var integer
1655 */
1656 public $Priority = null;
1657 /**
1658 * The character set of the message.
1659 * @var string
1660 */
1661 public $CharSet = 'iso-8859-1';
1662 /**
1663 * The MIME Content-type of the message.
1664 * @var string
1665 */
1666 public $ContentType = 'text/plain';
1667 /**
1668 * The message encoding.
1669 * Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
1670 * @var string
1671 */
1672 public $Encoding = '8bit';
1673 /**
1674 * Holds the most recent mailer error message.
1675 * @var string
1676 */
1677 public $ErrorInfo = '';
1678 /**
1679 * The From email address for the message.
1680 * @var string
1681 */
1682 public $From = 'root@localhost';
1683 /**
1684 * The From name of the message.
1685 * @var string
1686 */
1687 public $FromName = 'Root User';
1688 /**
1689 * The Sender email (Return-Path) of the message.
1690 * If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
1691 * @var string
1692 */
1693 public $Sender = '';
1694 /**
1695 * The Return-Path of the message.
1696 * If empty, it will be set to either From or Sender.
1697 * @var string
1698 * @deprecated Email senders should never set a return-path header;
1699 * it's the receiver's job (RFC5321 section 4.4), so this no longer does anything.
1700 * @link https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321 reference
1701 */
1702 public $ReturnPath = '';
1703 /**
1704 * The Subject of the message.
1705 * @var string
1706 */
1707 public $Subject = '';
1708 /**
1709 * An HTML or plain text message body.
1710 * If HTML then call isHTML(true).
1711 * @var string
1712 */
1713 public $Body = '';
1714 /**
1715 * The plain-text message body.
1716 * This body can be read by mail clients that do not have HTML email
1717 * capability such as mutt & Eudora.
1718 * Clients that can read HTML will view the normal Body.
1719 * @var string
1720 */
1721 public $AltBody = '';
1722 /**
1723 * An iCal message part body.
1724 * Only supported in simple alt or alt_inline message types
1725 * To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator
1726 * @link http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/
1727 * @link http://kigkonsult.se/iCalcreator/
1728 * @var string
1729 */
1730 public $Ical = '';
1731 /**
1732 * The complete compiled MIME message body.
1733 * @access protected
1734 * @var string
1735 */
1736 protected $MIMEBody = '';
1737 /**
1738 * The complete compiled MIME message headers.
1739 * @var string
1740 * @access protected
1741 */
1742 protected $MIMEHeader = '';
1743 /**
1744 * Extra headers that createHeader() doesn't fold in.
1745 * @var string
1746 * @access protected
1747 */
1748 protected $mailHeader = '';
1749 /**
1750 * Word-wrap the message body to this number of chars.
1751 * Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.
1752 * @var integer
1753 */
1754 public $WordWrap = 0;
1755 /**
1756 * Which method to use to send mail.
1757 * Options: "mail", "sendmail", or "smtp".
1758 * @var string
1759 */
1760 public $Mailer = 'mail';
1761 /**
1762 * The path to the sendmail program.
1763 * @var string
1764 */
1765 public $Sendmail = '/usr/sbin/sendmail';
1766 /**
1767 * Whether mail() uses a fully sendmail-compatible MTA.
1768 * One which supports sendmail's "-oi -f" options.
1769 * @var boolean
1770 */
1771 public $UseSendmailOptions = true;
1772 /**
1773 * Path to PHPMailer plugins.
1774 * Useful if the SMTP class is not in the PHP include path.
1775 * @var string
1776 * @deprecated Should not be needed now there is an autoloader.
1777 */
1778 public $PluginDir = '';
1779 /**
1780 * The email address that a reading confirmation should be sent to, also known as read receipt.
1781 * @var string
1782 */
1783 public $ConfirmReadingTo = '';
1784 /**
1785 * The hostname to use in the Message-ID header and as default HELO string.
1786 * If empty, PHPMailer attempts to find one with, in order,
1787 * $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value
1788 * 'localhost.localdomain'.
1789 * @var string
1790 */
1791 public $Hostname = '';
1792 /**
1793 * An ID to be used in the Message-ID header.
1794 * If empty, a unique id will be generated.
1795 * You can set your own, but it must be in the format "<id@domain>",
1796 * as defined in RFC5322 section 3.6.4 or it will be ignored.
1797 * @see https://tools.ietf.org/html/rfc5322#section-3.6.4
1798 * @var string
1799 */
1800 public $MessageID = '';
1801 /**
1802 * The message Date to be used in the Date header.
1803 * If empty, the current date will be added.
1804 * @var string
1805 */
1806 public $MessageDate = '';
1807 /**
1808 * SMTP hosts.
1809 * Either a single hostname or multiple semicolon-delimited hostnames.
1810 * You can also specify a different port
1811 * for each host by using this format: [hostname:port]
1812 * (e.g. "smtp1.example.com:25;smtp2.example.com").
1813 * You can also specify encryption type, for example:
1814 * (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465").
1815 * Hosts will be tried in order.
1816 * @var string
1817 */
1818 public $Host = 'localhost';
1819 /**
1820 * The default SMTP server port.
1821 * @var integer
1822 * @TODO Why is this needed when the SMTP class takes care of it?
1823 */
1824 public $Port = 25;
1825 /**
1826 * The SMTP HELO of the message.
1827 * Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find
1828 * one with the same method described above for $Hostname.
1829 * @var string
1830 * @see PHPMailer::$Hostname
1831 */
1832 public $Helo = '';
1833 /**
1834 * What kind of encryption to use on the SMTP connection.
1835 * Options: '', 'ssl' or 'tls'
1836 * @var string
1837 */
1838 public $SMTPSecure = '';
1839 /**
1840 * Whether to enable TLS encryption automatically if a server supports it,
1841 * even if `SMTPSecure` is not set to 'tls'.
1842 * Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.
1843 * @var boolean
1844 */
1845 public $SMTPAutoTLS = true;
1846 /**
1847 * Whether to use SMTP authentication.
1848 * Uses the Username and Password properties.
1849 * @var boolean
1850 * @see PHPMailer::$Username
1851 * @see PHPMailer::$Password
1852 */
1853 public $SMTPAuth = false;
1854 /**
1855 * Options array passed to stream_context_create when connecting via SMTP.
1856 * @var array
1857 */
1858 public $SMTPOptions = array();
1859 /**
1860 * SMTP username.
1861 * @var string
1862 */
1863 public $Username = '';
1864 /**
1865 * SMTP password.
1866 * @var string
1867 */
1868 public $Password = '';
1869 /**
1870 * SMTP auth type.
1871 * Options are CRAM-MD5, LOGIN, PLAIN, NTLM, XOAUTH2, attempted in that order if not specified
1872 * @var string
1873 */
1874 public $AuthType = '';
1875 /**
1876 * SMTP realm.
1877 * Used for NTLM auth
1878 * @var string
1879 */
1880 public $Realm = '';
1881 /**
1882 * SMTP workstation.
1883 * Used for NTLM auth
1884 * @var string
1885 */
1886 public $Workstation = '';
1887 /**
1888 * The SMTP server timeout in seconds.
1889 * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
1890 * @var integer
1891 */
1892 public $Timeout = 300;
1893 /**
1894 * SMTP class debug output mode.
1895 * Debug output level.
1896 * Options:
1897 * * `0` No output
1898 * * `1` Commands
1899 * * `2` Data and commands
1900 * * `3` As 2 plus connection status
1901 * * `4` Low-level data output
1902 * @var integer
1903 * @see SMTP::$do_debug
1904 */
1905 public $SMTPDebug = 0;
1906 /**
1907 * How to handle debug output.
1908 * Options:
1909 * * `echo` Output plain-text as-is, appropriate for CLI
1910 * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
1911 * * `error_log` Output to error log as configured in php.ini
1912 *
1913 * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
1914 * <code>
1915 * $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
1916 * </code>
1917 * @var string|callable
1918 * @see SMTP::$Debugoutput
1919 */
1920 public $Debugoutput = 'echo';
1921 /**
1922 * Whether to keep SMTP connection open after each message.
1923 * If this is set to true then to close the connection
1924 * requires an explicit call to smtpClose().
1925 * @var boolean
1926 */
1927 public $SMTPKeepAlive = false;
1928 /**
1929 * Whether to split multiple to addresses into multiple messages
1930 * or send them all in one message.
1931 * Only supported in `mail` and `sendmail` transports, not in SMTP.
1932 * @var boolean
1933 */
1934 public $SingleTo = false;
1935 /**
1936 * Storage for addresses when SingleTo is enabled.
1937 * @var array
1938 * @TODO This should really not be public
1939 */
1940 public $SingleToArray = array();
1941 /**
1942 * Whether to generate VERP addresses on send.
1943 * Only applicable when sending via SMTP.
1944 * @link https://en.wikipedia.org/wiki/Variable_envelope_return_path
1945 * @link http://www.postfix.org/VERP_README.html Postfix VERP info
1946 * @var boolean
1947 */
1948 public $do_verp = false;
1949 /**
1950 * Whether to allow sending messages with an empty body.
1951 * @var boolean
1952 */
1953 public $AllowEmpty = false;
1954 /**
1955 * The default line ending.
1956 * @note The default remains "\n". We force CRLF where we know
1957 * it must be used via self::CRLF.
1958 * @var string
1959 */
1960 public $LE = "\n";
1961 /**
1962 * DKIM selector.
1963 * @var string
1964 */
1965 public $DKIM_selector = '';
1966 /**
1967 * DKIM Identity.
1968 * Usually the email address used as the source of the email.
1969 * @var string
1970 */
1971 public $DKIM_identity = '';
1972 /**
1973 * DKIM passphrase.
1974 * Used if your key is encrypted.
1975 * @var string
1976 */
1977 public $DKIM_passphrase = '';
1978 /**
1979 * DKIM signing domain name.
1980 * @example 'example.com'
1981 * @var string
1982 */
1983 public $DKIM_domain = '';
1984 /**
1985 * DKIM private key file path.
1986 * @var string
1987 */
1988 public $DKIM_private = '';
1989 /**
1990 * DKIM private key string.
1991 * If set, takes precedence over `$DKIM_private`.
1992 * @var string
1993 */
1994 public $DKIM_private_string = '';
1995 /**
1996 * Callback Action function name.
1997 *
1998 * The function that handles the result of the send email action.
1999 * It is called out by send() for each email sent.
2000 *
2001 * Value can be any php callable: http://www.php.net/is_callable
2002 *
2003 * Parameters:
2004 * boolean $result result of the send action
2005 * string $to email address of the recipient
2006 * string $cc cc email addresses
2007 * string $bcc bcc email addresses
2008 * string $subject the subject
2009 * string $body the email body
2010 * string $from email address of sender
2011 * @var string
2012 */
2013 public $action_function = '';
2014 /**
2015 * What to put in the X-Mailer header.
2016 * Options: An empty string for PHPMailer default, whitespace for none, or a string to use
2017 * @var string
2018 */
2019 public $XMailer = '';
2020 /**
2021 * Which validator to use by default when validating email addresses.
2022 * May be a callable to inject your own validator, but there are several built-in validators.
2023 * @see PHPMailer::validateAddress()
2024 * @var string|callable
2025 * @static
2026 */
2027 public static $validator = 'auto';
2028 /**
2029 * An instance of the SMTP sender class.
2030 * @var SMTP
2031 * @access protected
2032 */
2033 protected $smtp = null;
2034 /**
2035 * The array of 'to' names and addresses.
2036 * @var array
2037 * @access protected
2038 */
2039 protected $to = array();
2040 /**
2041 * The array of 'cc' names and addresses.
2042 * @var array
2043 * @access protected
2044 */
2045 protected $cc = array();
2046 /**
2047 * The array of 'bcc' names and addresses.
2048 * @var array
2049 * @access protected
2050 */
2051 protected $bcc = array();
2052 /**
2053 * The array of reply-to names and addresses.
2054 * @var array
2055 * @access protected
2056 */
2057 protected $ReplyTo = array();
2058 /**
2059 * An array of all kinds of addresses.
2060 * Includes all of $to, $cc, $bcc
2061 * @var array
2062 * @access protected
2063 * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
2064 */
2065 protected $all_recipients = array();
2066 /**
2067 * An array of names and addresses queued for validation.
2068 * In send(), valid and non duplicate entries are moved to $all_recipients
2069 * and one of $to, $cc, or $bcc.
2070 * This array is used only for addresses with IDN.
2071 * @var array
2072 * @access protected
2073 * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
2074 * @see PHPMailer::$all_recipients
2075 */
2076 protected $RecipientsQueue = array();
2077 /**
2078 * An array of reply-to names and addresses queued for validation.
2079 * In send(), valid and non duplicate entries are moved to $ReplyTo.
2080 * This array is used only for addresses with IDN.
2081 * @var array
2082 * @access protected
2083 * @see PHPMailer::$ReplyTo
2084 */
2085 protected $ReplyToQueue = array();
2086 /**
2087 * The array of attachments.
2088 * @var array
2089 * @access protected
2090 */
2091 protected $attachment = array();
2092 /**
2093 * The array of custom headers.
2094 * @var array
2095 * @access protected
2096 */
2097 protected $CustomHeader = array();
2098 /**
2099 * The most recent Message-ID (including angular brackets).
2100 * @var string
2101 * @access protected
2102 */
2103 protected $lastMessageID = '';
2104 /**
2105 * The message's MIME type.
2106 * @var string
2107 * @access protected
2108 */
2109 protected $message_type = '';
2110 /**
2111 * The array of MIME boundary strings.
2112 * @var array
2113 * @access protected
2114 */
2115 protected $boundary = array();
2116 /**
2117 * The array of available languages.
2118 * @var array
2119 * @access protected
2120 */
2121 protected $language = array();
2122 /**
2123 * The number of errors encountered.
2124 * @var integer
2125 * @access protected
2126 */
2127 protected $error_count = 0;
2128 /**
2129 * The S/MIME certificate file path.
2130 * @var string
2131 * @access protected
2132 */
2133 protected $sign_cert_file = '';
2134 /**
2135 * The S/MIME key file path.
2136 * @var string
2137 * @access protected
2138 */
2139 protected $sign_key_file = '';
2140 /**
2141 * The optional S/MIME extra certificates ("CA Chain") file path.
2142 * @var string
2143 * @access protected
2144 */
2145 protected $sign_extracerts_file = '';
2146 /**
2147 * The S/MIME password for the key.
2148 * Used only if the key is encrypted.
2149 * @var string
2150 * @access protected
2151 */
2152 protected $sign_key_pass = '';
2153 /**
2154 * Whether to throw exceptions for errors.
2155 * @var boolean
2156 * @access protected
2157 */
2158 protected $exceptions = false;
2159 /**
2160 * Unique ID used for message ID and boundaries.
2161 * @var string
2162 * @access protected
2163 */
2164 protected $uniqueid = '';
2165 /**
2166 * Error severity: message only, continue processing.
2167 */
2168 const STOP_MESSAGE = 0;
2169 /**
2170 * Error severity: message, likely ok to continue processing.
2171 */
2172 const STOP_CONTINUE = 1;
2173 /**
2174 * Error severity: message, plus full stop, critical error reached.
2175 */
2176 const STOP_CRITICAL = 2;
2177 /**
2178 * SMTP RFC standard line ending.
2179 */
2180 const CRLF = "\r\n";
2181 /**
2182 * The maximum line length allowed by RFC 2822 section 2.1.1
2183 * @var integer
2184 */
2185 const MAX_LINE_LENGTH = 998;
2186 /**
2187 * Constructor.
2188 * @param boolean $exceptions Should we throw external exceptions?
2189 */
2190 public function __construct($exceptions = null)
2191 {
2192 if ($exceptions !== null) {
2193 $this->exceptions = (boolean)$exceptions;
2194 }
2195 }
2196 /**
2197 * Destructor.
2198 */
2199 public function __destruct()
2200 {
2201 //Close any open SMTP connection nicely
2202 $this->smtpClose();
2203 }
2204 /**
2205 * Call mail() in a safe_mode-aware fashion.
2206 * Also, unless sendmail_path points to sendmail (or something that
2207 * claims to be sendmail), don't pass params (not a perfect fix,
2208 * but it will do)
2209 * @param string $to To
2210 * @param string $subject Subject
2211 * @param string $body Message Body
2212 * @param string $header Additional Header(s)
2213 * @param string $params Params
2214 * @access private
2215 * @return boolean
2216 */
2217 private function mailPassthru($to, $subject, $body, $header, $params)
2218 {
2219 //Check overloading of mail function to avoid double-encoding
2220 if (ini_get('mbstring.func_overload') & 1) {
2221 $subject = $this->secureHeader($subject);
2222 } else {
2223 $subject = $this->encodeHeader($this->secureHeader($subject));
2224 }
2225 //Can't use additional_parameters in safe_mode
2226 //@link http://php.net/manual/en/function.mail.php
2227 if (ini_get('safe_mode') or !$this->UseSendmailOptions or is_null($params)) {
2228 $result = @mail($to, $subject, $body, $header);
2229 } else {
2230 $result = @mail($to, $subject, $body, $header, $params);
2231 }
2232 return $result;
2233 }
2234 /**
2235 * Output debugging info via user-defined method.
2236 * Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).
2237 * @see PHPMailer::$Debugoutput
2238 * @see PHPMailer::$SMTPDebug
2239 * @param string $str
2240 */
2241 protected function edebug($str)
2242 {
2243 if ($this->SMTPDebug <= 0) {
2244 return;
2245 }
2246 //Avoid clash with built-in function names
2247 if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
2248 call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
2249 return;
2250 }
2251 switch ($this->Debugoutput) {
2252 case 'error_log':
2253 //Don't output, just log
2254 error_log($str);
2255 break;
2256 case 'html':
2257 //Cleans up output a bit for a better looking, HTML-safe output
2258 echo htmlentities(
2259 preg_replace('/[\r\n]+/', '', $str),
2260 ENT_QUOTES,
2261 'UTF-8'
2262 )
2263 . "<br>\n";
2264 break;
2265 case 'echo':
2266 default:
2267 //Normalize line breaks
2268 $str = preg_replace('/\r\n?/ms', "\n", $str);
2269 echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
2270 "\n",
2271 "\n \t ",
2272 trim($str)
2273 ) . "\n";
2274 }
2275 }
2276 /**
2277 * Sets message type to HTML or plain.
2278 * @param boolean $isHtml True for HTML mode.
2279 * @return void
2280 */
2281 public function isHTML($isHtml = true)
2282 {
2283 if ($isHtml) {
2284 $this->ContentType = 'text/html';
2285 } else {
2286 $this->ContentType = 'text/plain';
2287 }
2288 }
2289 /**
2290 * Send messages using SMTP.
2291 * @return void
2292 */
2293 public function isSMTP()
2294 {
2295 $this->Mailer = 'smtp';
2296 }
2297 /**
2298 * Send messages using PHP's mail() function.
2299 * @return void
2300 */
2301 public function isMail()
2302 {
2303 $this->Mailer = 'mail';
2304 }
2305 /**
2306 * Send messages using $Sendmail.
2307 * @return void
2308 */
2309 public function isSendmail()
2310 {
2311 $ini_sendmail_path = ini_get('sendmail_path');
2312 if (!stristr($ini_sendmail_path, 'sendmail')) {
2313 $this->Sendmail = '/usr/sbin/sendmail';
2314 } else {
2315 $this->Sendmail = $ini_sendmail_path;
2316 }
2317 $this->Mailer = 'sendmail';
2318 }
2319 /**
2320 * Send messages using qmail.
2321 * @return void
2322 */
2323 public function isQmail()
2324 {
2325 $ini_sendmail_path = ini_get('sendmail_path');
2326 if (!stristr($ini_sendmail_path, 'qmail')) {
2327 $this->Sendmail = '/var/qmail/bin/qmail-inject';
2328 } else {
2329 $this->Sendmail = $ini_sendmail_path;
2330 }
2331 $this->Mailer = 'qmail';
2332 }
2333 /**
2334 * Add a "To" address.
2335 * @param string $address The email address to send to
2336 * @param string $name
2337 * @return boolean true on success, false if address already used or invalid in some way
2338 */
2339 public function addAddress($address, $name = '')
2340 {
2341 return $this->addOrEnqueueAnAddress('to', $address, $name);
2342 }
2343 /**
2344 * Add a "CC" address.
2345 * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
2346 * @param string $address The email address to send to
2347 * @param string $name
2348 * @return boolean true on success, false if address already used or invalid in some way
2349 */
2350 public function addCC($address, $name = '')
2351 {
2352 return $this->addOrEnqueueAnAddress('cc', $address, $name);
2353 }
2354 /**
2355 * Add a "BCC" address.
2356 * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
2357 * @param string $address The email address to send to
2358 * @param string $name
2359 * @return boolean true on success, false if address already used or invalid in some way
2360 */
2361 public function addBCC($address, $name = '')
2362 {
2363 return $this->addOrEnqueueAnAddress('bcc', $address, $name);
2364 }
2365 /**
2366 * Add a "Reply-To" address.
2367 * @param string $address The email address to reply to
2368 * @param string $name
2369 * @return boolean true on success, false if address already used or invalid in some way
2370 */
2371 public function addReplyTo($address, $name = '')
2372 {
2373 return $this->addOrEnqueueAnAddress('Reply-To', $address, $name);
2374 }
2375 /**
2376 * Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer
2377 * can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still
2378 * be modified after calling this function), addition of such addresses is delayed until send().
2379 * Addresses that have been added already return false, but do not throw exceptions.
2380 * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
2381 * @param string $address The email address to send, resp. to reply to
2382 * @param string $name
2383 * @throws phpmailerException
2384 * @return boolean true on success, false if address already used or invalid in some way
2385 * @access protected
2386 */
2387 protected function addOrEnqueueAnAddress($kind, $address, $name)
2388 {
2389 $address = trim($address);
2390 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
2391 if (($pos = strrpos($address, '@')) === false) {
2392 // At-sign is misssing.
2393 $error_message = $this->lang('invalid_address') . " (addAnAddress $kind): $address";
2394 $this->setError($error_message);
2395 $this->edebug($error_message);
2396 if ($this->exceptions) {
2397 throw new phpmailerException($error_message);
2398 }
2399 return false;
2400 }
2401 $params = array($kind, $address, $name);
2402 // Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
2403 if ($this->has8bitChars(substr($address, ++$pos)) and $this->idnSupported()) {
2404 if ($kind != 'Reply-To') {
2405 if (!array_key_exists($address, $this->RecipientsQueue)) {
2406 $this->RecipientsQueue[$address] = $params;
2407 return true;
2408 }
2409 } else {
2410 if (!array_key_exists($address, $this->ReplyToQueue)) {
2411 $this->ReplyToQueue[$address] = $params;
2412 return true;
2413 }
2414 }
2415 return false;
2416 }
2417 // Immediately add standard addresses without IDN.
2418 return call_user_func_array(array($this, 'addAnAddress'), $params);
2419 }
2420 /**
2421 * Add an address to one of the recipient arrays or to the ReplyTo array.
2422 * Addresses that have been added already return false, but do not throw exceptions.
2423 * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
2424 * @param string $address The email address to send, resp. to reply to
2425 * @param string $name
2426 * @throws phpmailerException
2427 * @return boolean true on success, false if address already used or invalid in some way
2428 * @access protected
2429 */
2430 protected function addAnAddress($kind, $address, $name = '')
2431 {
2432 if (!in_array($kind, array('to', 'cc', 'bcc', 'Reply-To'))) {
2433 $error_message = $this->lang('Invalid recipient kind: ') . $kind;
2434 $this->setError($error_message);
2435 $this->edebug($error_message);
2436 if ($this->exceptions) {
2437 throw new phpmailerException($error_message);
2438 }
2439 return false;
2440 }
2441 if (!$this->validateAddress($address)) {
2442 $error_message = $this->lang('invalid_address') . " (addAnAddress $kind): $address";
2443 $this->setError($error_message);
2444 $this->edebug($error_message);
2445 if ($this->exceptions) {
2446 throw new phpmailerException($error_message);
2447 }
2448 return false;
2449 }
2450 if ($kind != 'Reply-To') {
2451 if (!array_key_exists(strtolower($address), $this->all_recipients)) {
2452 array_push($this->$kind, array($address, $name));
2453 $this->all_recipients[strtolower($address)] = true;
2454 return true;
2455 }
2456 } else {
2457 if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
2458 $this->ReplyTo[strtolower($address)] = array($address, $name);
2459 return true;
2460 }
2461 }
2462 return false;
2463 }
2464 /**
2465 * Parse and validate a string containing one or more RFC822-style comma-separated email addresses
2466 * of the form "display name <address>" into an array of name/address pairs.
2467 * Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available.
2468 * Note that quotes in the name part are removed.
2469 * @param string $addrstr The address list string
2470 * @param bool $useimap Whether to use the IMAP extension to parse the list
2471 * @return array
2472 * @link http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation
2473 */
2474 public function parseAddresses($addrstr, $useimap = true)
2475 {
2476 $addresses = array();
2477 if ($useimap and function_exists('imap_rfc822_parse_adrlist')) {
2478 //Use this built-in parser if it's available
2479 $list = imap_rfc822_parse_adrlist($addrstr, '');
2480 foreach ($list as $address) {
2481 if ($address->host != '.SYNTAX-ERROR.') {
2482 if ($this->validateAddress($address->mailbox . '@' . $address->host)) {
2483 $addresses[] = array(
2484 'name' => (property_exists($address, 'personal') ? $address->personal : ''),
2485 'address' => $address->mailbox . '@' . $address->host
2486 );
2487 }
2488 }
2489 }
2490 } else {
2491 //Use this simpler parser
2492 $list = explode(',', $addrstr);
2493 foreach ($list as $address) {
2494 $address = trim($address);
2495 //Is there a separate name part?
2496 if (strpos($address, '<') === false) {
2497 //No separate name, just use the whole thing
2498 if ($this->validateAddress($address)) {
2499 $addresses[] = array(
2500 'name' => '',
2501 'address' => $address
2502 );
2503 }
2504 } else {
2505 list($name, $email) = explode('<', $address);
2506 $email = trim(str_replace('>', '', $email));
2507 if ($this->validateAddress($email)) {
2508 $addresses[] = array(
2509 'name' => trim(str_replace(array('"', "'"), '', $name)),
2510 'address' => $email
2511 );
2512 }
2513 }
2514 }
2515 }
2516 return $addresses;
2517 }
2518 /**
2519 * Set the From and FromName properties.
2520 * @param string $address
2521 * @param string $name
2522 * @param boolean $auto Whether to also set the Sender address, defaults to true
2523 * @throws phpmailerException
2524 * @return boolean
2525 */
2526 public function setFrom($address, $name = '', $auto = true)
2527 {
2528 $address = trim($address);
2529 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
2530 // Don't validate now addresses with IDN. Will be done in send().
2531 if (($pos = strrpos($address, '@')) === false or
2532 (!$this->has8bitChars(substr($address, ++$pos)) or !$this->idnSupported()) and
2533 !$this->validateAddress($address)) {
2534 $error_message = $this->lang('invalid_address') . " (setFrom) $address";
2535 $this->setError($error_message);
2536 $this->edebug($error_message);
2537 if ($this->exceptions) {
2538 throw new phpmailerException($error_message);
2539 }
2540 return false;
2541 }
2542 $this->From = $address;
2543 $this->FromName = $name;
2544 if ($auto) {
2545 if (empty($this->Sender)) {
2546 $this->Sender = $address;
2547 }
2548 }
2549 return true;
2550 }
2551 /**
2552 * Return the Message-ID header of the last email.
2553 * Technically this is the value from the last time the headers were created,
2554 * but it's also the message ID of the last sent message except in
2555 * pathological cases.
2556 * @return string
2557 */
2558 public function getLastMessageID()
2559 {
2560 return $this->lastMessageID;
2561 }
2562 /**
2563 * Check that a string looks like an email address.
2564 * @param string $address The email address to check
2565 * @param string|callable $patternselect A selector for the validation pattern to use :
2566 * * `auto` Pick best pattern automatically;
2567 * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
2568 * * `pcre` Use old PCRE implementation;
2569 * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL;
2570 * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
2571 * * `noregex` Don't use a regex: super fast, really dumb.
2572 * Alternatively you may pass in a callable to inject your own validator, for example:
2573 * PHPMailer::validateAddress('user@example.com', function($address) {
2574 * return (strpos($address, '@') !== false);
2575 * });
2576 * You can also set the PHPMailer::$validator static to a callable, allowing built-in methods to use your validator.
2577 * @return boolean
2578 * @static
2579 * @access public
2580 */
2581 public static function validateAddress($address, $patternselect = null)
2582 {
2583 if (is_null($patternselect)) {
2584 $patternselect = self::$validator;
2585 }
2586 if (is_callable($patternselect)) {
2587 return call_user_func($patternselect, $address);
2588 }
2589 //Reject line breaks in addresses; it's valid RFC5322, but not RFC5321
2590 if (strpos($address, "\n") !== false or strpos($address, "\r") !== false) {
2591 return false;
2592 }
2593 if (!$patternselect or $patternselect == 'auto') {
2594 //Check this constant first so it works when extension_loaded() is disabled by safe mode
2595 //Constant was added in PHP 5.2.4
2596 if (defined('PCRE_VERSION')) {
2597 //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
2598 if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
2599 $patternselect = 'pcre8';
2600 } else {
2601 $patternselect = 'pcre';
2602 }
2603 } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
2604 //Fall back to older PCRE
2605 $patternselect = 'pcre';
2606 } else {
2607 //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
2608 if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
2609 $patternselect = 'php';
2610 } else {
2611 $patternselect = 'noregex';
2612 }
2613 }
2614 }
2615 switch ($patternselect) {
2616 case 'pcre8':
2617 /**
2618 * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
2619 * @link http://squiloople.com/2009/12/20/email-address-validation/
2620 * @copyright 2009-2010 Michael Rushton
2621 * Feel free to use and redistribute this code. But please keep this copyright notice.
2622 */
2623 return (boolean)preg_match(
2624 '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
2625 '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
2626 '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
2627 '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
2628 '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
2629 '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
2630 '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
2631 '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
2632 '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
2633 $address
2634 );
2635 case 'pcre':
2636 //An older regex that doesn't need a recent PCRE
2637 return (boolean)preg_match(
2638 '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
2639 '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
2640 '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
2641 '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
2642 '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
2643 '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
2644 '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
2645 '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
2646 '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
2647 '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
2648 $address
2649 );
2650 case 'html5':
2651 /**
2652 * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
2653 * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
2654 */
2655 return (boolean)preg_match(
2656 '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
2657 '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
2658 $address
2659 );
2660 case 'noregex':
2661 //No PCRE! Do something _very_ approximate!
2662 //Check the address is 3 chars or longer and contains an @ that's not the first or last char
2663 return (strlen($address) >= 3
2664 and strpos($address, '@') >= 1
2665 and strpos($address, '@') != strlen($address) - 1);
2666 case 'php':
2667 default:
2668 return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
2669 }
2670 }
2671 /**
2672 * Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the
2673 * "intl" and "mbstring" PHP extensions.
2674 * @return bool "true" if required functions for IDN support are present
2675 */
2676 public function idnSupported()
2677 {
2678 // @TODO: Write our own "idn_to_ascii" function for PHP <= 5.2.
2679 return function_exists('idn_to_ascii') and function_exists('mb_convert_encoding');
2680 }
2681 /**
2682 * Converts IDN in given email address to its ASCII form, also known as punycode, if possible.
2683 * Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet.
2684 * This function silently returns unmodified address if:
2685 * - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form)
2686 * - Conversion to punycode is impossible (e.g. required PHP functions are not available)
2687 * or fails for any reason (e.g. domain has characters not allowed in an IDN)
2688 * @see PHPMailer::$CharSet
2689 * @param string $address The email address to convert
2690 * @return string The encoded address in ASCII form
2691 */
2692 public function punyencodeAddress($address)
2693 {
2694 // Verify we have required functions, CharSet, and at-sign.
2695 if ($this->idnSupported() and
2696 !empty($this->CharSet) and
2697 ($pos = strrpos($address, '@')) !== false) {
2698 $domain = substr($address, ++$pos);
2699 // Verify CharSet string is a valid one, and domain properly encoded in this CharSet.
2700 if ($this->has8bitChars($domain) and @mb_check_encoding($domain, $this->CharSet)) {
2701 $domain = mb_convert_encoding($domain, 'UTF-8', $this->CharSet);
2702 if (($punycode = defined('INTL_IDNA_VARIANT_UTS46') ?
2703 idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) :
2704 idn_to_ascii($domain)) !== false) {
2705 return substr($address, 0, $pos) . $punycode;
2706 }
2707 }
2708 }
2709 return $address;
2710 }
2711 /**
2712 * Create a message and send it.
2713 * Uses the sending method specified by $Mailer.
2714 * @throws phpmailerException
2715 * @return boolean false on error - See the ErrorInfo property for details of the error.
2716 */
2717 public function send()
2718 {
2719 try {
2720 if (!$this->preSend()) {
2721 return false;
2722 }
2723 return $this->postSend();
2724 } catch (phpmailerException $exc) {
2725 $this->mailHeader = '';
2726 $this->setError($exc->getMessage());
2727 if ($this->exceptions) {
2728 throw $exc;
2729 }
2730 return false;
2731 }
2732 }
2733 /**
2734 * Prepare a message for sending.
2735 * @throws phpmailerException
2736 * @return boolean
2737 */
2738 public function preSend()
2739 {
2740 try {
2741 $this->error_count = 0; // Reset errors
2742 $this->mailHeader = '';
2743 // Dequeue recipient and Reply-To addresses with IDN
2744 foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) {
2745 $params[1] = $this->punyencodeAddress($params[1]);
2746 call_user_func_array(array($this, 'addAnAddress'), $params);
2747 }
2748 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
2749 throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
2750 }
2751 // Validate From, Sender, and ConfirmReadingTo addresses
2752 foreach (array('From', 'Sender', 'ConfirmReadingTo') as $address_kind) {
2753 $this->$address_kind = trim($this->$address_kind);
2754 if (empty($this->$address_kind)) {
2755 continue;
2756 }
2757 $this->$address_kind = $this->punyencodeAddress($this->$address_kind);
2758 if (!$this->validateAddress($this->$address_kind)) {
2759 $error_message = $this->lang('invalid_address') . ' (punyEncode) ' . $this->$address_kind;
2760 $this->setError($error_message);
2761 $this->edebug($error_message);
2762 if ($this->exceptions) {
2763 throw new phpmailerException($error_message);
2764 }
2765 return false;
2766 }
2767 }
2768 // Set whether the message is multipart/alternative
2769 if ($this->alternativeExists()) {
2770 $this->ContentType = 'multipart/alternative';
2771 }
2772 $this->setMessageType();
2773 // Refuse to send an empty message unless we are specifically allowing it
2774 if (!$this->AllowEmpty and empty($this->Body)) {
2775 throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
2776 }
2777 // Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
2778 $this->MIMEHeader = '';
2779 $this->MIMEBody = $this->createBody();
2780 // createBody may have added some headers, so retain them
2781 $tempheaders = $this->MIMEHeader;
2782 $this->MIMEHeader = $this->createHeader();
2783 $this->MIMEHeader .= $tempheaders;
2784 // To capture the complete message when using mail(), create
2785 // an extra header list which createHeader() doesn't fold in
2786 if ($this->Mailer == 'mail') {
2787 if (count($this->to) > 0) {
2788 $this->mailHeader .= $this->addrAppend('To', $this->to);
2789 } else {
2790 $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
2791 }
2792 $this->mailHeader .= $this->headerLine(
2793 'Subject',
2794 $this->encodeHeader($this->secureHeader(trim($this->Subject)))
2795 );
2796 }
2797 // Sign with DKIM if enabled
2798 if (!empty($this->DKIM_domain)
2799 && !empty($this->DKIM_selector)
2800 && (!empty($this->DKIM_private_string)
2801 || (!empty($this->DKIM_private) && file_exists($this->DKIM_private))
2802 )
2803 ) {
2804 $header_dkim = $this->DKIM_Add(
2805 $this->MIMEHeader . $this->mailHeader,
2806 $this->encodeHeader($this->secureHeader($this->Subject)),
2807 $this->MIMEBody
2808 );
2809 $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
2810 str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
2811 }
2812 return true;
2813 } catch (phpmailerException $exc) {
2814 $this->setError($exc->getMessage());
2815 if ($this->exceptions) {
2816 throw $exc;
2817 }
2818 return false;
2819 }
2820 }
2821 /**
2822 * Actually send a message.
2823 * Send the email via the selected mechanism
2824 * @throws phpmailerException
2825 * @return boolean
2826 */
2827 public function postSend()
2828 {
2829 try {
2830 // Choose the mailer and send through it
2831 switch ($this->Mailer) {
2832 case 'sendmail':
2833 case 'qmail':
2834 return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
2835 case 'smtp':
2836 return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
2837 case 'mail':
2838 return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
2839 default:
2840 $sendMethod = $this->Mailer.'Send';
2841 if (method_exists($this, $sendMethod)) {
2842 return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
2843 }
2844 return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
2845 }
2846 } catch (phpmailerException $exc) {
2847 $this->setError($exc->getMessage());
2848 $this->edebug($exc->getMessage());
2849 if ($this->exceptions) {
2850 throw $exc;
2851 }
2852 }
2853 return false;
2854 }
2855 /**
2856 * Send mail using the $Sendmail program.
2857 * @param string $header The message headers
2858 * @param string $body The message body
2859 * @see PHPMailer::$Sendmail
2860 * @throws phpmailerException
2861 * @access protected
2862 * @return boolean
2863 */
2864 protected function sendmailSend($header, $body)
2865 {
2866 if ($this->Sender != '') {
2867 if ($this->Mailer == 'qmail') {
2868 $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
2869 } else {
2870 $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
2871 }
2872 } else {
2873 if ($this->Mailer == 'qmail') {
2874 $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
2875 } else {
2876 $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
2877 }
2878 }
2879 if ($this->SingleTo) {
2880 foreach ($this->SingleToArray as $toAddr) {
2881 if (!@$mail = popen($sendmail, 'w')) {
2882 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
2883 }
2884 fputs($mail, 'To: ' . $toAddr . "\n");
2885 fputs($mail, $header);
2886 fputs($mail, $body);
2887 $result = pclose($mail);
2888 $this->doCallback(
2889 ($result == 0),
2890 array($toAddr),
2891 $this->cc,
2892 $this->bcc,
2893 $this->Subject,
2894 $body,
2895 $this->From
2896 );
2897 if ($result != 0) {
2898 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
2899 }
2900 }
2901 } else {
2902 if (!@$mail = popen($sendmail, 'w')) {
2903 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
2904 }
2905 fputs($mail, $header);
2906 fputs($mail, $body);
2907 $result = pclose($mail);
2908 $this->doCallback(
2909 ($result == 0),
2910 $this->to,
2911 $this->cc,
2912 $this->bcc,
2913 $this->Subject,
2914 $body,
2915 $this->From
2916 );
2917 if ($result != 0) {
2918 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
2919 }
2920 }
2921 return true;
2922 }
2923 /**
2924 * Send mail using the PHP mail() function.
2925 * @param string $header The message headers
2926 * @param string $body The message body
2927 * @link http://www.php.net/manual/en/book.mail.php
2928 * @throws phpmailerException
2929 * @access protected
2930 * @return boolean
2931 */
2932 protected function mailSend($header, $body)
2933 {
2934 $toArr = array();
2935 foreach ($this->to as $toaddr) {
2936 $toArr[] = $this->addrFormat($toaddr);
2937 }
2938 $to = implode(', ', $toArr);
2939 $params = null;
2940 //This sets the SMTP envelope sender which gets turned into a return-path header by the receiver
2941 if (!empty($this->Sender)) {
2942 $params = sprintf('-f%s', $this->Sender);
2943 }
2944 if ($this->Sender != '' and !ini_get('safe_mode')) {
2945 $old_from = ini_get('sendmail_from');
2946 ini_set('sendmail_from', $this->Sender);
2947 }
2948 $result = false;
2949 if ($this->SingleTo and count($toArr) > 1) {
2950 foreach ($toArr as $toAddr) {
2951 $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
2952 $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
2953 }
2954 } else {
2955 $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
2956 $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
2957 }
2958 if (isset($old_from)) {
2959 ini_set('sendmail_from', $old_from);
2960 }
2961 if (!$result) {
2962 throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
2963 }
2964 return true;
2965 }
2966 /**
2967 * Get an instance to use for SMTP operations.
2968 * Override this function to load your own SMTP implementation
2969 * @return SMTP
2970 */
2971 public function getSMTPInstance()
2972 {
2973 if (!is_object($this->smtp)) {
2974 $this->smtp = new SMTP;
2975 }
2976 return $this->smtp;
2977 }
2978 /**
2979 * Send mail via SMTP.
2980 * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
2981 * Uses the PHPMailerSMTP class by default.
2982 * @see PHPMailer::getSMTPInstance() to use a different class.
2983 * @param string $header The message headers
2984 * @param string $body The message body
2985 * @throws phpmailerException
2986 * @uses SMTP
2987 * @access protected
2988 * @return boolean
2989 */
2990 protected function smtpSend($header, $body)
2991 {
2992 $bad_rcpt = array();
2993 if (!$this->smtpConnect($this->SMTPOptions)) {
2994 throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
2995 }
2996 if ('' == $this->Sender) {
2997 $smtp_from = $this->From;
2998 } else {
2999 $smtp_from = $this->Sender;
3000 }
3001 if (!$this->smtp->mail($smtp_from)) {
3002 $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
3003 throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
3004 }
3005 // Attempt to send to all recipients
3006 foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
3007 foreach ($togroup as $to) {
3008 if (!$this->smtp->recipient($to[0])) {
3009 $error = $this->smtp->getError();
3010 $bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
3011 $isSent = false;
3012 } else {
3013 $isSent = true;
3014 }
3015 $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
3016 }
3017 }
3018 // Only send the DATA command if we have viable recipients
3019 if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
3020 throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
3021 }
3022 if ($this->SMTPKeepAlive) {
3023 $this->smtp->reset();
3024 } else {
3025 $this->smtp->quit();
3026 $this->smtp->close();
3027 }
3028 //Create error message for any bad addresses
3029 if (count($bad_rcpt) > 0) {
3030 $errstr = '';
3031 foreach ($bad_rcpt as $bad) {
3032 $errstr .= $bad['to'] . ': ' . $bad['error'];
3033 }
3034 throw new phpmailerException(
3035 $this->lang('recipients_failed') . $errstr,
3036 self::STOP_CONTINUE
3037 );
3038 }
3039 return true;
3040 }
3041 /**
3042 * Initiate a connection to an SMTP server.
3043 * Returns false if the operation failed.
3044 * @param array $options An array of options compatible with stream_context_create()
3045 * @uses SMTP
3046 * @access public
3047 * @throws phpmailerException
3048 * @return boolean
3049 */
3050 public function smtpConnect($options = null)
3051 {
3052 if (is_null($this->smtp)) {
3053 $this->smtp = $this->getSMTPInstance();
3054 }
3055 //If no options are provided, use whatever is set in the instance
3056 if (is_null($options)) {
3057 $options = $this->SMTPOptions;
3058 }
3059 // Already connected?
3060 if ($this->smtp->connected()) {
3061 return true;
3062 }
3063 $this->smtp->setTimeout($this->Timeout);
3064 $this->smtp->setDebugLevel($this->SMTPDebug);
3065 $this->smtp->setDebugOutput($this->Debugoutput);
3066 $this->smtp->setVerp($this->do_verp);
3067 $hosts = explode(';', $this->Host);
3068 $lastexception = null;
3069 foreach ($hosts as $hostentry) {
3070 $hostinfo = array();
3071 if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9:\[\]\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)){
3072 // Not a valid host entry
3073 continue;
3074 }
3075 // $hostinfo[2]: optional ssl or tls prefix
3076 // $hostinfo[3]: the hostname
3077 // $hostinfo[4]: optional port number
3078 // The host string prefix can temporarily override the current setting for SMTPSecure
3079 // If it's not specified, the default value is used
3080 $prefix = '';
3081 $secure = $this->SMTPSecure;
3082 $tls = ($this->SMTPSecure == 'tls');
3083 if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
3084 $prefix = 'ssl://';
3085 $tls = false; // Can't have SSL and TLS at the same time
3086 $secure = 'ssl';
3087 } elseif ($hostinfo[2] == 'tls') {
3088 $tls = true;
3089 // tls doesn't use a prefix
3090 $secure = 'tls';
3091 }
3092 //Do we need the OpenSSL extension?
3093 $sslext = defined('OPENSSL_ALGO_SHA1');
3094 if ('tls' === $secure or 'ssl' === $secure) {
3095 //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
3096 if (!$sslext) {
3097 throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
3098 }
3099 }
3100 $host = $hostinfo[3];
3101 $port = $this->Port;
3102 $tport = (integer)$hostinfo[4];
3103 if ($tport > 0 and $tport < 65536) {
3104 $port = $tport;
3105 }
3106 if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
3107 try {
3108 if ($this->Helo) {
3109 $hello = $this->Helo;
3110 } else {
3111 $hello = $this->serverHostname();
3112 }
3113 $this->smtp->hello($hello);
3114 //Automatically enable TLS encryption if:
3115 // * it's not disabled
3116 // * we have openssl extension
3117 // * we are not already using SSL
3118 // * the server offers STARTTLS
3119 if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
3120 $tls = true;
3121 }
3122 if ($tls) {
3123 if (!$this->smtp->startTLS()) {
3124 throw new phpmailerException($this->lang('connect_host'));
3125 }
3126 // We must resend EHLO after TLS negotiation
3127 $this->smtp->hello($hello);
3128 }
3129 if ($this->SMTPAuth) {
3130 if (!$this->smtp->authenticate(
3131 $this->Username,
3132 $this->Password,
3133 $this->AuthType,
3134 $this->Realm,
3135 $this->Workstation
3136 )
3137 ) {
3138 throw new phpmailerException($this->lang('authenticate'));
3139 }
3140 }
3141 return true;
3142 } catch (phpmailerException $exc) {
3143 $lastexception = $exc;
3144 $this->edebug($exc->getMessage());
3145 // We must have connected, but then failed TLS or Auth, so close connection nicely
3146 $this->smtp->quit();
3147 }
3148 }
3149 }
3150 // If we get here, all connection attempts have failed, so close connection hard
3151 $this->smtp->close();
3152 // As we've caught all exceptions, just report whatever the last one was
3153 if ($this->exceptions and !is_null($lastexception)) {
3154 throw $lastexception;
3155 }
3156 return false;
3157 }
3158 /**
3159 * Close the active SMTP session if one exists.
3160 * @return void
3161 */
3162 public function smtpClose()
3163 {
3164 if (is_a($this->smtp, 'SMTP')) {
3165 if ($this->smtp->connected()) {
3166 $this->smtp->quit();
3167 $this->smtp->close();
3168 }
3169 }
3170 }
3171 /**
3172 * Set the language for error messages.
3173 * Returns false if it cannot load the language file.
3174 * The default language is English.
3175 * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
3176 * @param string $lang_path Path to the language file directory, with trailing separator (slash)
3177 * @return boolean
3178 * @access public
3179 */
3180 public function setLanguage($langcode = 'en', $lang_path = '')
3181 {
3182 // Backwards compatibility for renamed language codes
3183 $renamed_langcodes = array(
3184 'br' => 'pt_br',
3185 'cz' => 'cs',
3186 'dk' => 'da',
3187 'no' => 'nb',
3188 'se' => 'sv',
3189 );
3190 if (isset($renamed_langcodes[$langcode])) {
3191 $langcode = $renamed_langcodes[$langcode];
3192 }
3193 // Define full set of translatable strings in English
3194 $PHPMAILER_LANG = array(
3195 'authenticate' => 'SMTP Error: Could not authenticate.',
3196 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
3197 'data_not_accepted' => 'SMTP Error: data not accepted.',
3198 'empty_message' => 'Message body empty',
3199 'encoding' => 'Unknown encoding: ',
3200 'execute' => 'Could not execute: ',
3201 'file_access' => 'Could not access file: ',
3202 'file_open' => 'File Error: Could not open file: ',
3203 'from_failed' => 'The following From address failed: ',
3204 'instantiate' => 'Could not instantiate mail function.',
3205 'invalid_address' => 'Invalid address: ',
3206 'mailer_not_supported' => ' mailer is not supported.',
3207 'provide_address' => 'You must provide at least one recipient email address.',
3208 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
3209 'signing' => 'Signing Error: ',
3210 'smtp_connect_failed' => 'SMTP connect() failed.',
3211 'smtp_error' => 'SMTP server error: ',
3212 'variable_set' => 'Cannot set or reset variable: ',
3213 'extension_missing' => 'Extension missing: '
3214 );
3215 if (empty($lang_path)) {
3216 // Calculate an absolute path so it can work if CWD is not here
3217 $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
3218 }
3219 //Validate $langcode
3220 if (!preg_match('/^[a-z]{2}(?:_[a-zA-Z]{2})?$/', $langcode)) {
3221 $langcode = 'en';
3222 }
3223 $foundlang = true;
3224 $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
3225 // There is no English translation file
3226 if ($langcode != 'en') {
3227 // Make sure language file path is readable
3228 if (!is_readable($lang_file)) {
3229 $foundlang = false;
3230 } else {
3231 // Overwrite language-specific strings.
3232 // This way we'll never have missing translation keys.
3233 $foundlang = include $lang_file;
3234 }
3235 }
3236 $this->language = $PHPMAILER_LANG;
3237 return (boolean)$foundlang; // Returns false if language not found
3238 }
3239 /**
3240 * Get the array of strings for the current language.
3241 * @return array
3242 */
3243 public function getTranslations()
3244 {
3245 return $this->language;
3246 }
3247 /**
3248 * Create recipient headers.
3249 * @access public
3250 * @param string $type
3251 * @param array $addr An array of recipient,
3252 * where each recipient is a 2-element indexed array with element 0 containing an address
3253 * and element 1 containing a name, like:
3254 * array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
3255 * @return string
3256 */
3257 public function addrAppend($type, $addr)
3258 {
3259 $addresses = array();
3260 foreach ($addr as $address) {
3261 $addresses[] = $this->addrFormat($address);
3262 }
3263 return $type . ': ' . implode(', ', $addresses) . $this->LE;
3264 }
3265 /**
3266 * Format an address for use in a message header.
3267 * @access public
3268 * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
3269 * like array('joe@example.com', 'Joe User')
3270 * @return string
3271 */
3272 public function addrFormat($addr)
3273 {
3274 if (empty($addr[1])) { // No name provided
3275 return $this->secureHeader($addr[0]);
3276 } else {
3277 return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
3278 $addr[0]
3279 ) . '>';
3280 }
3281 }
3282 /**
3283 * Word-wrap message.
3284 * For use with mailers that do not automatically perform wrapping
3285 * and for quoted-printable encoded messages.
3286 * Original written by philippe.
3287 * @param string $message The message to wrap
3288 * @param integer $length The line length to wrap to
3289 * @param boolean $qp_mode Whether to run in Quoted-Printable mode
3290 * @access public
3291 * @return string
3292 */
3293 public function wrapText($message, $length, $qp_mode = false)
3294 {
3295 if ($qp_mode) {
3296 $soft_break = sprintf(' =%s', $this->LE);
3297 } else {
3298 $soft_break = $this->LE;
3299 }
3300 // If utf-8 encoding is used, we will need to make sure we don't
3301 // split multibyte characters when we wrap
3302 $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
3303 $lelen = strlen($this->LE);
3304 $crlflen = strlen(self::CRLF);
3305 $message = $this->fixEOL($message);
3306 //Remove a trailing line break
3307 if (substr($message, -$lelen) == $this->LE) {
3308 $message = substr($message, 0, -$lelen);
3309 }
3310 //Split message into lines
3311 $lines = explode($this->LE, $message);
3312 //Message will be rebuilt in here
3313 $message = '';
3314 foreach ($lines as $line) {
3315 $words = explode(' ', $line);
3316 $buf = '';
3317 $firstword = true;
3318 foreach ($words as $word) {
3319 if ($qp_mode and (strlen($word) > $length)) {
3320 $space_left = $length - strlen($buf) - $crlflen;
3321 if (!$firstword) {
3322 if ($space_left > 20) {
3323 $len = $space_left;
3324 if ($is_utf8) {
3325 $len = $this->utf8CharBoundary($word, $len);
3326 } elseif (substr($word, $len - 1, 1) == '=') {
3327 $len--;
3328 } elseif (substr($word, $len - 2, 1) == '=') {
3329 $len -= 2;
3330 }
3331 $part = substr($word, 0, $len);
3332 $word = substr($word, $len);
3333 $buf .= ' ' . $part;
3334 $message .= $buf . sprintf('=%s', self::CRLF);
3335 } else {
3336 $message .= $buf . $soft_break;
3337 }
3338 $buf = '';
3339 }
3340 while (strlen($word) > 0) {
3341 if ($length <= 0) {
3342 break;
3343 }
3344 $len = $length;
3345 if ($is_utf8) {
3346 $len = $this->utf8CharBoundary($word, $len);
3347 } elseif (substr($word, $len - 1, 1) == '=') {
3348 $len--;
3349 } elseif (substr($word, $len - 2, 1) == '=') {
3350 $len -= 2;
3351 }
3352 $part = substr($word, 0, $len);
3353 $word = substr($word, $len);
3354 if (strlen($word) > 0) {
3355 $message .= $part . sprintf('=%s', self::CRLF);
3356 } else {
3357 $buf = $part;
3358 }
3359 }
3360 } else {
3361 $buf_o = $buf;
3362 if (!$firstword) {
3363 $buf .= ' ';
3364 }
3365 $buf .= $word;
3366 if (strlen($buf) > $length and $buf_o != '') {
3367 $message .= $buf_o . $soft_break;
3368 $buf = $word;
3369 }
3370 }
3371 $firstword = false;
3372 }
3373 $message .= $buf . self::CRLF;
3374 }
3375 return $message;
3376 }
3377 /**
3378 * Find the last character boundary prior to $maxLength in a utf-8
3379 * quoted-printable encoded string.
3380 * Original written by Colin Brown.
3381 * @access public
3382 * @param string $encodedText utf-8 QP text
3383 * @param integer $maxLength Find the last character boundary prior to this length
3384 * @return integer
3385 */
3386 public function utf8CharBoundary($encodedText, $maxLength)
3387 {
3388 $foundSplitPos = false;
3389 $lookBack = 3;
3390 while (!$foundSplitPos) {
3391 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
3392 $encodedCharPos = strpos($lastChunk, '=');
3393 if (false !== $encodedCharPos) {
3394 // Found start of encoded character byte within $lookBack block.
3395 // Check the encoded byte value (the 2 chars after the '=')
3396 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
3397 $dec = hexdec($hex);
3398 if ($dec < 128) {
3399 // Single byte character.
3400 // If the encoded char was found at pos 0, it will fit
3401 // otherwise reduce maxLength to start of the encoded char
3402 if ($encodedCharPos > 0) {
3403 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
3404 }
3405 $foundSplitPos = true;
3406 } elseif ($dec >= 192) {
3407 // First byte of a multi byte character
3408 // Reduce maxLength to split at start of character
3409 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
3410 $foundSplitPos = true;
3411 } elseif ($dec < 192) {
3412 // Middle byte of a multi byte character, look further back
3413 $lookBack += 3;
3414 }
3415 } else {
3416 // No encoded character found
3417 $foundSplitPos = true;
3418 }
3419 }
3420 return $maxLength;
3421 }
3422 /**
3423 * Apply word wrapping to the message body.
3424 * Wraps the message body to the number of chars set in the WordWrap property.
3425 * You should only do this to plain-text bodies as wrapping HTML tags may break them.
3426 * This is called automatically by createBody(), so you don't need to call it yourself.
3427 * @access public
3428 * @return void
3429 */
3430 public function setWordWrap()
3431 {
3432 if ($this->WordWrap < 1) {
3433 return;
3434 }
3435 switch ($this->message_type) {
3436 case 'alt':
3437 case 'alt_inline':
3438 case 'alt_attach':
3439 case 'alt_inline_attach':
3440 $this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
3441 break;
3442 default:
3443 $this->Body = $this->wrapText($this->Body, $this->WordWrap);
3444 break;
3445 }
3446 }
3447 /**
3448 * Assemble message headers.
3449 * @access public
3450 * @return string The assembled headers
3451 */
3452 public function createHeader()
3453 {
3454 $result = '';
3455 if ($this->MessageDate == '') {
3456 $this->MessageDate = self::rfcDate();
3457 }
3458 $result .= $this->headerLine('Date', $this->MessageDate == '' ? self::rfcDate() : $this->MessageDate);
3459 // To be created automatically by mail()
3460 if ($this->SingleTo) {
3461 if ($this->Mailer != 'mail') {
3462 foreach ($this->to as $toaddr) {
3463 $this->SingleToArray[] = $this->addrFormat($toaddr);
3464 }
3465 }
3466 } else {
3467 if (count($this->to) > 0) {
3468 if ($this->Mailer != 'mail') {
3469 $result .= $this->addrAppend('To', $this->to);
3470 }
3471 } elseif (count($this->cc) == 0) {
3472 $result .= $this->headerLine('To', 'undisclosed-recipients:;');
3473 }
3474 }
3475 $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
3476 // sendmail and mail() extract Cc from the header before sending
3477 if (count($this->cc) > 0) {
3478 $result .= $this->addrAppend('Cc', $this->cc);
3479 }
3480 // sendmail and mail() extract Bcc from the header before sending
3481 if ((
3482 $this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail'
3483 )
3484 and count($this->bcc) > 0
3485 ) {
3486 $result .= $this->addrAppend('Bcc', $this->bcc);
3487 }
3488 if (count($this->ReplyTo) > 0) {
3489 $result .= $this->addrAppend('Reply-To', $this->ReplyTo);
3490 }
3491 // mail() sets the subject itself
3492 if ($this->Mailer != 'mail') {
3493 $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
3494 }
3495 // Only allow a custom message ID if it conforms to RFC 5322 section 3.6.4
3496 // https://tools.ietf.org/html/rfc5322#section-3.6.4
3497 if ('' != $this->MessageID and preg_match('/^<.*@.*>$/', $this->MessageID)) {
3498 $this->lastMessageID = $this->MessageID;
3499 } else {
3500 //$this->lastMessageID = sprintf('<%s@%s>', $this->uniqueid, $this->serverHostname());
3501 $this->lastMessageID = '<'.md5($this->uniqueid)."@".explode("@",$this->From)[1].'>';
3502 }
3503 $result .= $this->headerLine('Message-ID', $this->lastMessageID);
3504 if (!is_null($this->Priority)) {
3505 $result .= $this->headerLine('X-Priority', $this->Priority);
3506 }
3507 /* if ($this->XMailer == '') {
3508 $result .= $this->headerLine(
3509 'X-Mailer',
3510 //'PHPMailer ' . $this->Version . '(https://github.com/PHPMailer/PHPMailer)'
3511 'PHPMailer ' . $this->uniqueid
3512 );
3513 } else {
3514 $myXmailer = trim($this->XMailer);
3515 if ($myXmailer) {
3516 //$result .= $this->headerLine('X-Mailer', $myXmailer);
3517 $result .= $this->headerLine('X-Mailer', $myXmailer.$this->uniqueid);
3518 }
3519 }*/
3520 if ($this->ConfirmReadingTo != '') {
3521 $result .= $this->headerLine('Disposition-Notification-To', '<' . $this->ConfirmReadingTo . '>');
3522 }
3523 // Add custom headers
3524 foreach ($this->CustomHeader as $header) {
3525 $result .= $this->headerLine(
3526 trim($header[0]),
3527 $this->encodeHeader(trim($header[1]))
3528 );
3529 }
3530 if (!$this->sign_key_file) {
3531 $result .= $this->headerLine('MIME-Version', '1.0');
3532 $result .= $this->getMailMIME();
3533 }
3534 return $result;
3535 }
3536 /**
3537 * Get the message MIME type headers.
3538 * @access public
3539 * @return string
3540 */
3541 public function getMailMIME()
3542 {
3543 $result = '';
3544 $ismultipart = true;
3545 switch ($this->message_type) {
3546 case 'inline':
3547 $result .= $this->headerLine('Content-Type', 'multipart/related;');
3548 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
3549 break;
3550 case 'attach':
3551 case 'inline_attach':
3552 case 'alt_attach':
3553 case 'alt_inline_attach':
3554 $result .= $this->headerLine('Content-Type', 'multipart/mixed;');
3555 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
3556 break;
3557 case 'alt':
3558 case 'alt_inline':
3559 $result .= $this->headerLine('Content-Type', 'multipart/alternative;');
3560 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
3561 break;
3562 default:
3563 // Catches case 'plain': and case '':
3564 $result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
3565 $ismultipart = false;
3566 break;
3567 }
3568 // RFC1341 part 5 says 7bit is assumed if not specified
3569 if ($this->Encoding != '7bit') {
3570 // RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
3571 if ($ismultipart) {
3572 if ($this->Encoding == '8bit') {
3573 $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
3574 }
3575 // The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
3576 } else {
3577 $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
3578 }
3579 }
3580 if ($this->Mailer != 'mail') {
3581 $result .= $this->LE;
3582 }
3583 return $result;
3584 }
3585 /**
3586 * Returns the whole MIME message.
3587 * Includes complete headers and body.
3588 * Only valid post preSend().
3589 * @see PHPMailer::preSend()
3590 * @access public
3591 * @return string
3592 */
3593 public function getSentMIMEMessage()
3594 {
3595 return rtrim($this->MIMEHeader . $this->mailHeader, "\n\r") . self::CRLF . self::CRLF . $this->MIMEBody;
3596 }
3597 /**
3598 * Create unique ID
3599 * @return string
3600 */
3601 protected function generateId() {
3602 return md5(uniqid(time()));
3603 }
3604 /**
3605 * Assemble the message body.
3606 * Returns an empty string on failure.
3607 * @access public
3608 * @throws phpmailerException
3609 * @return string The assembled message body
3610 */
3611 public function createBody()
3612 {
3613 $body = '';
3614 //Create unique IDs and preset boundaries
3615 $this->uniqueid = $this->generateId();
3616 $this->boundary[1] = '1' . $this->uniqueid;
3617 $this->boundary[2] = '2' . $this->uniqueid;
3618 $this->boundary[3] = '3' . $this->uniqueid;
3619 if ($this->sign_key_file) {
3620 $body .= $this->getMailMIME() . $this->LE;
3621 }
3622 $this->setWordWrap();
3623 $bodyEncoding = $this->Encoding;
3624 $bodyCharSet = $this->CharSet;
3625 //Can we do a 7-bit downgrade?
3626 if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
3627 $bodyEncoding = '7bit';
3628 //All ISO 8859, Windows codepage and UTF-8 charsets are ascii compatible up to 7-bit
3629 $bodyCharSet = 'us-ascii';
3630 }
3631 //If lines are too long, and we're not already using an encoding that will shorten them,
3632 //change to quoted-printable transfer encoding for the body part only
3633 if ('base64' != $this->Encoding and self::hasLineLongerThanMax($this->Body)) {
3634 $bodyEncoding = 'quoted-printable';
3635 }
3636 $altBodyEncoding = $this->Encoding;
3637 $altBodyCharSet = $this->CharSet;
3638 //Can we do a 7-bit downgrade?
3639 if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
3640 $altBodyEncoding = '7bit';
3641 //All ISO 8859, Windows codepage and UTF-8 charsets are ascii compatible up to 7-bit
3642 $altBodyCharSet = 'us-ascii';
3643 }
3644 //If lines are too long, and we're not already using an encoding that will shorten them,
3645 //change to quoted-printable transfer encoding for the alt body part only
3646 if ('base64' != $altBodyEncoding and self::hasLineLongerThanMax($this->AltBody)) {
3647 $altBodyEncoding = 'quoted-printable';
3648 }
3649 //Use this as a preamble in all multipart message types
3650 $mimepre = "This is a multi-part message in MIME format." . $this->LE . $this->LE;
3651 switch ($this->message_type) {
3652 case 'inline':
3653 $body .= $mimepre;
3654 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
3655 $body .= $this->encodeString($this->Body, $bodyEncoding);
3656 $body .= $this->LE . $this->LE;
3657 $body .= $this->attachAll('inline', $this->boundary[1]);
3658 break;
3659 case 'attach':
3660 $body .= $mimepre;
3661 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
3662 $body .= $this->encodeString($this->Body, $bodyEncoding);
3663 $body .= $this->LE . $this->LE;
3664 $body .= $this->attachAll('attachment', $this->boundary[1]);
3665 break;
3666 case 'inline_attach':
3667 $body .= $mimepre;
3668 $body .= $this->textLine('--' . $this->boundary[1]);
3669 $body .= $this->headerLine('Content-Type', 'multipart/related;');
3670 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
3671 $body .= $this->LE;
3672 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
3673 $body .= $this->encodeString($this->Body, $bodyEncoding);
3674 $body .= $this->LE . $this->LE;
3675 $body .= $this->attachAll('inline', $this->boundary[2]);
3676 $body .= $this->LE;
3677 $body .= $this->attachAll('attachment', $this->boundary[1]);
3678 break;
3679 case 'alt':
3680 $body .= $mimepre;
3681 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
3682 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
3683 $body .= $this->LE . $this->LE;
3684 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
3685 $body .= $this->encodeString($this->Body, $bodyEncoding);
3686 $body .= $this->LE . $this->LE;
3687 if (!empty($this->Ical)) {
3688 $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
3689 $body .= $this->encodeString($this->Ical, $this->Encoding);
3690 $body .= $this->LE . $this->LE;
3691 }
3692 $body .= $this->endBoundary($this->boundary[1]);
3693 break;
3694 case 'alt_inline':
3695 $body .= $mimepre;
3696 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
3697 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
3698 $body .= $this->LE . $this->LE;
3699 $body .= $this->textLine('--' . $this->boundary[1]);
3700 $body .= $this->headerLine('Content-Type', 'multipart/related;');
3701 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
3702 $body .= $this->LE;
3703 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
3704 $body .= $this->encodeString($this->Body, $bodyEncoding);
3705 $body .= $this->LE . $this->LE;
3706 $body .= $this->attachAll('inline', $this->boundary[2]);
3707 $body .= $this->LE;
3708 $body .= $this->endBoundary($this->boundary[1]);
3709 break;
3710 case 'alt_attach':
3711 $body .= $mimepre;
3712 $body .= $this->textLine('--' . $this->boundary[1]);
3713 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
3714 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
3715 $body .= $this->LE;
3716 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
3717 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
3718 $body .= $this->LE . $this->LE;
3719 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
3720 $body .= $this->encodeString($this->Body, $bodyEncoding);
3721 $body .= $this->LE . $this->LE;
3722 $body .= $this->endBoundary($this->boundary[2]);
3723 $body .= $this->LE;
3724 $body .= $this->attachAll('attachment', $this->boundary[1]);
3725 break;
3726 case 'alt_inline_attach':
3727 $body .= $mimepre;
3728 $body .= $this->textLine('--' . $this->boundary[1]);
3729 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
3730 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
3731 $body .= $this->LE;
3732 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
3733 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
3734 $body .= $this->LE . $this->LE;
3735 $body .= $this->textLine('--' . $this->boundary[2]);
3736 $body .= $this->headerLine('Content-Type', 'multipart/related;');
3737 $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
3738 $body .= $this->LE;
3739 $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
3740 $body .= $this->encodeString($this->Body, $bodyEncoding);
3741 $body .= $this->LE . $this->LE;
3742 $body .= $this->attachAll('inline', $this->boundary[3]);
3743 $body .= $this->LE;
3744 $body .= $this->endBoundary($this->boundary[2]);
3745 $body .= $this->LE;
3746 $body .= $this->attachAll('attachment', $this->boundary[1]);
3747 break;
3748 default:
3749 // Catch case 'plain' and case '', applies to simple `text/plain` and `text/html` body content types
3750 //Reset the `Encoding` property in case we changed it for line length reasons
3751 $this->Encoding = $bodyEncoding;
3752 $body .= $this->encodeString($this->Body, $this->Encoding);
3753 break;
3754 }
3755 if ($this->isError()) {
3756 $body = '';
3757 } elseif ($this->sign_key_file) {
3758 try {
3759 if (!defined('PKCS7_TEXT')) {
3760 throw new phpmailerException($this->lang('extension_missing') . 'openssl');
3761 }
3762 // @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
3763 $file = tempnam(sys_get_temp_dir(), 'mail');
3764 if (false === file_put_contents($file, $body)) {
3765 throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
3766 }
3767 $signed = tempnam(sys_get_temp_dir(), 'signed');
3768 //Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
3769 if (empty($this->sign_extracerts_file)) {
3770 $sign = @openssl_pkcs7_sign(
3771 $file,
3772 $signed,
3773 'file://' . realpath($this->sign_cert_file),
3774 array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
3775 null
3776 );
3777 } else {
3778 $sign = @openssl_pkcs7_sign(
3779 $file,
3780 $signed,
3781 'file://' . realpath($this->sign_cert_file),
3782 array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
3783 null,
3784 PKCS7_DETACHED,
3785 $this->sign_extracerts_file
3786 );
3787 }
3788 if ($sign) {
3789 @unlink($file);
3790 $body = file_get_contents($signed);
3791 @unlink($signed);
3792 //The message returned by openssl contains both headers and body, so need to split them up
3793 $parts = explode("\n\n", $body, 2);
3794 $this->MIMEHeader .= $parts[0] . $this->LE . $this->LE;
3795 $body = $parts[1];
3796 } else {
3797 @unlink($file);
3798 @unlink($signed);
3799 throw new phpmailerException($this->lang('signing') . openssl_error_string());
3800 }
3801 } catch (phpmailerException $exc) {
3802 $body = '';
3803 if ($this->exceptions) {
3804 throw $exc;
3805 }
3806 }
3807 }
3808 return $body;
3809 }
3810 /**
3811 * Return the start of a message boundary.
3812 * @access protected
3813 * @param string $boundary
3814 * @param string $charSet
3815 * @param string $contentType
3816 * @param string $encoding
3817 * @return string
3818 */
3819 protected function getBoundary($boundary, $charSet, $contentType, $encoding)
3820 {
3821 $result = '';
3822 if ($charSet == '') {
3823 $charSet = $this->CharSet;
3824 }
3825 if ($contentType == '') {
3826 $contentType = $this->ContentType;
3827 }
3828 if ($encoding == '') {
3829 $encoding = $this->Encoding;
3830 }
3831 $result .= $this->textLine('--' . $boundary);
3832 $result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
3833 $result .= $this->LE;
3834 // RFC1341 part 5 says 7bit is assumed if not specified
3835 if ($encoding != '7bit') {
3836 $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
3837 }
3838 $result .= $this->LE;
3839 return $result;
3840 }
3841 /**
3842 * Return the end of a message boundary.
3843 * @access protected
3844 * @param string $boundary
3845 * @return string
3846 */
3847 protected function endBoundary($boundary)
3848 {
3849 return $this->LE . '--' . $boundary . '--' . $this->LE;
3850 }
3851 /**
3852 * Set the message type.
3853 * PHPMailer only supports some preset message types, not arbitrary MIME structures.
3854 * @access protected
3855 * @return void
3856 */
3857 protected function setMessageType()
3858 {
3859 $type = array();
3860 if ($this->alternativeExists()) {
3861 $type[] = 'alt';
3862 }
3863 if ($this->inlineImageExists()) {
3864 $type[] = 'inline';
3865 }
3866 if ($this->attachmentExists()) {
3867 $type[] = 'attach';
3868 }
3869 $this->message_type = implode('_', $type);
3870 if ($this->message_type == '') {
3871 //The 'plain' message_type refers to the message having a single body element, not that it is plain-text
3872 $this->message_type = 'plain';
3873 }
3874 }
3875 /**
3876 * Format a header line.
3877 * @access public
3878 * @param string $name
3879 * @param string $value
3880 * @return string
3881 */
3882 public function headerLine($name, $value)
3883 {
3884 return $name . ': ' . $value . $this->LE;
3885 }
3886 /**
3887 * Return a formatted mail line.
3888 * @access public
3889 * @param string $value
3890 * @return string
3891 */
3892 public function textLine($value)
3893 {
3894 return $value . $this->LE;
3895 }
3896 /**
3897 * Add an attachment from a path on the filesystem.
3898 * Returns false if the file could not be found or read.
3899 * @param string $path Path to the attachment.
3900 * @param string $name Overrides the attachment name.
3901 * @param string $encoding File encoding (see $Encoding).
3902 * @param string $type File extension (MIME) type.
3903 * @param string $disposition Disposition to use
3904 * @throws phpmailerException
3905 * @return boolean
3906 */
3907 public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
3908 {
3909 try {
3910 if (!@is_file($path)) {
3911 throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
3912 }
3913 // If a MIME type is not specified, try to work it out from the file name
3914 if ($type == '') {
3915 $type = self::filenameToType($path);
3916 }
3917 $filename = basename($path);
3918 if ($name == '') {
3919 $name = $filename;
3920 }
3921 $this->attachment[] = array(
3922 0 => $path,
3923 1 => $filename,
3924 2 => $name,
3925 3 => $encoding,
3926 4 => $type,
3927 5 => false, // isStringAttachment
3928 6 => $disposition,
3929 7 => 0
3930 );
3931 } catch (phpmailerException $exc) {
3932 $this->setError($exc->getMessage());
3933 $this->edebug($exc->getMessage());
3934 if ($this->exceptions) {
3935 throw $exc;
3936 }
3937 return false;
3938 }
3939 return true;
3940 }
3941 /**
3942 * Return the array of attachments.
3943 * @return array
3944 */
3945 public function getAttachments()
3946 {
3947 return $this->attachment;
3948 }
3949 /**
3950 * Attach all file, string, and binary attachments to the message.
3951 * Returns an empty string on failure.
3952 * @access protected
3953 * @param string $disposition_type
3954 * @param string $boundary
3955 * @return string
3956 */
3957 protected function attachAll($disposition_type, $boundary)
3958 {
3959 // Return text of body
3960 $mime = array();
3961 $cidUniq = array();
3962 $incl = array();
3963 // Add all attachments
3964 foreach ($this->attachment as $attachment) {
3965 // Check if it is a valid disposition_filter
3966 if ($attachment[6] == $disposition_type) {
3967 // Check for string attachment
3968 $string = '';
3969 $path = '';
3970 $bString = $attachment[5];
3971 if ($bString) {
3972 $string = $attachment[0];
3973 } else {
3974 $path = $attachment[0];
3975 }
3976 $inclhash = md5(serialize($attachment));
3977 if (in_array($inclhash, $incl)) {
3978 continue;
3979 }
3980 $incl[] = $inclhash;
3981 $name = $attachment[2];
3982 $encoding = $attachment[3];
3983 $type = $attachment[4];
3984 $disposition = $attachment[6];
3985 $cid = $attachment[7];
3986 if ($disposition == 'inline' && array_key_exists($cid, $cidUniq)) {
3987 continue;
3988 }
3989 $cidUniq[$cid] = true;
3990 $mime[] = sprintf('--%s%s', $boundary, $this->LE);
3991 //Only include a filename property if we have one
3992 if (!empty($name)) {
3993 $mime[] = sprintf(
3994 'Content-Type: %s; name="%s"%s',
3995 $type,
3996 $this->encodeHeader($this->secureHeader($name)),
3997 $this->LE
3998 );
3999 } else {
4000 $mime[] = sprintf(
4001 'Content-Type: %s%s',
4002 $type,
4003 $this->LE
4004 );
4005 }
4006 // RFC1341 part 5 says 7bit is assumed if not specified
4007 if ($encoding != '7bit') {
4008 $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
4009 }
4010 if ($disposition == 'inline') {
4011 $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
4012 }
4013 // If a filename contains any of these chars, it should be quoted,
4014 // but not otherwise: RFC2183 & RFC2045 5.1
4015 // Fixes a warning in IETF's msglint MIME checker
4016 // Allow for bypassing the Content-Disposition header totally
4017 if (!(empty($disposition))) {
4018 $encoded_name = $this->encodeHeader($this->secureHeader($name));
4019 if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) {
4020 $mime[] = sprintf(
4021 'Content-Disposition: %s; filename="%s"%s',
4022 $disposition,
4023 $encoded_name,
4024 $this->LE . $this->LE
4025 );
4026 } else {
4027 if (!empty($encoded_name)) {
4028 $mime[] = sprintf(
4029 'Content-Disposition: %s; filename=%s%s',
4030 $disposition,
4031 $encoded_name,
4032 $this->LE . $this->LE
4033 );
4034 } else {
4035 $mime[] = sprintf(
4036 'Content-Disposition: %s%s',
4037 $disposition,
4038 $this->LE . $this->LE
4039 );
4040 }
4041 }
4042 } else {
4043 $mime[] = $this->LE;
4044 }
4045 // Encode as string attachment
4046 if ($bString) {
4047 $mime[] = $this->encodeString($string, $encoding);
4048 if ($this->isError()) {
4049 return '';
4050 }
4051 $mime[] = $this->LE . $this->LE;
4052 } else {
4053 $mime[] = $this->encodeFile($path, $encoding);
4054 if ($this->isError()) {
4055 return '';
4056 }
4057 $mime[] = $this->LE . $this->LE;
4058 }
4059 }
4060 }
4061 $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
4062 return implode('', $mime);
4063 }
4064 /**
4065 * Encode a file attachment in requested format.
4066 * Returns an empty string on failure.
4067 * @param string $path The full path to the file
4068 * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
4069 * @throws phpmailerException
4070 * @access protected
4071 * @return string
4072 */
4073 protected function encodeFile($path, $encoding = 'base64')
4074 {
4075 try {
4076 if (!is_readable($path)) {
4077 throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
4078 }
4079 $magic_quotes = get_magic_quotes_runtime();
4080 if ($magic_quotes) {
4081 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
4082 set_magic_quotes_runtime(false);
4083 } else {
4084 //Doesn't exist in PHP 5.4, but we don't need to check because
4085 //get_magic_quotes_runtime always returns false in 5.4+
4086 //so it will never get here
4087 ini_set('magic_quotes_runtime', false);
4088 }
4089 }
4090 $file_buffer = file_get_contents($path);
4091 $file_buffer = $this->encodeString($file_buffer, $encoding);
4092 if ($magic_quotes) {
4093 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
4094 set_magic_quotes_runtime($magic_quotes);
4095 } else {
4096 ini_set('magic_quotes_runtime', $magic_quotes);
4097 }
4098 }
4099 return $file_buffer;
4100 } catch (Exception $exc) {
4101 $this->setError($exc->getMessage());
4102 return '';
4103 }
4104 }
4105 /**
4106 * Encode a string in requested format.
4107 * Returns an empty string on failure.
4108 * @param string $str The text to encode
4109 * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
4110 * @access public
4111 * @return string
4112 */
4113 public function encodeString($str, $encoding = 'base64')
4114 {
4115 $encoded = '';
4116 switch (strtolower($encoding)) {
4117 case 'base64':
4118 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
4119 break;
4120 case '7bit':
4121 case '8bit':
4122 $encoded = $this->fixEOL($str);
4123 // Make sure it ends with a line break
4124 if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
4125 $encoded .= $this->LE;
4126 }
4127 break;
4128 case 'binary':
4129 $encoded = $str;
4130 break;
4131 case 'quoted-printable':
4132 $encoded = $this->encodeQP($str);
4133 break;
4134 default:
4135 $this->setError($this->lang('encoding') . $encoding);
4136 break;
4137 }
4138 return $encoded;
4139 }
4140 /**
4141 * Encode a header string optimally.
4142 * Picks shortest of Q, B, quoted-printable or none.
4143 * @access public
4144 * @param string $str
4145 * @param string $position
4146 * @return string
4147 */
4148 public function encodeHeader($str, $position = 'text')
4149 {
4150 $matchcount = 0;
4151 switch (strtolower($position)) {
4152 case 'phrase':
4153 if (!preg_match('/[\200-\377]/', $str)) {
4154 // Can't use addslashes as we don't know the value of magic_quotes_sybase
4155 $encoded = addcslashes($str, "\0..\37\177\\\"");
4156 if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
4157 return ($encoded);
4158 } else {
4159 return ("\"$encoded\"");
4160 }
4161 }
4162 $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
4163 break;
4164 /** @noinspection PhpMissingBreakStatementInspection */
4165 case 'comment':
4166 $matchcount = preg_match_all('/[()"]/', $str, $matches);
4167 // Intentional fall-through
4168 case 'text':
4169 default:
4170 $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
4171 break;
4172 }
4173 //There are no chars that need encoding
4174 if ($matchcount == 0) {
4175 return ($str);
4176 }
4177 $maxlen = 75 - 7 - strlen($this->CharSet);
4178 // Try to select the encoding which should produce the shortest output
4179 if ($matchcount > strlen($str) / 3) {
4180 // More than a third of the content will need encoding, so B encoding will be most efficient
4181 $encoding = 'B';
4182 if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) {
4183 // Use a custom function which correctly encodes and wraps long
4184 // multibyte strings without breaking lines within a character
4185 $encoded = $this->base64EncodeWrapMB($str, "\n");
4186 } else {
4187 $encoded = base64_encode($str);
4188 $maxlen -= $maxlen % 4;
4189 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
4190 }
4191 } else {
4192 $encoding = 'Q';
4193 $encoded = $this->encodeQ($str, $position);
4194 $encoded = $this->wrapText($encoded, $maxlen, true);
4195 $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
4196 }
4197 $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
4198 $encoded = trim(str_replace("\n", $this->LE, $encoded));
4199 return $encoded;
4200 }
4201 /**
4202 * Check if a string contains multi-byte characters.
4203 * @access public
4204 * @param string $str multi-byte text to wrap encode
4205 * @return boolean
4206 */
4207 public function hasMultiBytes($str)
4208 {
4209 if (function_exists('mb_strlen')) {
4210 return (strlen($str) > mb_strlen($str, $this->CharSet));
4211 } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
4212 return false;
4213 }
4214 }
4215 /**
4216 * Does a string contain any 8-bit chars (in any charset)?
4217 * @param string $text
4218 * @return boolean
4219 */
4220 public function has8bitChars($text)
4221 {
4222 return (boolean)preg_match('/[\x80-\xFF]/', $text);
4223 }
4224 /**
4225 * Encode and wrap long multibyte strings for mail headers
4226 * without breaking lines within a character.
4227 * Adapted from a function by paravoid
4228 * @link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
4229 * @access public
4230 * @param string $str multi-byte text to wrap encode
4231 * @param string $linebreak string to use as linefeed/end-of-line
4232 * @return string
4233 */
4234 public function base64EncodeWrapMB($str, $linebreak = null)
4235 {
4236 $start = '=?' . $this->CharSet . '?B?';
4237 $end = '?=';
4238 $encoded = '';
4239 if ($linebreak === null) {
4240 $linebreak = $this->LE;
4241 }
4242 $mb_length = mb_strlen($str, $this->CharSet);
4243 // Each line must have length <= 75, including $start and $end
4244 $length = 75 - strlen($start) - strlen($end);
4245 // Average multi-byte ratio
4246 $ratio = $mb_length / strlen($str);
4247 // Base64 has a 4:3 ratio
4248 $avgLength = floor($length * $ratio * .75);
4249 for ($i = 0; $i < $mb_length; $i += $offset) {
4250 $lookBack = 0;
4251 do {
4252 $offset = $avgLength - $lookBack;
4253 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
4254 $chunk = base64_encode($chunk);
4255 $lookBack++;
4256 } while (strlen($chunk) > $length);
4257 $encoded .= $chunk . $linebreak;
4258 }
4259 // Chomp the last linefeed
4260 $encoded = substr($encoded, 0, -strlen($linebreak));
4261 return $encoded;
4262 }
4263 /**
4264 * Encode a string in quoted-printable format.
4265 * According to RFC2045 section 6.7.
4266 * @access public
4267 * @param string $string The text to encode
4268 * @param integer $line_max Number of chars allowed on a line before wrapping
4269 * @return string
4270 * @link http://www.php.net/manual/en/function.quoted-printable-decode.php#89417 Adapted from this comment
4271 */
4272 public function encodeQP($string, $line_max = 76)
4273 {
4274 // Use native function if it's available (>= PHP5.3)
4275 if (function_exists('quoted_printable_encode')) {
4276 return quoted_printable_encode($string);
4277 }
4278 // Fall back to a pure PHP implementation
4279 $string = str_replace(
4280 array('%20', '%0D%0A.', '%0D%0A', '%'),
4281 array(' ', "\r\n=2E", "\r\n", '='),
4282 rawurlencode($string)
4283 );
4284 return preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
4285 }
4286 /**
4287 * Backward compatibility wrapper for an old QP encoding function that was removed.
4288 * @see PHPMailer::encodeQP()
4289 * @access public
4290 * @param string $string
4291 * @param integer $line_max
4292 * @param boolean $space_conv
4293 * @return string
4294 * @deprecated Use encodeQP instead.
4295 */
4296 public function encodeQPphp(
4297 $string,
4298 $line_max = 76,
4299 /** @noinspection PhpUnusedParameterInspection */ $space_conv = false
4300 ) {
4301 return $this->encodeQP($string, $line_max);
4302 }
4303 /**
4304 * Encode a string using Q encoding.
4305 * @link http://tools.ietf.org/html/rfc2047
4306 * @param string $str the text to encode
4307 * @param string $position Where the text is going to be used, see the RFC for what that means
4308 * @access public
4309 * @return string
4310 */
4311 public function encodeQ($str, $position = 'text')
4312 {
4313 // There should not be any EOL in the string
4314 $pattern = '';
4315 $encoded = str_replace(array("\r", "\n"), '', $str);
4316 switch (strtolower($position)) {
4317 case 'phrase':
4318 // RFC 2047 section 5.3
4319 $pattern = '^A-Za-z0-9!*+\/ -';
4320 break;
4321 /** @noinspection PhpMissingBreakStatementInspection */
4322 case 'comment':
4323 // RFC 2047 section 5.2
4324 $pattern = '\(\)"';
4325 // intentional fall-through
4326 // for this reason we build the $pattern without including delimiters and []
4327 case 'text':
4328 default:
4329 // RFC 2047 section 5.1
4330 // Replace every high ascii, control, =, ? and _ characters
4331 $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
4332 break;
4333 }
4334 $matches = array();
4335 if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
4336 // If the string contains an '=', make sure it's the first thing we replace
4337 // so as to avoid double-encoding
4338 $eqkey = array_search('=', $matches[0]);
4339 if (false !== $eqkey) {
4340 unset($matches[0][$eqkey]);
4341 array_unshift($matches[0], '=');
4342 }
4343 foreach (array_unique($matches[0]) as $char) {
4344 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
4345 }
4346 }
4347 // Replace every spaces to _ (more readable than =20)
4348 return str_replace(' ', '_', $encoded);
4349 }
4350 /**
4351 * Add a string or binary attachment (non-filesystem).
4352 * This method can be used to attach ascii or binary data,
4353 * such as a BLOB record from a database.
4354 * @param string $string String attachment data.
4355 * @param string $filename Name of the attachment.
4356 * @param string $encoding File encoding (see $Encoding).
4357 * @param string $type File extension (MIME) type.
4358 * @param string $disposition Disposition to use
4359 * @return void
4360 */
4361 public function addStringAttachment(
4362 $string,
4363 $filename,
4364 $encoding = 'base64',
4365 $type = '',
4366 $disposition = 'attachment'
4367 ) {
4368 // If a MIME type is not specified, try to work it out from the file name
4369 if ($type == '') {
4370 $type = self::filenameToType($filename);
4371 }
4372 // Append to $attachment array
4373 $this->attachment[] = array(
4374 0 => $string,
4375 1 => $filename,
4376 2 => basename($filename),
4377 3 => $encoding,
4378 4 => $type,
4379 5 => true, // isStringAttachment
4380 6 => $disposition,
4381 7 => 0
4382 );
4383 }
4384 /**
4385 * Add an embedded (inline) attachment from a file.
4386 * This can include images, sounds, and just about any other document type.
4387 * These differ from 'regular' attachments in that they are intended to be
4388 * displayed inline with the message, not just attached for download.
4389 * This is used in HTML messages that embed the images
4390 * the HTML refers to using the $cid value.
4391 * @param string $path Path to the attachment.
4392 * @param string $cid Content ID of the attachment; Use this to reference
4393 * the content when using an embedded image in HTML.
4394 * @param string $name Overrides the attachment name.
4395 * @param string $encoding File encoding (see $Encoding).
4396 * @param string $type File MIME type.
4397 * @param string $disposition Disposition to use
4398 * @return boolean True on successfully adding an attachment
4399 */
4400 public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
4401 {
4402 if (!@is_file($path)) {
4403 $this->setError($this->lang('file_access') . $path);
4404 return false;
4405 }
4406 // If a MIME type is not specified, try to work it out from the file name
4407 if ($type == '') {
4408 $type = self::filenameToType($path);
4409 }
4410 $filename = basename($path);
4411 if ($name == '') {
4412 $name = $filename;
4413 }
4414 // Append to $attachment array
4415 $this->attachment[] = array(
4416 0 => $path,
4417 1 => $filename,
4418 2 => $name,
4419 3 => $encoding,
4420 4 => $type,
4421 5 => false, // isStringAttachment
4422 6 => $disposition,
4423 7 => $cid
4424 );
4425 return true;
4426 }
4427 /**
4428 * Add an embedded stringified attachment.
4429 * This can include images, sounds, and just about any other document type.
4430 * Be sure to set the $type to an image type for images:
4431 * JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'.
4432 * @param string $string The attachment binary data.
4433 * @param string $cid Content ID of the attachment; Use this to reference
4434 * the content when using an embedded image in HTML.
4435 * @param string $name
4436 * @param string $encoding File encoding (see $Encoding).
4437 * @param string $type MIME type.
4438 * @param string $disposition Disposition to use
4439 * @return boolean True on successfully adding an attachment
4440 */
4441 public function addStringEmbeddedImage(
4442 $string,
4443 $cid,
4444 $name = '',
4445 $encoding = 'base64',
4446 $type = '',
4447 $disposition = 'inline'
4448 ) {
4449 // If a MIME type is not specified, try to work it out from the name
4450 if ($type == '' and !empty($name)) {
4451 $type = self::filenameToType($name);
4452 }
4453 // Append to $attachment array
4454 $this->attachment[] = array(
4455 0 => $string,
4456 1 => $name,
4457 2 => $name,
4458 3 => $encoding,
4459 4 => $type,
4460 5 => true, // isStringAttachment
4461 6 => $disposition,
4462 7 => $cid
4463 );
4464 return true;
4465 }
4466 /**
4467 * Check if an inline attachment is present.
4468 * @access public
4469 * @return boolean
4470 */
4471 public function inlineImageExists()
4472 {
4473 foreach ($this->attachment as $attachment) {
4474 if ($attachment[6] == 'inline') {
4475 return true;
4476 }
4477 }
4478 return false;
4479 }
4480 /**
4481 * Check if an attachment (non-inline) is present.
4482 * @return boolean
4483 */
4484 public function attachmentExists()
4485 {
4486 foreach ($this->attachment as $attachment) {
4487 if ($attachment[6] == 'attachment') {
4488 return true;
4489 }
4490 }
4491 return false;
4492 }
4493 /**
4494 * Check if this message has an alternative body set.
4495 * @return boolean
4496 */
4497 public function alternativeExists()
4498 {
4499 return !empty($this->AltBody);
4500 }
4501 /**
4502 * Clear queued addresses of given kind.
4503 * @access protected
4504 * @param string $kind 'to', 'cc', or 'bcc'
4505 * @return void
4506 */
4507 public function clearQueuedAddresses($kind)
4508 {
4509 $RecipientsQueue = $this->RecipientsQueue;
4510 foreach ($RecipientsQueue as $address => $params) {
4511 if ($params[0] == $kind) {
4512 unset($this->RecipientsQueue[$address]);
4513 }
4514 }
4515 }
4516 /**
4517 * Clear all To recipients.
4518 * @return void
4519 */
4520 public function clearAddresses()
4521 {
4522 foreach ($this->to as $to) {
4523 unset($this->all_recipients[strtolower($to[0])]);
4524 }
4525 $this->to = array();
4526 $this->clearQueuedAddresses('to');
4527 }
4528 /**
4529 * Clear all CC recipients.
4530 * @return void
4531 */
4532 public function clearCCs()
4533 {
4534 foreach ($this->cc as $cc) {
4535 unset($this->all_recipients[strtolower($cc[0])]);
4536 }
4537 $this->cc = array();
4538 $this->clearQueuedAddresses('cc');
4539 }
4540 /**
4541 * Clear all BCC recipients.
4542 * @return void
4543 */
4544 public function clearBCCs()
4545 {
4546 foreach ($this->bcc as $bcc) {
4547 unset($this->all_recipients[strtolower($bcc[0])]);
4548 }
4549 $this->bcc = array();
4550 $this->clearQueuedAddresses('bcc');
4551 }
4552 /**
4553 * Clear all ReplyTo recipients.
4554 * @return void
4555 */
4556 public function clearReplyTos()
4557 {
4558 $this->ReplyTo = array();
4559 $this->ReplyToQueue = array();
4560 }
4561 /**
4562 * Clear all recipient types.
4563 * @return void
4564 */
4565 public function clearAllRecipients()
4566 {
4567 $this->to = array();
4568 $this->cc = array();
4569 $this->bcc = array();
4570 $this->all_recipients = array();
4571 $this->RecipientsQueue = array();
4572 }
4573 /**
4574 * Clear all filesystem, string, and binary attachments.
4575 * @return void
4576 */
4577 public function clearAttachments()
4578 {
4579 $this->attachment = array();
4580 }
4581 /**
4582 * Clear all custom headers.
4583 * @return void
4584 */
4585 public function clearCustomHeaders()
4586 {
4587 $this->CustomHeader = array();
4588 }
4589 /**
4590 * Add an error message to the error container.
4591 * @access protected
4592 * @param string $msg
4593 * @return void
4594 */
4595 protected function setError($msg)
4596 {
4597 $this->error_count++;
4598 if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
4599 $lasterror = $this->smtp->getError();
4600 if (!empty($lasterror['error'])) {
4601 $msg .= $this->lang('smtp_error') . $lasterror['error'];
4602 if (!empty($lasterror['detail'])) {
4603 $msg .= ' Detail: '. $lasterror['detail'];
4604 }
4605 if (!empty($lasterror['smtp_code'])) {
4606 $msg .= ' SMTP code: ' . $lasterror['smtp_code'];
4607 }
4608 if (!empty($lasterror['smtp_code_ex'])) {
4609 $msg .= ' Additional SMTP info: ' . $lasterror['smtp_code_ex'];
4610 }
4611 }
4612 }
4613 $this->ErrorInfo = $msg;
4614 }
4615 /**
4616 * Return an RFC 822 formatted date.
4617 * @access public
4618 * @return string
4619 * @static
4620 */
4621 public static function rfcDate()
4622 {
4623 // Set the time zone to whatever the default is to avoid 500 errors
4624 // Will default to UTC if it's not set properly in php.ini
4625 date_default_timezone_set(@date_default_timezone_get());
4626 return date('D, j M Y H:i:s O');
4627 }
4628 /**
4629 * Get the server hostname.
4630 * Returns 'localhost.localdomain' if unknown.
4631 * @access protected
4632 * @return string
4633 */
4634 protected function serverHostname()
4635 {
4636 $result = 'localhost.localdomain';
4637 if (!empty($this->Hostname)) {
4638 $result = $this->Hostname;
4639 } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
4640 $result = $_SERVER['SERVER_NAME'];
4641 } elseif (function_exists('gethostname') && gethostname() !== false) {
4642 $result = gethostname();
4643 } elseif (php_uname('n') !== false) {
4644 $result = php_uname('n');
4645 }
4646 return $result;
4647 }
4648 /**
4649 * Get an error message in the current language.
4650 * @access protected
4651 * @param string $key
4652 * @return string
4653 */
4654 protected function lang($key)
4655 {
4656 if (count($this->language) < 1) {
4657 $this->setLanguage('en'); // set the default language
4658 }
4659 if (array_key_exists($key, $this->language)) {
4660 if ($key == 'smtp_connect_failed') {
4661 //Include a link to troubleshooting docs on SMTP connection failure
4662 //this is by far the biggest cause of support questions
4663 //but it's usually not PHPMailer's fault.
4664 return $this->language[$key] . ' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting';
4665 }
4666 return $this->language[$key];
4667 } else {
4668 //Return the key as a fallback
4669 return $key;
4670 }
4671 }
4672 /**
4673 * Check if an error occurred.
4674 * @access public
4675 * @return boolean True if an error did occur.
4676 */
4677 public function isError()
4678 {
4679 return ($this->error_count > 0);
4680 }
4681 /**
4682 * Ensure consistent line endings in a string.
4683 * Changes every end of line from CRLF, CR or LF to $this->LE.
4684 * @access public
4685 * @param string $str String to fixEOL
4686 * @return string
4687 */
4688 public function fixEOL($str)
4689 {
4690 // Normalise to \n
4691 $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
4692 // Now convert LE as needed
4693 if ($this->LE !== "\n") {
4694 $nstr = str_replace("\n", $this->LE, $nstr);
4695 }
4696 return $nstr;
4697 }
4698 /**
4699 * Add a custom header.
4700 * $name value can be overloaded to contain
4701 * both header name and value (name:value)
4702 * @access public
4703 * @param string $name Custom header name
4704 * @param string $value Header value
4705 * @return void
4706 */
4707 public function addCustomHeader($name, $value = null,$overwrite = false)
4708 {
4709 if ($value === null)
4710 {
4711 $header = explode(':', $name, 2);
4712 $name = $header[0];
4713 }
4714 if ($overwrite)
4715 {
4716 $this->CustomHeader[$name] = isset($header) ? $header : array($name, $value);
4717 }
4718 else
4719 {
4720 $this->CustomHeader[] = isset($header) ? $header : array($name, $value);
4721 }
4722 }
4723 /**
4724 * Returns all custom headers.
4725 * @return array
4726 */
4727 public function getCustomHeaders()
4728 {
4729 return array_values($this->CustomHeader);
4730 }
4731 /**
4732 * Create a message body from an HTML string.
4733 * Automatically inlines images and creates a plain-text version by converting the HTML,
4734 * overwriting any existing values in Body and AltBody.
4735 * $basedir is used when handling relative image paths, e.g. <img src="images/a.png">
4736 * will look for an image file in $basedir/images/a.png and convert it to inline.
4737 * If you don't want to apply these transformations to your HTML, just set Body and AltBody yourself.
4738 * @access public
4739 * @param string $message HTML message string
4740 * @param string $basedir base directory for relative paths to images
4741 * @param boolean|callable $advanced Whether to use the internal HTML to text converter
4742 * or your own custom converter @see PHPMailer::html2text()
4743 * @return string $message The transformed message Body
4744 */
4745 public function msgHTML($message, $basedir = '', $advanced = false)
4746 {
4747 preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
4748 if (array_key_exists(2, $images)) {
4749 foreach ($images[2] as $imgindex => $url) {
4750 // Convert data URIs into embedded images
4751 if (preg_match('#^data:(image[^;,]*)(;base64)?,#', $url, $match)) {
4752 $data = substr($url, strpos($url, ','));
4753 if ($match[2]) {
4754 $data = base64_decode($data);
4755 } else {
4756 $data = rawurldecode($data);
4757 }
4758 $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
4759 if ($this->addStringEmbeddedImage($data, $cid, 'embed' . $imgindex, 'base64', $match[1])) {
4760 $message = str_replace(
4761 $images[0][$imgindex],
4762 $images[1][$imgindex] . '="cid:' . $cid . '"',
4763 $message
4764 );
4765 }
4766 } elseif (substr($url, 0, 4) !== 'cid:' && !preg_match('#^[a-z][a-z0-9+.-]*://#i', $url)) {
4767 // Do not change urls for absolute images (thanks to corvuscorax)
4768 // Do not change urls that are already inline images
4769 $filename = basename($url);
4770 $directory = dirname($url);
4771 if ($directory == '.') {
4772 $directory = '';
4773 }
4774 $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
4775 if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
4776 $basedir .= '/';
4777 }
4778 if (strlen($directory) > 1 && substr($directory, -1) != '/') {
4779 $directory .= '/';
4780 }
4781 if ($this->addEmbeddedImage(
4782 $basedir . $directory . $filename,
4783 $cid,
4784 $filename,
4785 'base64',
4786 self::_mime_types((string)self::mb_pathinfo($filename, PATHINFO_EXTENSION))
4787 )
4788 ) {
4789 $message = preg_replace(
4790 '/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui',
4791 $images[1][$imgindex] . '="cid:' . $cid . '"',
4792 $message
4793 );
4794 }
4795 }
4796 }
4797 }
4798 $this->isHTML(true);
4799 // Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
4800 $this->Body = $this->normalizeBreaks($message);
4801 $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
4802 if (!$this->alternativeExists()) {
4803 $this->AltBody = 'To view this email message, open it in a program that understands HTML!' .
4804 self::CRLF . self::CRLF;
4805 }
4806 return $this->Body;
4807 }
4808 /**
4809 * Convert an HTML string into plain text.
4810 * This is used by msgHTML().
4811 * Note - older versions of this function used a bundled advanced converter
4812 * which was been removed for license reasons in #232.
4813 * Example usage:
4814 * <code>
4815 * // Use default conversion
4816 * $plain = $mail->html2text($html);
4817 * // Use your own custom converter
4818 * $plain = $mail->html2text($html, function($html) {
4819 * $converter = new MyHtml2text($html);
4820 * return $converter->get_text();
4821 * });
4822 * </code>
4823 * @param string $html The HTML text to convert
4824 * @param boolean|callable $advanced Any boolean value to use the internal converter,
4825 * or provide your own callable for custom conversion.
4826 * @return string
4827 */
4828 public function html2text($html, $advanced = false)
4829 {
4830 if (is_callable($advanced)) {
4831 return call_user_func($advanced, $html);
4832 }
4833 return html_entity_decode(
4834 trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))),
4835 ENT_QUOTES,
4836 $this->CharSet
4837 );
4838 }
4839 /**
4840 * Get the MIME type for a file extension.
4841 * @param string $ext File extension
4842 * @access public
4843 * @return string MIME type of file.
4844 * @static
4845 */
4846 public static function _mime_types($ext = '')
4847 {
4848 $mimes = array(
4849 'xl' => 'application/excel',
4850 'js' => 'application/javascript',
4851 'hqx' => 'application/mac-binhex40',
4852 'cpt' => 'application/mac-compactpro',
4853 'bin' => 'application/macbinary',
4854 'doc' => 'application/msword',
4855 'word' => 'application/msword',
4856 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
4857 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
4858 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
4859 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
4860 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
4861 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
4862 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
4863 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
4864 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
4865 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
4866 'class' => 'application/octet-stream',
4867 'dll' => 'application/octet-stream',
4868 'dms' => 'application/octet-stream',
4869 'exe' => 'application/octet-stream',
4870 'lha' => 'application/octet-stream',
4871 'lzh' => 'application/octet-stream',
4872 'psd' => 'application/octet-stream',
4873 'sea' => 'application/octet-stream',
4874 'so' => 'application/octet-stream',
4875 'oda' => 'application/oda',
4876 'pdf' => 'application/pdf',
4877 'ai' => 'application/postscript',
4878 'eps' => 'application/postscript',
4879 'ps' => 'application/postscript',
4880 'smi' => 'application/smil',
4881 'smil' => 'application/smil',
4882 'mif' => 'application/vnd.mif',
4883 'xls' => 'application/vnd.ms-excel',
4884 'ppt' => 'application/vnd.ms-powerpoint',
4885 'wbxml' => 'application/vnd.wap.wbxml',
4886 'wmlc' => 'application/vnd.wap.wmlc',
4887 'dcr' => 'application/x-director',
4888 'dir' => 'application/x-director',
4889 'dxr' => 'application/x-director',
4890 'dvi' => 'application/x-dvi',
4891 'gtar' => 'application/x-gtar',
4892 'php3' => 'application/x-httpd-php',
4893 'php4' => 'application/x-httpd-php',
4894 'php' => 'application/x-httpd-php',
4895 'phtml' => 'application/x-httpd-php',
4896 'phps' => 'application/x-httpd-php-source',
4897 'swf' => 'application/x-shockwave-flash',
4898 'sit' => 'application/x-stuffit',
4899 'tar' => 'application/x-tar',
4900 'tgz' => 'application/x-tar',
4901 'xht' => 'application/xhtml+xml',
4902 'xhtml' => 'application/xhtml+xml',
4903 'zip' => 'application/zip',
4904 'mid' => 'audio/midi',
4905 'midi' => 'audio/midi',
4906 'mp2' => 'audio/mpeg',
4907 'mp3' => 'audio/mpeg',
4908 'mpga' => 'audio/mpeg',
4909 'aif' => 'audio/x-aiff',
4910 'aifc' => 'audio/x-aiff',
4911 'aiff' => 'audio/x-aiff',
4912 'ram' => 'audio/x-pn-realaudio',
4913 'rm' => 'audio/x-pn-realaudio',
4914 'rpm' => 'audio/x-pn-realaudio-plugin',
4915 'ra' => 'audio/x-realaudio',
4916 'wav' => 'audio/x-wav',
4917 'bmp' => 'image/bmp',
4918 'gif' => 'image/gif',
4919 'jpeg' => 'image/jpeg',
4920 'jpe' => 'image/jpeg',
4921 'jpg' => 'image/jpeg',
4922 'png' => 'image/png',
4923 'tiff' => 'image/tiff',
4924 'tif' => 'image/tiff',
4925 'eml' => 'message/rfc822',
4926 'css' => 'text/css',
4927 'html' => 'text/html',
4928 'htm' => 'text/html',
4929 'shtml' => 'text/html',
4930 'log' => 'text/plain',
4931 'text' => 'text/plain',
4932 'txt' => 'text/plain',
4933 'rtx' => 'text/richtext',
4934 'rtf' => 'text/rtf',
4935 'vcf' => 'text/vcard',
4936 'vcard' => 'text/vcard',
4937 'xml' => 'text/xml',
4938 'xsl' => 'text/xml',
4939 'mpeg' => 'video/mpeg',
4940 'mpe' => 'video/mpeg',
4941 'mpg' => 'video/mpeg',
4942 'mov' => 'video/quicktime',
4943 'qt' => 'video/quicktime',
4944 'rv' => 'video/vnd.rn-realvideo',
4945 'avi' => 'video/x-msvideo',
4946 'movie' => 'video/x-sgi-movie'
4947 );
4948 if (array_key_exists(strtolower($ext), $mimes)) {
4949 return $mimes[strtolower($ext)];
4950 }
4951 return 'application/octet-stream';
4952 }
4953 /**
4954 * Map a file name to a MIME type.
4955 * Defaults to 'application/octet-stream', i.e.. arbitrary binary data.
4956 * @param string $filename A file name or full path, does not need to exist as a file
4957 * @return string
4958 * @static
4959 */
4960 public static function filenameToType($filename)
4961 {
4962 // In case the path is a URL, strip any query string before getting extension
4963 $qpos = strpos($filename, '?');
4964 if (false !== $qpos) {
4965 $filename = substr($filename, 0, $qpos);
4966 }
4967 $pathinfo = self::mb_pathinfo($filename);
4968 return self::_mime_types($pathinfo['extension']);
4969 }
4970 /**
4971 * Multi-byte-safe pathinfo replacement.
4972 * Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe.
4973 * Works similarly to the one in PHP >= 5.2.0
4974 * @link http://www.php.net/manual/en/function.pathinfo.php#107461
4975 * @param string $path A filename or path, does not need to exist as a file
4976 * @param integer|string $options Either a PATHINFO_* constant,
4977 * or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2
4978 * @return string|array
4979 * @static
4980 */
4981 public static function mb_pathinfo($path, $options = null)
4982 {
4983 $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
4984 $pathinfo = array();
4985 if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
4986 if (array_key_exists(1, $pathinfo)) {
4987 $ret['dirname'] = $pathinfo[1];
4988 }
4989 if (array_key_exists(2, $pathinfo)) {
4990 $ret['basename'] = $pathinfo[2];
4991 }
4992 if (array_key_exists(5, $pathinfo)) {
4993 $ret['extension'] = $pathinfo[5];
4994 }
4995 if (array_key_exists(3, $pathinfo)) {
4996 $ret['filename'] = $pathinfo[3];
4997 }
4998 }
4999 switch ($options) {
5000 case PATHINFO_DIRNAME:
5001 case 'dirname':
5002 return $ret['dirname'];
5003 case PATHINFO_BASENAME:
5004 case 'basename':
5005 return $ret['basename'];
5006 case PATHINFO_EXTENSION:
5007 case 'extension':
5008 return $ret['extension'];
5009 case PATHINFO_FILENAME:
5010 case 'filename':
5011 return $ret['filename'];
5012 default:
5013 return $ret;
5014 }
5015 }
5016 /**
5017 * Set or reset instance properties.
5018 * You should avoid this function - it's more verbose, less efficient, more error-prone and
5019 * harder to debug than setting properties directly.
5020 * Usage Example:
5021 * `$mail->set('SMTPSecure', 'tls');`
5022 * is the same as:
5023 * `$mail->SMTPSecure = 'tls';`
5024 * @access public
5025 * @param string $name The property name to set
5026 * @param mixed $value The value to set the property to
5027 * @return boolean
5028 * @TODO Should this not be using the __set() magic function?
5029 */
5030 public function set($name, $value = '')
5031 {
5032 if (property_exists($this, $name)) {
5033 $this->$name = $value;
5034 return true;
5035 } else {
5036 $this->setError($this->lang('variable_set') . $name);
5037 return false;
5038 }
5039 }
5040 /**
5041 * Strip newlines to prevent header injection.
5042 * @access public
5043 * @param string $str
5044 * @return string
5045 */
5046 public function secureHeader($str)
5047 {
5048 return trim(str_replace(array("\r", "\n"), '', $str));
5049 }
5050 /**
5051 * Normalize line breaks in a string.
5052 * Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format.
5053 * Defaults to CRLF (for message bodies) and preserves consecutive breaks.
5054 * @param string $text
5055 * @param string $breaktype What kind of line break to use, defaults to CRLF
5056 * @return string
5057 * @access public
5058 * @static
5059 */
5060 public static function normalizeBreaks($text, $breaktype = "\r\n")
5061 {
5062 return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
5063 }
5064 /**
5065 * Set the public and private key files and password for S/MIME signing.
5066 * @access public
5067 * @param string $cert_filename
5068 * @param string $key_filename
5069 * @param string $key_pass Password for private key
5070 * @param string $extracerts_filename Optional path to chain certificate
5071 */
5072 public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename = '')
5073 {
5074 $this->sign_cert_file = $cert_filename;
5075 $this->sign_key_file = $key_filename;
5076 $this->sign_key_pass = $key_pass;
5077 $this->sign_extracerts_file = $extracerts_filename;
5078 }
5079 /**
5080 * Quoted-Printable-encode a DKIM header.
5081 * @access public
5082 * @param string $txt
5083 * @return string
5084 */
5085 public function DKIM_QP($txt)
5086 {
5087 $line = '';
5088 for ($i = 0; $i < strlen($txt); $i++) {
5089 $ord = ord($txt[$i]);
5090 if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
5091 $line .= $txt[$i];
5092 } else {
5093 $line .= '=' . sprintf('%02X', $ord);
5094 }
5095 }
5096 return $line;
5097 }
5098 /**
5099 * Generate a DKIM signature.
5100 * @access public
5101 * @param string $signHeader
5102 * @throws phpmailerException
5103 * @return string The DKIM signature value
5104 */
5105 public function DKIM_Sign($signHeader)
5106 {
5107 if (!defined('PKCS7_TEXT')) {
5108 if ($this->exceptions) {
5109 throw new phpmailerException($this->lang('extension_missing') . 'openssl');
5110 }
5111 return '';
5112 }
5113 $privKeyStr = !empty($this->DKIM_private_string) ? $this->DKIM_private_string : file_get_contents($this->DKIM_private);
5114 if ('' != $this->DKIM_passphrase) {
5115 $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
5116 } else {
5117 $privKey = openssl_pkey_get_private($privKeyStr);
5118 }
5119 //Workaround for missing digest algorithms in old PHP & OpenSSL versions
5120 //@link http://stackoverflow.com/a/11117338/333340
5121 if (version_compare(PHP_VERSION, '5.3.0') >= 0 and
5122 in_array('sha256WithRSAEncryption', openssl_get_md_methods(true))) {
5123 if (openssl_sign($signHeader, $signature, $privKey, 'sha256WithRSAEncryption')) {
5124 openssl_pkey_free($privKey);
5125 return base64_encode($signature);
5126 }
5127 } else {
5128 $pinfo = openssl_pkey_get_details($privKey);
5129 $hash = hash('sha256', $signHeader);
5130 //'Magic' constant for SHA256 from RFC3447
5131 //@link https://tools.ietf.org/html/rfc3447#page-43
5132 $t = '3031300d060960864801650304020105000420' . $hash;
5133 $pslen = $pinfo['bits'] / 8 - (strlen($t) / 2 + 3);
5134 $eb = pack('H*', '0001' . str_repeat('FF', $pslen) . '00' . $t);
5135 if (openssl_private_encrypt($eb, $signature, $privKey, OPENSSL_NO_PADDING)) {
5136 openssl_pkey_free($privKey);
5137 return base64_encode($signature);
5138 }
5139 }
5140 openssl_pkey_free($privKey);
5141 return '';
5142 }
5143 /**
5144 * Generate a DKIM canonicalization header.
5145 * @access public
5146 * @param string $signHeader Header
5147 * @return string
5148 */
5149 public function DKIM_HeaderC($signHeader)
5150 {
5151 $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
5152 $lines = explode("\r\n", $signHeader);
5153 foreach ($lines as $key => $line) {
5154 list($heading, $value) = explode(':', $line, 2);
5155 $heading = strtolower($heading);
5156 $value = preg_replace('/\s{2,}/', ' ', $value); // Compress useless spaces
5157 $lines[$key] = $heading . ':' . trim($value); // Don't forget to remove WSP around the value
5158 }
5159 $signHeader = implode("\r\n", $lines);
5160 return $signHeader;
5161 }
5162 /**
5163 * Generate a DKIM canonicalization body.
5164 * @access public
5165 * @param string $body Message Body
5166 * @return string
5167 */
5168 public function DKIM_BodyC($body)
5169 {
5170 if ($body == '') {
5171 return "\r\n";
5172 }
5173 // stabilize line endings
5174 $body = str_replace("\r\n", "\n", $body);
5175 $body = str_replace("\n", "\r\n", $body);
5176 // END stabilize line endings
5177 while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
5178 $body = substr($body, 0, strlen($body) - 2);
5179 }
5180 return $body;
5181 }
5182 /**
5183 * Create the DKIM header and body in a new message header.
5184 * @access public
5185 * @param string $headers_line Header lines
5186 * @param string $subject Subject
5187 * @param string $body Body
5188 * @return string
5189 */
5190 public function DKIM_Add($headers_line, $subject, $body)
5191 {
5192 $DKIMsignatureType = 'rsa-sha256'; // Signature & hash algorithms
5193 $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
5194 $DKIMquery = 'dns/txt'; // Query method
5195 $DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
5196 $subject_header = "Subject: $subject";
5197 $headers = explode($this->LE, $headers_line);
5198 $from_header = '';
5199 $to_header = '';
5200 $date_header = '';
5201 $current = '';
5202 foreach ($headers as $header) {
5203 if (strpos($header, 'From:') === 0) {
5204 $from_header = $header;
5205 $current = 'from_header';
5206 } elseif (strpos($header, 'To:') === 0) {
5207 $to_header = $header;
5208 $current = 'to_header';
5209 } elseif (strpos($header, 'Date:') === 0) {
5210 $date_header = $header;
5211 $current = 'date_header';
5212 } else {
5213 if (!empty($$current) && strpos($header, ' =?') === 0) {
5214 $$current .= $header;
5215 } else {
5216 $current = '';
5217 }
5218 }
5219 }
5220 $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
5221 $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
5222 $date = str_replace('|', '=7C', $this->DKIM_QP($date_header));
5223 $subject = str_replace(
5224 '|',
5225 '=7C',
5226 $this->DKIM_QP($subject_header)
5227 ); // Copied header fields (dkim-quoted-printable)
5228 $body = $this->DKIM_BodyC($body);
5229 $DKIMlen = strlen($body); // Length of body
5230 $DKIMb64 = base64_encode(pack('H*', hash('sha256', $body))); // Base64 of packed binary SHA-256 hash of body
5231 if ('' == $this->DKIM_identity) {
5232 $ident = '';
5233 } else {
5234 $ident = ' i=' . $this->DKIM_identity . ';';
5235 }
5236 $dkimhdrs = 'DKIM-Signature: v=1; a=' .
5237 $DKIMsignatureType . '; q=' .
5238 $DKIMquery . '; l=' .
5239 $DKIMlen . '; s=' .
5240 $this->DKIM_selector .
5241 ";\r\n" .
5242 "\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" .
5243 "\th=From:To:Date:Subject;\r\n" .
5244 "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" .
5245 "\tz=$from\r\n" .
5246 "\t|$to\r\n" .
5247 "\t|$date\r\n" .
5248 "\t|$subject;\r\n" .
5249 "\tbh=" . $DKIMb64 . ";\r\n" .
5250 "\tb=";
5251 $toSign = $this->DKIM_HeaderC(
5252 $from_header . "\r\n" .
5253 $to_header . "\r\n" .
5254 $date_header . "\r\n" .
5255 $subject_header . "\r\n" .
5256 $dkimhdrs
5257 );
5258 $signed = $this->DKIM_Sign($toSign);
5259 return $dkimhdrs . $signed . "\r\n";
5260 }
5261 /**
5262 * Detect if a string contains a line longer than the maximum line length allowed.
5263 * @param string $str
5264 * @return boolean
5265 * @static
5266 */
5267 public static function hasLineLongerThanMax($str)
5268 {
5269 //+2 to include CRLF line break for a 1000 total
5270 return (boolean)preg_match('/^(.{'.(self::MAX_LINE_LENGTH + 2).',})/m', $str);
5271 }
5272 /**
5273 * Allows for public read access to 'to' property.
5274 * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
5275 * @access public
5276 * @return array
5277 */
5278 public function getToAddresses()
5279 {
5280 return $this->to;
5281 }
5282 /**
5283 * Allows for public read access to 'cc' property.
5284 * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
5285 * @access public
5286 * @return array
5287 */
5288 public function getCcAddresses()
5289 {
5290 return $this->cc;
5291 }
5292 /**
5293 * Allows for public read access to 'bcc' property.
5294 * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
5295 * @access public
5296 * @return array
5297 */
5298 public function getBccAddresses()
5299 {
5300 return $this->bcc;
5301 }
5302 /**
5303 * Allows for public read access to 'ReplyTo' property.
5304 * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
5305 * @access public
5306 * @return array
5307 */
5308 public function getReplyToAddresses()
5309 {
5310 return $this->ReplyTo;
5311 }
5312 /**
5313 * Allows for public read access to 'all_recipients' property.
5314 * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
5315 * @access public
5316 * @return array
5317 */
5318 public function getAllRecipientAddresses()
5319 {
5320 return $this->all_recipients;
5321 }
5322 /**
5323 * Perform a callback.
5324 * @param boolean $isSent
5325 * @param array $to
5326 * @param array $cc
5327 * @param array $bcc
5328 * @param string $subject
5329 * @param string $body
5330 * @param string $from
5331 */
5332 protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
5333 {
5334 if (!empty($this->action_function) && is_callable($this->action_function)) {
5335 $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
5336 call_user_func_array($this->action_function, $params);
5337 }
5338 }
5339}
5340/**
5341 * PHPMailer exception handler
5342 * @package PHPMailer
5343 */
5344class phpmailerException extends Exception
5345{
5346 /**
5347 * Prettify error message output
5348 * @return string
5349 */
5350 public function errorMessage()
5351 {
5352 $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
5353 return $errorMsg;
5354 }
5355}
5356
5357
5358$mail = new PHPMailer();
5359
5360
5361 function LoadFeeds($letter){
5362
5363 $url = array(
5364 /* Auto Blog */
5365 'https://www.autoblog.com/category/aftermarket/rss.xml',
5366 'https://www.autoblog.com/category/by-the-numbers/rss.xml',
5367 'https://www.autoblog.com/category/celebrities/rss.xml',
5368 'https://www.autoblog.com/category/design-style/rss.xml',
5369 'https://www.autoblog.com/category/earnings-financials/rss.xml',
5370 'https://www.autoblog.com/category/etc/rss.xml',
5371 'https://www.autoblog.com/category/government-legal/rss.xml',
5372 'https://www.autoblog.com/category/green-auto-news/rss.xml',
5373 'https://www.autoblog.com/category/hirings-firings-layoffs/rss.xml',
5374 'https://www.autoblog.com/category/humor/rss.xml',
5375 'https://www.autoblog.com/category/marketing-advertising/rss.xml',
5376 'https://www.autoblog.com/category/motorsports/rss.xml',
5377 'https://www.autoblog.com/category/plants-manufacturing/rss.xml',
5378 'https://www.autoblog.com/category/podcasts/rss.xml',
5379 'https://www.autoblog.com/category/read-this/rss.xml',
5380 'https://www.autoblog.com/category/recalls/rss.xml',
5381 'https://www.autoblog.com/category/rumormill/rss.xml',
5382 'https://www.autoblog.com/category/spy-photos/rss.xml',
5383 'https://www.autoblog.com/category/toys-games/rss.xml',
5384 'https://www.autoblog.com/category/tv-movies/rss.xml',
5385 'https://www.autoblog.com/category/uaw-unions/rss.xml',
5386 'https://www.autoblog.com/category/weird-car-news/rss.xml',
5387 'https://www.autoblog.com/category/shanghai-motor-show/rss.xml',
5388 'https://www.autoblog.com/category/beijing-motor-show/rss.xml',
5389 'https://www.autoblog.com/category/ces/rss.xml',
5390 'https://www.autoblog.com/category/chicago-auto-show/rss.xml',
5391 'https://www.autoblog.com/category/detroit-auto-show/rss.xml',
5392 'https://www.autoblog.com/category/frankfurt-auto-show/rss.xml',
5393 'https://www.autoblog.com/category/geneva-motor-show/rss.xml',
5394 'https://www.autoblog.com/category/la-auto-show/rss.xml',
5395 'https://www.autoblog.com/category/misc-auto-shows/rss.xml',
5396 'https://www.autoblog.com/category/montreal-auto-show/rss.xml',
5397 'https://www.autoblog.com/category/new-york-auto-show/rss.xml',
5398 'https://www.autoblog.com/category/paris-motor-show/rss.xml',
5399 'https://www.autoblog.com/category/sema-show/rss.xml',
5400 'https://www.autoblog.com/category/tokyo-auto-salon/rss.xml',
5401 'https://www.autoblog.com/category/tokyo-motor-show/rss.xml',
5402 'https://www.autoblog.com/category/upshift/rss.xml',
5403 'https://www.autoblog.com/category/acura/rss.xml',
5404 'https://www.autoblog.com/category/land-rover/rss.xml',
5405 'https://www.autoblog.com/category/alfa-romeo/rss.xml',
5406 'https://www.autoblog.com/category/lexus/rss.xml',
5407 'https://www.autoblog.com/category/aston-martin/rss.xml',
5408 'https://www.autoblog.com/category/lincoln/rss.xml',
5409 'https://www.autoblog.com/category/audi/rss.xml',
5410 'https://www.autoblog.com/category/lotus/rss.xml',
5411 'https://www.autoblog.com/category/bentley/rss.xml',
5412 'https://www.autoblog.com/category/maserati/rss.xml',
5413 'https://www.autoblog.com/category/bmw/rss.xml',
5414 'https://www.autoblog.com/category/maybach/rss.xml',
5415 'https://www.autoblog.com/category/bugatti/rss.xml',
5416 'https://www.autoblog.com/category/mazda/rss.xml',
5417 'https://www.autoblog.com/category/buick/rss.xml',
5418 'https://www.autoblog.com/category/mclaren/rss.xml',
5419 'https://www.autoblog.com/category/cadillac/rss.xml',
5420 'https://www.autoblog.com/category/mercedes-benz/rss.xml',
5421 'https://www.autoblog.com/category/chevrolet/rss.xml',
5422 'https://www.autoblog.com/category/mercury/rss.xml',
5423 'https://www.autoblog.com/category/chrysler/rss.xml',
5424 'https://www.autoblog.com/category/mini/rss.xml',
5425 'https://www.autoblog.com/category/coda/rss.xml',
5426 'https://www.autoblog.com/category/misc-automakers/rss.xml',
5427 'https://www.autoblog.com/category/dodge/rss.xml',
5428 'https://www.autoblog.com/category/mitsubishi/rss.xml',
5429 'https://www.autoblog.com/category/ferrari/rss.xml',
5430 'https://www.autoblog.com/category/nissan/rss.xml',
5431 'https://www.autoblog.com/category/fiat/rss.xml',
5432 'https://www.autoblog.com/category/pontiac/rss.xml',
5433 'https://www.autoblog.com/category/fisker/rss.xml',
5434 'https://www.autoblog.com/category/porsche/rss.xml',
5435 'https://www.autoblog.com/category/ford/rss.xml',
5436 'https://www.autoblog.com/category/ram/rss.xml',
5437 'https://www.autoblog.com/category/genesis/rss.xml',
5438 'https://www.autoblog.com/category/rolls-royce/rss.xml',
5439 'https://www.autoblog.com/category/gm/rss.xml',
5440 'https://www.autoblog.com/category/saturn/rss.xml',
5441 'https://www.autoblog.com/category/gmc/rss.xml',
5442 'https://www.autoblog.com/category/scion/rss.xml',
5443 'https://www.autoblog.com/category/honda/rss.xml',
5444 'https://www.autoblog.com/category/smart/rss.xml',
5445 'https://www.autoblog.com/category/hummer/rss.xml',
5446 'https://www.autoblog.com/category/spyker/rss.xml',
5447 'https://www.autoblog.com/category/hyundai/rss.xml',
5448 'https://www.autoblog.com/category/subaru/rss.xml',
5449 'https://www.autoblog.com/category/infiniti/rss.xml',
5450 'https://www.autoblog.com/category/suzuki/rss.xml',
5451 'https://www.autoblog.com/category/isuzu/rss.xml',
5452 'https://www.autoblog.com/category/tesla/rss.xml',
5453 'https://www.autoblog.com/category/jaguar/rss.xml',
5454 'https://www.autoblog.com/category/toyota/rss.xml',
5455 'https://www.autoblog.com/category/jeep/rss.xml',
5456 'https://www.autoblog.com/category/volkswagen/rss.xml',
5457 'https://www.autoblog.com/category/kia/rss.xml',
5458 'https://www.autoblog.com/category/volvo/rss.xml',
5459 'https://www.autoblog.com/category/lamborghini/rss.xml',
5460 'https://www.autoblog.com/category/auction-action/rss.xml',
5461 'https://www.autoblog.com/category/buying-guide/rss.xml',
5462 'https://www.autoblog.com/category/carbuying/rss.xml',
5463 'https://www.autoblog.com/category/used-car-buying-guide/rss.xml',
5464 'https://www.autoblog.com/category/comparison/rss.xml',
5465 'https://www.autoblog.com/category/citroen/rss.xml',
5466 'https://www.autoblog.com/category/daewoo/rss.xml',
5467 'https://www.autoblog.com/category/daihatsu/rss.xml',
5468 'https://www.autoblog.com/category/holden/rss.xml',
5469 'https://www.autoblog.com/category/koenigsegg/rss.xml',
5470 'https://www.autoblog.com/category/lancia/rss.xml',
5471 'https://www.autoblog.com/category/opel/rss.xml',
5472 'https://www.autoblog.com/category/pagani/rss.xml',
5473 'https://www.autoblog.com/category/peugeot/rss.xml',
5474 'https://www.autoblog.com/category/renault/rss.xml',
5475 'https://www.autoblog.com/category/saab/rss.xml',
5476 'https://www.autoblog.com/category/seat/rss.xml',
5477 'https://www.autoblog.com/category/skoda/rss.xml',
5478 'https://www.autoblog.com/category/tata/rss.xml',
5479 'https://www.autoblog.com/category/vauxhall/rss.xml',
5480 'https://www.autoblog.com/category/alternative-fuels/rss.xml',
5481 'https://www.autoblog.com/category/autobloggreen-exclusive/rss.xml',
5482 'https://www.autoblog.com/category/biodiesel/rss.xml',
5483 'https://www.autoblog.com/category/emissions/rss.xml',
5484 'https://www.autoblog.com/category/ethanol/rss.xml',
5485 'https://www.autoblog.com/category/fuel-efficiency/rss.xml',
5486 'https://www.autoblog.com/category/green-automakers/rss.xml',
5487 'https://www.autoblog.com/category/green-culture/rss.xml',
5488 'https://www.autoblog.com/category/green-daily/rss.xml',
5489 'https://www.autoblog.com/category/green-driving/rss.xml',
5490 'https://www.autoblog.com/category/nev-neighborhood-electric-vehicle/rss.xml',
5491 'https://www.autoblog.com/category/transportation-alternatives/rss.xml',
5492 'https://www.autoblog.com/category/affiliate-posts/rss.xml',
5493 'https://www.autoblog.com/category/automotive-history/rss.xml',
5494 'https://www.autoblog.com/category/car-repair-questions-and-answers/rss.xml',
5495 'https://www.autoblog.com/category/driving/rss.xml',
5496 'https://www.autoblog.com/category/gas-prices/rss.xml',
5497 'https://www.autoblog.com/category/car-insurance/rss.xml',
5498 'https://www.autoblog.com/category/maintenance/rss.xml',
5499 'https://www.autoblog.com/category/ownership/rss.xml',
5500 'https://www.autoblog.com/category/parts-and-accessories/rss.xml',
5501 'https://www.autoblog.com/category/safety/rss.xml',
5502 'https://www.autoblog.com/category/best-cars/rss.xml',
5503 'https://www.autoblog.com/category/deep-dive/rss.xml',
5504 'https://www.autoblog.com/category/first-drives/rss.xml',
5505 'https://www.autoblog.com/category/first-ride/rss.xml',
5506 'https://www.autoblog.com/category/long-term-garage/rss.xml',
5507 'https://www.autoblog.com/category/reviews-1/rss.xml',
5508 'https://www.autoblog.com/category/quick-spin/rss.xml',
5509 'https://www.autoblog.com/category/autoblog-black/rss.xml',
5510 'https://www.autoblog.com/category/openroad/rss.xml',
5511 'https://www.autoblog.com/category/diy/rss.xml',
5512 'https://www.autoblog.com/category/emerging-technologies/rss.xml',
5513 'https://www.autoblog.com/category/gadgets/rss.xml',
5514 'https://www.autoblog.com/category/infotainment/rss.xml',
5515 'https://www.autoblog.com/category/smartphone/rss.xml',
5516 'https://www.autoblog.com/category/tech/rss.xml',
5517 'https://www.autoblog.com/category/technology-of-the-year/rss.xml',
5518 'https://www.autoblog.com/category/convertibles/rss.xml',
5519 'https://www.autoblog.com/category/coupes/rss.xml',
5520 'https://www.autoblog.com/category/crossovers/rss.xml',
5521 'https://www.autoblog.com/category/hatchbacks/rss.xml',
5522 'https://www.autoblog.com/category/minivans/rss.xml',
5523 'https://www.autoblog.com/category/motorcycles/rss.xml',
5524 'https://www.autoblog.com/category/sedan/rss.xml',
5525 'https://www.autoblog.com/category/suvs/rss.xml',
5526 'https://www.autoblog.com/category/trucks/rss.xml',
5527 'https://www.autoblog.com/category/wagons/rss.xml',
5528 'https://www.autoblog.com/category/autonomous/rss.xml',
5529 'https://www.autoblog.com/category/bikes/rss.xml',
5530 'https://www.autoblog.com/category/economy/rss.xml',
5531 'https://www.autoblog.com/category/timewarp/rss.xml',
5532 'https://www.autoblog.com/category/commercial-trucks/rss.xml',
5533 'https://www.autoblog.com/category/conceptcars/rss.xml',
5534 'https://www.autoblog.com/category/diesel/rss.xml',
5535 'https://www.autoblog.com/category/electric/rss.xml',
5536 'https://www.autoblog.com/category/future/rss.xml',
5537 'https://www.autoblog.com/category/hybrids/rss.xml',
5538 'https://www.autoblog.com/category/hydrogen/rss.xml',
5539 'https://www.autoblog.com/category/lightweight/rss.xml',
5540 'https://www.autoblog.com/category/luxury/rss.xml',
5541 'https://www.autoblog.com/category/military/rss.xml',
5542 'https://www.autoblog.com/category/natural-gas/rss.xml',
5543 'https://www.autoblog.com/category/off-road/rss.xml',
5544 'https://www.autoblog.com/category/sports/rss.xml',
5545 'https://www.autoblog.com/category/police-emergency/rss.xml',
5546 'https://www.autoblog.com/category/racing/rss.xml',
5547 'https://www.autoblog.com/category/solar/rss.xml',
5548 'https://www.autoblog.com/category/special-limited-editions/rss.xml',
5549 'https://www.autoblog.com/category/supercars/rss.xml',
5550 'https://www.autoblog.com/category/autoblog-details/rss.xml',
5551 'https://www.autoblog.com/category/autoblog-minute/rss.xml',
5552 'https://www.autoblog.com/category/autoblog-wrenched/rss.xml',
5553 'https://www.autoblog.com/category/beauty-roll/rss.xml',
5554 'https://www.autoblog.com/category/car-club-usa/rss.xml',
5555 'https://www.autoblog.com/category/carboom/rss.xml',
5556 'https://www.autoblog.com/category/original-video/rss.xml',
5557 'https://www.autoblog.com/category/stars-selling-cars/rss.xml',
5558 'https://www.autoblog.com/category/super-bowl-commercials/rss.xml',
5559 'https://www.autoblog.com/category/the-list/rss.xml',
5560 'https://www.autoblog.com/category/translogic/rss.xml',
5561 'https://www.autoblog.com/category/videos/rss.xml',
5562 'https://www.autoblog.com/category/vr/rss.xml',
5563
5564 /* The Seattle Times */
5565 'https://www.seattletimes.com/seattle-news/feed/',
5566 'https://www.seattletimes.com/crime/feed/',
5567 'https://www.seattletimes.com/data/feed/',
5568 'https://www.seattletimes.com/education/feed/',
5569 'https://www.seattletimes.com/education-lab/feed/',
5570 'https://www.seattletimes.com/eastside/feed/',
5571 'https://www.seattletimes.com/health/feed/',
5572 'https://www.seattletimes.com/marijuana/feed/',
5573 'https://www.seattletimes.com/northwest/feed/',
5574 'https://www.seattletimes.com/obituaries/feed/',
5575 'https://www.seattletimes.com/politics/feed/',
5576 'https://www.seattletimes.com/puget-sound/feed/',
5577 'https://www.seattletimes.com/science/feed/',
5578 'https://www.seattletimes.com/special-reports/feed/',
5579 'https://www.seattletimes.com/transportation/feed/',
5580 'https://www.seattletimes.com/weather/feed/',
5581 'https://www.seattletimes.com/author/ron-judd/feed/',
5582 'https://www.seattletimes.com/author/danny-westneat/feed/',
5583 'https://www.seattletimes.com/nation-world/feed/',
5584 'https://www.seattletimes.com/nation/feed/',
5585 'https://www.seattletimes.com/world/feed/',
5586 'https://www.seattletimes.com/oddities/feed/',
5587 'https://www.seattletimes.com/opinion/feed/',
5588 'https://www.seattletimes.com/business/feed/',
5589 'https://www.seattletimes.com/agriculture/feed/',
5590 'https://www.seattletimes.com/amazon/feed/',
5591 'https://www.seattletimes.com/boeing-aerospace/feed/',
5592 'https://www.seattletimes.com/economy/feed/',
5593 'https://www.seattletimes.com/local-business/feed/',
5594 'https://www.seattletimes.com/markets/feed/',
5595 'https://www.seattletimes.com/microsoft/feed/',
5596 'https://www.seattletimes.com/technology/feed/',
5597 'https://www.seattletimes.com/real-estate/feed/',
5598 'https://www.seattletimes.com/retail/feed/',
5599 'https://www.seattletimes.com/starbucks/feed/',
5600 'https://www.seattletimes.com/author/jon-talton/feed/',
5601 'https://www.seattletimes.com/sports/feed/',
5602 'https://www.seattletimes.com/auto-racing/feed/',
5603 'https://www.seattletimes.com/college/feed/',
5604 'https://www.seattletimes.com/wsu-cougars/feed/',
5605 'https://www.seattletimes.com/wsu-cougar-basketball/feed/',
5606 'https://www.seattletimes.com/wsu-cougar-football/feed/',
5607 'https://www.seattletimes.com/golf/feed/',
5608 'https://www.seattletimes.com/gonzaga-bulldogs/feed/',
5609 'https://www.seattletimes.com/high-school/feed/',
5610 'https://www.seattletimes.com/hockey/feed/',
5611 'https://www.seattletimes.com/horse-racing/feed/',
5612 'https://www.seattletimes.com/uw-huskies/feed/',
5613 'https://www.seattletimes.com/uw-husky-basketball/feed/',
5614 'https://www.seattletimes.com/uw-husky-football/feed/',
5615 'https://www.seattletimes.com/mariners/feed/',
5616 'https://www.seattletimes.com/nba/feed/',
5617 'https://www.seattletimes.com/ncaa-tournament/feed/',
5618 'https://www.seattletimes.com/feed/',
5619 'https://www.seattletimes.com/pac-12/feed/',
5620 'https://www.seattletimes.com/reign/feed/',
5621 'https://www.seattletimes.com/seahawks/feed/',
5622 'https://www.seattletimes.com/seattle-university/feed/',
5623 'https://www.seattletimes.com/snow-sports/feed/',
5624 'https://www.seattletimes.com/sounders/feed/',
5625 'https://www.seattletimes.com/storm/feed/',
5626 'https://www.seattletimes.com/world-cup/feed/',
5627 'https://www.seattletimes.com/author/bob-condotta/feed/',
5628 'https://www.seattletimes.com/author/ryan-divish/feed/',
5629 'https://www.seattletimes.com/author/larry-stone/feed/',
5630 'https://www.seattletimes.com/entertainment/feed/',
5631 'https://www.seattletimes.com/books/feed/',
5632 'https://www.seattletimes.com/classical-music/feed/',
5633 'https://www.seattletimes.com/events/feed/',
5634 'https://www.seattletimes.com/dance/feed/',
5635 'https://www.seattletimes.com/movies/feed/',
5636 'https://www.seattletimes.com/music/feed/',
5637 'https://www.seattletimes.com/entertainment/feed/',
5638 'https://www.seattletimes.com/tv/feed/',
5639 'https://www.seattletimes.com/tv/feed/',
5640 'https://www.seattletimes.com/video-games/feed/',
5641 'https://www.seattletimes.com/visual-arts/feed/',
5642 'https://www.seattletimes.com/life/feed/',
5643 'https://www.seattletimes.com/fashion/feed/',
5644 'https://www.seattletimes.com/fitness/feed/',
5645 'https://www.seattletimes.com/food-drink/feed/',
5646 'https://www.seattletimes.com/garden/feed/',
5647 'https://www.seattletimes.com/home-decor/feed/',
5648 'https://www.seattletimes.com/lifestyle/feed/',
5649 'https://www.seattletimes.com/outdoors/feed/',
5650 'https://www.seattletimes.com/pacific-nw-magazine/feed/',
5651 'https://www.seattletimes.com/life/feed/',
5652 'https://www.seattletimes.com/wellness/feed/',
5653 'https://www.seattletimes.com/opinion/feed/',
5654 'https://www.seattletimes.com/letters-to-the-editor/feed/',
5655 'https://www.seattletimes.com/author/kate-riley/feed/',
5656 'https://www.seattletimes.com/author/mark-higgins/feed/',
5657 'https://www.seattletimes.com/author/jonathan-martin/feed/',
5658 'https://www.seattletimes.com/author/thanh-tan/feed/',
5659 'https://www.seattletimes.com/photography/feed/',
5660 'https://www.seattletimes.com/photo-video/video/feed/',
5661
5662 /* The New York Times */
5663 'https://rss.nytimes.com/services/xml/rss/nyt/Africa.xml',
5664 'https://rss.nytimes.com/services/xml/rss/nyt/Americas.xml',
5665 'https://rss.nytimes.com/services/xml/rss/nyt/ArtandDesign.xml',
5666 'https://rss.nytimes.com/services/xml/rss/nyt/Arts.xml',
5667 'https://rss.nytimes.com/services/xml/rss/nyt/AsiaPacific.xml',
5668 'https://rss.nytimes.com/services/xml/rss/nyt/Automobiles.xml',
5669 'https://rss.nytimes.com/services/xml/rss/nyt/Baseball.xml',
5670 'https://rss.nytimes.com/services/xml/rss/nyt/Books.xml',
5671 'https://rss.nytimes.com/services/xml/rss/nyt/Business.xml',
5672 'https://rss.nytimes.com/services/xml/rss/nyt/Climate.xml',
5673 'https://rss.nytimes.com/services/xml/rss/nyt/CollegeBasketball.xml',
5674 'https://rss.nytimes.com/services/xml/rss/nyt/Dance.xml',
5675 'https://rss.nytimes.com/services/xml/rss/nyt/Dealbook.xml',
5676 'https://rss.nytimes.com/services/xml/rss/nyt/DiningandWine.xml',
5677 'https://rss.nytimes.com/services/xml/rss/nyt/Economy.xml',
5678 'https://rss.nytimes.com/services/xml/rss/nyt/Education.xml',
5679 'https://rss.nytimes.com/services/xml/rss/nyt/EnergyEnvironment.xml',
5680 'https://rss.nytimes.com/services/xml/rss/nyt/Europe.xml',
5681 'https://rss.nytimes.com/services/xml/rss/nyt/FashionandStyle.xml',
5682 'https://rss.nytimes.com/services/xml/rss/nyt/Golf.xml',
5683 'https://rss.nytimes.com/services/xml/rss/nyt/Health.xml',
5684 'https://rss.nytimes.com/services/xml/rss/nyt/Hockey.xml',
5685 'https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml',
5686 'https://rss.nytimes.com/services/xml/rss/nyt/Jobs.xml',
5687 'https://rss.nytimes.com/services/xml/rss/nyt/Lens.xml',
5688 'https://rss.nytimes.com/services/xml/rss/nyt/MediaandAdvertising.xml',
5689 'https://rss.nytimes.com/services/xml/rss/nyt/MiddleEast.xml',
5690 'https://rss.nytimes.com/services/xml/rss/nyt/MostEmailed.xml',
5691 'https://rss.nytimes.com/services/xml/rss/nyt/MostShared.xml',
5692 'https://rss.nytimes.com/services/xml/rss/nyt/MostViewed.xml',
5693 'https://rss.nytimes.com/services/xml/rss/nyt/Movies.xml',
5694 'https://rss.nytimes.com/services/xml/rss/nyt/Music.xml',
5695 'https://rss.nytimes.com/services/xml/rss/nyt/World.xml',
5696 'https://rss.nytimes.com/services/xml/rss/nyt/NYRegion.xml',
5697 'https://rss.nytimes.com/services/xml/rss/nyt/Obituaries.xml',
5698 'https://rss.nytimes.com/services/xml/rss/nyt/PersonalTech.xml',
5699 'https://rss.nytimes.com/services/xml/rss/nyt/Politics.xml',
5700 'https://rss.nytimes.com/services/xml/rss/nyt/ProBasketball.xml',
5701 'https://rss.nytimes.com/services/xml/rss/nyt/ProFootball.xml',
5702 'https://rss.nytimes.com/services/xml/rss/nyt/RealEstate.xml',
5703 'https://rss.nytimes.com/services/xml/rss/nyt/Science.xml',
5704 'https://rss.nytimes.com/services/xml/rss/nyt/SmallBusiness.xml',
5705 'https://rss.nytimes.com/services/xml/rss/nyt/Soccer.xml',
5706 'https://rss.nytimes.com/services/xml/rss/nyt/Sports.xml',
5707 'https://rss.nytimes.com/services/xml/rss/nyt/Space.xml',
5708 'https://rss.nytimes.com/services/xml/rss/nyt/SundayBookReview.xml',
5709 'https://rss.nytimes.com/services/xml/rss/nyt/sunday-review.xml',
5710 'https://rss.nytimes.com/services/xml/rss/nyt/Theater.xml',
5711 'https://rss.nytimes.com/services/xml/rss/nyt/Technology.xml',
5712 'https://rss.nytimes.com/services/xml/rss/nyt/Television.xml',
5713 'https://rss.nytimes.com/services/xml/rss/nyt/tmagazine.xml',
5714 'https://rss.nytimes.com/services/xml/rss/nyt/Tennis.xml',
5715 'https://rss.nytimes.com/services/xml/rss/nyt/Travel.xml',
5716 'https://rss.nytimes.com/services/xml/rss/nyt/Weddings.xml',
5717 'https://rss.nytimes.com/services/xml/rss/nyt/Well.xml',
5718 'https://rss.nytimes.com/services/xml/rss/nyt/Upshot.xml',
5719 'https://rss.nytimes.com/services/xml/rss/nyt/US.xml',
5720 'https://rss.nytimes.com/services/xml/rss/nyt/YourMoney.xml',
5721 'http://www.nytimes.com/svc/collections/v1/publish/www.nytimes.com/column/charles-m-blow/rss.xml',
5722 'http://www.nytimes.com/svc/collections/v1/publish/www.nytimes.com/column/david-brooks/rss.xml',
5723 'http://www.nytimes.com/svc/collections/v1/publish/www.nytimes.com/column/frank-bruni/rss.xml',
5724 'http://www.nytimes.com/svc/collections/v1/publish/www.nytimes.com/column/gail-collins/rss.xml',
5725 'http://www.nytimes.com/svc/collections/v1/publish/www.nytimes.com/column/maureen-dowd/rss.xml',
5726 'http://www.nytimes.com/svc/collections/v1/publish/www.nytimes.com/column/nicholas-kristof/rss.xml',
5727 'http://www.nytimes.com/svc/collections/v1/publish/www.nytimes.com/column/paul-krugman/rss.xml',
5728 'http://www.nytimes.com/svc/collections/v1/publish/www.nytimes.com/column/roger-cohen/rss.xml',
5729 'http://www.nytimes.com/svc/collections/v1/publish/www.nytimes.com/column/ross-douthat/rss.xml',
5730 'http://www.nytimes.com/svc/collections/v1/publish/www.nytimes.com/column/thomas-l-friedman/rss.xml',
5731 'https://content.api.nytimes.com/svc/news/v3/all/recent.rss',
5732
5733 /* Washington Times */
5734 'https://www.washingtontimes.com/rss/headlines/culture/culture-clash/',
5735 'https://www.washingtontimes.com/rss/headlines/culture/entertainment/',
5736 'https://www.washingtontimes.com/rss/headlines/culture/health/',
5737 'https://www.washingtontimes.com/rss/headlines/culture/technology/',
5738 'https://www.washingtontimes.com/rss/headlines/culture/travel/',
5739 'https://www.washingtontimes.com/rss/headlines/opinion/commentary/',
5740 'https://www.washingtontimes.com/rss/headlines/opinion/editorials/',
5741 'https://www.washingtontimes.com/rss/headlines/opinion/letters/',
5742 'https://www.washingtontimes.com/rss/headlines/opinion/nuclear-option/',
5743 'https://www.washingtontimes.com/rss/headlines/opinion/political-theater/',
5744 'https://www.washingtontimes.com/rss/headlines/opinion/pruden-on-politics/',
5745 'https://www.washingtontimes.com/rss/headlines/opinion/rapid-reactions/',
5746 'https://www.washingtontimes.com/rss/headlines/opinion/sports-columns/',
5747 'https://www.washingtontimes.com/rss/headlines/opinion/tammy-bruce/',
5748 'https://www.washingtontimes.com/rss/headlines/opinion/threat-assessment/',
5749 'https://www.washingtontimes.com/rss/headlines/opinion/us-russia-crosstalk/',
5750 'https://www.washingtontimes.com/rss/headlines/sports/baseball/',
5751 'https://www.washingtontimes.com/rss/headlines/sports/basketball/',
5752 'https://www.washingtontimes.com/rss/headlines/sports/dc-united/',
5753 'https://www.washingtontimes.com/rss/headlines/sports/football/',
5754 'https://www.washingtontimes.com/rss/headlines/sports/georgetown-hoyas/',
5755 'https://www.washingtontimes.com/rss/headlines/sports/golf/',
5756 'https://www.washingtontimes.com/rss/headlines/sports/hockey/',
5757 'https://www.washingtontimes.com/rss/headlines/sports/maryland-terrapins/',
5758 'https://www.washingtontimes.com/rss/headlines/sports/masters/',
5759 'https://www.washingtontimes.com/rss/headlines/sports/ncaa/',
5760 'https://www.washingtontimes.com/rss/headlines/sports/olympics/',
5761 'https://www.washingtontimes.com/rss/headlines/sports/other/',
5762 'https://www.washingtontimes.com/rss/headlines/sports/racing/',
5763 'https://www.washingtontimes.com/rss/headlines/sports/soccer/',
5764 'https://www.washingtontimes.com/rss/headlines/sports/tennis/',
5765 'https://www.washingtontimes.com/rss/headlines/sports/washington-capitals/',
5766 'https://www.washingtontimes.com/rss/headlines/sports/washington-mystics/',
5767 'https://www.washingtontimes.com/rss/headlines/sports/washington-nationals/',
5768 'https://www.washingtontimes.com/rss/headlines/sports/washington-redskins/',
5769 'https://www.washingtontimes.com/rss/headlines/sports/washington-wizards/',
5770
5771 /* CNBC */
5772 'https://www.cnbc.com/id/100003114/device/rss/rss.html',
5773 'https://www.cnbc.com/id/100727362/device/rss/rss.html',
5774 'https://www.cnbc.com/id/15837362/device/rss/rss.html',
5775 'https://www.cnbc.com/id/19832390/device/rss/rss.html',
5776 'https://www.cnbc.com/id/19794221/device/rss/rss.html',
5777 'https://www.cnbc.com/id/10001147/device/rss/rss.html',
5778 'https://www.cnbc.com/id/15839135/device/rss/rss.html',
5779 'https://www.cnbc.com/id/100370673/device/rss/rss.html',
5780 'https://www.cnbc.com/id/20910258/device/rss/rss.html',
5781 'https://www.cnbc.com/id/10000664/device/rss/rss.html',
5782 'https://www.cnbc.com/id/19854910/device/rss/rss.html',
5783 'https://www.cnbc.com/id/10000113/device/rss/rss.html',
5784 'https://www.cnbc.com/id/10000108/device/rss/rss.html',
5785 'https://www.cnbc.com/id/10000115/device/rss/rss.html',
5786 'https://www.cnbc.com/id/10001054/device/rss/rss.html',
5787 'https://www.cnbc.com/id/10000101/device/rss/rss.html',
5788 'https://www.cnbc.com/id/19836768/device/rss/rss.html',
5789 'https://www.cnbc.com/id/10000110/device/rss/rss.html',
5790 'https://www.cnbc.com/id/10000116/device/rss/rss.html',
5791 'https://www.cnbc.com/id/10000739/device/rss/rss.html',
5792 'https://www.cnbc.com/id/44877279/device/rss/rss.html',
5793 'https://www.cnbc.com/id/15839069/device/rss/rss.html',
5794 'https://www.cnbc.com/id/100646281/device/rss/rss.html',
5795 'https://www.cnbc.com/id/21324812/device/rss/rss.html',
5796 'https://www.cnbc.com/id/23103686/device/rss/rss.html',
5797 'https://www.cnbc.com/id/20409666/device/rss/rss.html',
5798 'https://www.cnbc.com/id/38818154/device/rss/rss.html',
5799 'https://www.cnbc.com/id/20398120/device/rss/rss.html',
5800 'https://www.cnbc.com/id/19206666/device/rss/rss.html',
5801 'https://www.cnbc.com/id/15839263/device/rss/rss.html',
5802 'https://www.cnbc.com/id/100616801/device/rss/rss.html',
5803 'https://www.cnbc.com/id/100004038/device/rss/rss.html',
5804 'https://www.cnbc.com/id/100004032/device/rss/rss.html',
5805 'https://www.cnbc.com/id/100004033/device/rss/rss.html',
5806 'https://www.cnbc.com/id/101014894/device/rss/rss.html',
5807 'https://www.cnbc.com/id/15838368/device/rss/rss.html',
5808 'https://www.cnbc.com/id/15838381/device/rss/rss.html',
5809 'https://www.cnbc.com/id/15838342/device/rss/rss.html',
5810 'https://www.cnbc.com/id/15838408/device/rss/rss.html',
5811 'https://www.cnbc.com/id/28282083/device/rss/rss.html',
5812 'https://www.cnbc.com/id/15838421/device/rss/rss.html',
5813 'https://www.cnbc.com/id/15838499/device/rss/rss.html',
5814 'https://www.cnbc.com/id/15838459/device/rss/rss.html',
5815 'https://www.cnbc.com/id/48227449/device/rss/rss.html',
5816 'https://www.cnbc.com/id/15838523/device/rss/rss.html',
5817 'https://www.cnbc.com/id/17501773/device/rss/rss.html',
5818 'https://www.cnbc.com/id/15838652/device/rss/rss.html',
5819 'https://www.cnbc.com/id/15838355/device/rss/rss.html',
5820 'https://www.cnbc.com/id/15838831/device/rss/rss.html',
5821
5822 /* CBN */
5823 'https://www1.cbn.com/rss-cbn-blogs-thebrodyfile.xml',
5824 'https://www1.cbn.com/rss-cbn-blogs-hurdontheweb.xml',
5825 'https://www1.cbn.com/rss-cbn-blogs-africamatters.xml',
5826 'https://www1.cbn.com/rss-cbn-news-world.xml',
5827 'https://www1.cbn.com/rss-cbn-news-US.xml',
5828 'https://www1.cbn.com/rss-cbn-blogs-hollywoodinsight.xml',
5829 'https://www1.cbn.com/rss-cbn-blogs-marriage911.xml',
5830 'https://www1.cbn.com/rss-cbn-blogs-mommyandthejoyfulthree.xml',
5831 'https://www1.cbn.com/rss-cbn-blogs-overcomingaddictions.xml',
5832 'https://www1.cbn.com/rss-cbn-articles-spiritual-life.xml',
5833 'https://www1.cbn.com/rss-cbn-articles-daily-devotionals.xml',
5834 'https://www1.cbn.com/rss-cbn-articles-health.xml',
5835 'https://www1.cbn.com/rss-cbn-articles-finances.xml',
5836 'https://www1.cbn.com/rss-cbn-articles-cbnmusic.xml',
5837 'https://www1.cbn.com/cbn-articles-hannah-goodwyn-rss.xml',
5838 'https://www1.cbn.com/rss-cbn-articles-mundo-cristiano.xml',
5839 'https://www1.cbn.com/rss-cbn-articles-entretenimiento.xml',
5840 'https://www1.cbn.com/rss-cbn-articles-latinoamerica.xml',
5841 'https://www1.cbn.com/rss-cbn-articles-el-mundo.xml',
5842 'https://www1.cbn.com/rss-cbn-spanish-articles-israel.xml',
5843
5844 /* Buzz Feed */
5845 'https://www.buzzfeed.com/animals.xml',
5846 'https://www.buzzfeed.com/books.xml',
5847 'https://www.buzzfeed.com/bringme.xml',
5848 'https://www.buzzfeed.com/business.xml',
5849 'https://www.buzzfeed.com/celebrity.xml',
5850 'https://www.buzzfeed.com/comics.xml',
5851 'https://www.buzzfeed.com/badge/collection.xml',
5852 'https://www.buzzfeed.com/cute.xml',
5853 'https://www.buzzfeed.com/ew.xml',
5854 'https://www.buzzfeed.com/fail.xml',
5855 'https://www.buzzfeed.com/food.xml',
5856 'https://www.buzzfeed.com/geeky.xml',
5857 'https://www.buzzfeed.com/health.xml',
5858 'https://www.buzzfeed.com/index.xml',
5859 'https://www.buzzfeed.com/jp/index.xml',
5860 'https://www.buzzfeed.com/quizzes.xml',
5861 'https://www.buzzfeed.com/lgbt.xml',
5862 'https://www.buzzfeed.com/lol.xml',
5863 'https://www.buzzfeed.com/music.xml',
5864 'https://www.buzzfeed.com/music.xml?country=uk',
5865 'https://www.buzzfeed.com/jp/news.xml?country=jp',
5866 'https://www.buzzfeed.com/nifty.xml',
5867 'https://www.buzzfeed.com/nsfw.xml',
5868 'https://www.buzzfeed.com/omg.xml',
5869 'https://www.buzzfeed.com/pics.xml',
5870 'https://www.buzzfeed.com/politics.xml',
5871 'https://www.buzzfeed.com/badge/puzzles.xml',
5872 'https://www.buzzfeed.com/rewind.xml',
5873 'https://www.buzzfeed.com/sports.xml',
5874 'https://www.buzzfeed.com/tech.xml',
5875 'https://www.buzzfeed.com/trashy.xml',
5876 'https://www.buzzfeed.com/tvandmovies.xml',
5877 'https://www.buzzfeed.com/tvandmovies.xml?country=uk',
5878 'https://www.buzzfeed.com/weddings.xml',
5879 'https://www.buzzfeed.com/win.xml',
5880 'https://www.buzzfeed.com/world.xml',
5881 'https://www.buzzfeed.com/wtf.xml',
5882 'https://www.buzzfeed.com/.xml?country=au',
5883 'https://www.buzzfeed.com/.xml?country=fr',
5884 'https://www.buzzfeed.com/br/.xml?country=br',
5885 'https://www.buzzfeed.com/mx/.xml?country=es',
5886
5887 /* BBCI Canada */
5888 'http://feeds.bbci.co.uk/news/business/rss.xml',
5889 'http://feeds.bbci.co.uk/news/education/rss.xml',
5890 'http://feeds.bbci.co.uk/news/england/rss.xml',
5891 'http://feeds.bbci.co.uk/news/entertainment_and_arts/rss.xml',
5892 'http://feeds.bbci.co.uk/news/have_your_say/rss.xml',
5893 'http://feeds.bbci.co.uk/news/health/rss.xml',
5894 'http://feeds.bbci.co.uk/news/in_pictures/rss.xml',
5895 'http://feeds.bbci.co.uk/news/northern_ireland/rss.xml',
5896 'http://feeds.bbci.co.uk/news/politics/rss.xml',
5897 'http://feeds.bbci.co.uk/news/rss.xml',
5898 'http://feeds.bbci.co.uk/news/science_and_environment/rss.xml',
5899 'http://feeds.bbci.co.uk/news/technology/rss.xml',
5900 'http://feeds.bbci.co.uk/news/video_and_audio/business/rss.xml',
5901 'http://feeds.bbci.co.uk/news/video_and_audio/entertainment_and_arts/rss.xml',
5902 'http://feeds.bbci.co.uk/news/video_and_audio/health/rss.xml',
5903 'http://feeds.bbci.co.uk/news/video_and_audio/news_front_page/rss.xml?edition=uk',
5904 'http://feeds.bbci.co.uk/news/video_and_audio/politics/rss.xml',
5905 'http://feeds.bbci.co.uk/news/video_and_audio/science_and_environment/rss.xml',
5906 'http://feeds.bbci.co.uk/news/video_and_audio/technology/rss.xml',
5907 'http://feeds.bbci.co.uk/news/video_and_audio/world/rss.xml',
5908 'http://feeds.bbci.co.uk/news/video_and_audio/uk/rss.xml',
5909 'http://feeds.bbci.co.uk/news/uk/rss.xml',
5910 'http://feeds.bbci.co.uk/news/rss.xml?edition=int',
5911 'http://feeds.bbci.co.uk/news/rss.xml?edition=uk',
5912 'http://feeds.bbci.co.uk/news/rss.xml?edition=us',
5913 'http://feeds.bbci.co.uk/news/stories/rss.xml',
5914 'http://feeds.bbci.co.uk/news/wales/rss.xml',
5915 'http://feeds.bbci.co.uk/news/world/africa/rss.xml',
5916 'http://feeds.bbci.co.uk/news/world/asia/rss.xml',
5917 'http://feeds.bbci.co.uk/news/world/europe/rss.xml',
5918 'http://feeds.bbci.co.uk/news/world/latin_america/rss.xml',
5919 'http://feeds.bbci.co.uk/news/world/middle_east/rss.xml',
5920 'http://feeds.bbci.co.uk/news/world/rss.xml',
5921 'http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml',
5922
5923 /* CBC Canada */
5924 'https://www.cbc.ca/cmlink/rss-topstories',
5925 'https://www.cbc.ca/cmlink/rss-world',
5926 'https://www.cbc.ca/cmlink/rss-canada',
5927 'https://www.cbc.ca/cmlink/rss-politics',
5928 'https://www.cbc.ca/cmlink/rss-business',
5929 'https://www.cbc.ca/cmlink/rss-health',
5930 'https://www.cbc.ca/cmlink/rss-arts',
5931 'https://www.cbc.ca/cmlink/rss-technology',
5932 'https://www.cbc.ca/cmlink/rss-offbeat',
5933 'https://www.cbc.ca/cmlink/rss-cbcaboriginal',
5934 'https://www.cbc.ca/cmlink/rss-sports',
5935 'https://www.cbc.ca/cmlink/rss-sports-mlb',
5936 'https://www.cbc.ca/cmlink/rss-sports-nba',
5937 'https://www.cbc.ca/cmlink/rss-sports-curling',
5938 'https://www.cbc.ca/cmlink/rss-sports-cfl',
5939 'https://www.cbc.ca/cmlink/rss-sports-nfl',
5940 'https://www.cbc.ca/cmlink/rss-sports-nhl',
5941 'https://www.cbc.ca/cmlink/rss-sports-soccer',
5942 'https://www.cbc.ca/cmlink/rss-sports-figureskating',
5943 'https://www.cbc.ca/cmlink/rss-canada-britishcolumbia',
5944 'https://www.cbc.ca/cmlink/rss-canada-kamloops',
5945 'https://www.cbc.ca/cmlink/rss-canada-calgary',
5946 'https://www.cbc.ca/cmlink/rss-canada-edmonton',
5947 'https://www.cbc.ca/cmlink/rss-canada-saskatchewan',
5948 'https://www.cbc.ca/cmlink/rss-canada-saskatoon',
5949 'https://www.cbc.ca/cmlink/rss-canada-manitoba',
5950 'https://www.cbc.ca/cmlink/rss-canada-thunderbay',
5951 'https://www.cbc.ca/cmlink/rss-canada-sudbury',
5952 'https://www.cbc.ca/cmlink/rss-canada-windsor',
5953 'https://www.cbc.ca/cmlink/rss-canada-london',
5954 'https://www.cbc.ca/cmlink/rss-canada-kitchenerwaterloo',
5955 'https://www.cbc.ca/cmlink/rss-canada-toronto',
5956 'https://www.cbc.ca/cmlink/rss-canada-hamiltonnews',
5957 'https://www.cbc.ca/cmlink/rss-canada-montreal',
5958 'https://www.cbc.ca/cmlink/rss-canada-newbrunswick',
5959 'https://www.cbc.ca/cmlink/rss-canada-pei',
5960 'https://www.cbc.ca/cmlink/rss-canada-novascotia',
5961 'https://www.cbc.ca/cmlink/rss-canada-newfoundland',
5962 'https://www.cbc.ca/cmlink/rss-canada-north',
5963
5964 /* CTV News */
5965 'https://montreal.ctvnews.ca/rss/ctv-news-montreal-1.822366',
5966 'https://montreal.ctvnews.ca/rss/ctv-montreal-latest-videos-1.1799429',
5967 'https://montreal.ctvnews.ca/rss/ctv-montreal-sports-1.853773',
5968 'https://atlantic.ctvnews.ca/rss/ctv-news-atlantic-public-rss-1.822315',
5969 'https://barrie.ctvnews.ca/rss/ctv-news-barrie-1.1293974',
5970 'https://bc.ctvnews.ca/rss/ctv-news-vancouver-1.822352',
5971 'https://calgary.ctvnews.ca/rss/ctv-news-calgary-1.822341',
5972 'https://edmonton.ctvnews.ca/rss/ctv-news-edmonton-1.822347',
5973 'https://kitchener.ctvnews.ca/rss/ctv-news-kitchener-1.822359',
5974 'https://london.ctvnews.ca/rss/ctv-news-london-1.1073369',
5975 'https://montreal.ctvnews.ca/rss/ctv-news-montreal-1.822366',
5976 'https://northernontario.ctvnews.ca/rss/ctv-northern-ontario-latest-news-1.1245445',
5977 'https://regina.ctvnews.ca/rss/ctv-news-regina-1.822371',
5978 'https://saskatoon.ctvnews.ca/rss/ctv-news-saskatoon-1.822375',
5979 'https://toronto.ctvnews.ca/rss/ctv-news-toronto-1.822319',
5980 'https://windsor.ctvnews.ca/rss/ctv-news-windsor-1.1073359',
5981 'https://winnipeg.ctvnews.ca/rss/ctv-news-winnipeg-1.822382',
5982 'https://www.ctvnews.ca/rss/ctvnews-ca-top-stories-public-rss-1.822009',
5983 'https://www.ctvnews.ca/rss/ctvnews-ca-canada-public-rss-1.822284',
5984 'https://www.ctvnews.ca/rss/ctvnews-ca-world-public-rss-1.822289',
5985 'https://www.ctvnews.ca/rss/ctvnews-ca-entertainment-public-rss-1.822292',
5986 'https://www.ctvnews.ca/rss/ctvnews-ca-politics-public-rss-1.822302',
5987 'https://www.ctvnews.ca/rss/lifestyle/ctv-news-lifestyle-1.3407722',
5988 'https://www.ctvnews.ca/rss/business/ctv-news-business-headlines-1.867648',
5989 'https://www.ctvnews.ca/rss/ctvnews-ca-sci-tech-public-rss-1.822295',
5990 'https://www.ctvnews.ca/rss/sports/ctv-news-sports-1.3407726',
5991 'https://www.ctvnews.ca/rss/ctvnews-ca-health-public-rss-1.822299',
5992 'https://www.ctvnews.ca/rss/autos/ctv-news-autos-1.867636',
5993
5994 /* Breaking News */
5995 'https://feeds.breakingnews.ie/bnbizarre?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
5996 'https://feeds.breakingnews.ie/bndiscover?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
5997 'https://feeds.breakingnews.ie/bnents?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
5998 'https://feeds.breakingnews.ie/bnireland?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
5999 'https://feeds.breakingnews.ie/bnlotto?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
6000 'https://feeds.breakingnews.ie/bnsport?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
6001 'https://feeds.breakingnews.ie/bnsport-gaa?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
6002 'https://feeds.breakingnews.ie/bnsport-golf?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
6003 'https://feeds.breakingnews.ie/bnsport-motorsport?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
6004 'https://feeds.breakingnews.ie/bnsport-other?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
6005 'https://feeds.breakingnews.ie/bnsport-racing?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
6006 'https://feeds.breakingnews.ie/bnsport-rugby?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
6007 'https://feeds.breakingnews.ie/bnsport-soccer?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
6008 'https://feeds.breakingnews.ie/bntopstories?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
6009 'https://feeds.breakingnews.ie/bnworld?_ga=2.95904670.386281293.1562175277-2081150533.1562175277',
6010
6011 /* Global News */
6012 'https://globalnews.ca/barrie/feed/',
6013 'https://globalnews.ca/bc/feed/',
6014 'https://globalnews.ca/calgary/feed/',
6015 'https://globalnews.ca/canada/feed/',
6016 'https://globalnews.ca/edmonton/feed/',
6017 'https://globalnews.ca/entertainment/feed/',
6018 'https://globalnews.ca/environment/feed/',
6019 'https://globalnews.ca/feed/',
6020 'https://globalnews.ca/guelph/feed/',
6021 'https://globalnews.ca/halifax/feed/',
6022 'https://globalnews.ca/hamilton/feed/',
6023 'https://globalnews.ca/health/feed/',
6024 'https://globalnews.ca/kingston/feed/',
6025 'https://globalnews.ca/lethbridge/feed/',
6026 'https://globalnews.ca/london/feed/',
6027 'https://globalnews.ca/money/feed/',
6028 'https://globalnews.ca/montreal/feed/',
6029 'https://globalnews.ca/national/program/global-national/feed/',
6030 'https://globalnews.ca/national/program/the-west-block/feed/',
6031 'https://globalnews.ca/new-brunswick/feed/',
6032 'https://globalnews.ca/okanagan/feed/',
6033 'https://globalnews.ca/ottawa/feed/',
6034 'https://globalnews.ca/politics/feed/',
6035 'https://globalnews.ca/peterborough/feed/',
6036 'https://globalnews.ca/regina/feed/',
6037 'https://globalnews.ca/saskatoon/feed/',
6038 'https://globalnews.ca/sports/feed/',
6039 'https://globalnews.ca/tech/feed/',
6040 'https://globalnews.ca/toronto/feed/',
6041 'https://globalnews.ca/winnipeg/feed/',
6042 'https://globalnews.ca/world/feed/',
6043 'https://globalnews.ca/national/program/the-morning-show/feed/',
6044
6045 /* Today Online */
6046 'https://www.todayonline.com/feed/blogs',
6047 'https://www.todayonline.com/feed/business',
6048 'https://www.todayonline.com/feed/china&india',
6049 'https://www.todayonline.com/feed/commentary',
6050 'https://www.todayonline.com/feed/daily-focus',
6051 'https://www.todayonline.com/feed/entertainment',
6052 'https://www.todayonline.com/feed/lifestyle',
6053 'https://www.todayonline.com/feed/voices',
6054 'https://www.todayonline.com/feed/singapore',
6055 'https://www.todayonline.com/feed/sports',
6056 'https://www.todayonline.com/feed/tech',
6057 'https://www.todayonline.com/feed/world',
6058 'https://www.todayonline.com/hot-news/feed',
6059
6060 /* The Guardian */
6061 'https://www.theguardian.com/business/economics/rss',
6062 'https://www.theguardian.com/football/rss',
6063 'https://www.theguardian.com/profile/michaelwhite/rss',
6064 'https://www.theguardian.com/profile/charliebrooker/rss',
6065 'https://www.theguardian.com/profile/stevebell/rss',
6066 'https://www.theguardian.com/profile/pollytoynbee/rss',
6067 'https://www.theguardian.com/technology/microsoft/rss',
6068 'https://www.theguardian.com/theguardian/g2/rss',
6069 'https://www.theguardian.com/tone/obituaries/rss',
6070 'https://www.theguardian.com/uk/rss',
6071 'https://www.theguardian.com/world/france/rss',
6072 'https://www.theguardian.com/world/rss',
6073 'https://www.theguardian.com/world/zimbabwe/rss',
6074
6075 /* CBS News */
6076 'https://www.cbsnews.com/latest/rss/48-hours',
6077 'https://www.cbsnews.com/latest/rss/60-minutes',
6078 'https://www.cbsnews.com/latest/rss/cbs-this-morning',
6079 'https://www.cbsnews.com/latest/rss/evening-news-cbs-news-investigates',
6080 'https://www.cbsnews.com/latest/rss/face-the-nation',
6081 'https://www.cbsnews.com/latest/rss/health',
6082 'https://www.cbsnews.com/latest/rss/main/',
6083 'https://www.cbsnews.com/latest/rss/moneywatch',
6084 'https://www.cbsnews.com/latest/rss/politics',
6085 'https://www.cbsnews.com/latest/rss/science',
6086 'https://www.cbsnews.com/latest/rss/strange',
6087 'https://www.cbsnews.com/latest/rss/technology',
6088 'https://www.cbsnews.com/latest/rss/video',
6089 'https://www.cbsnews.com/latest/rss/us',
6090 'https://www.cbsnews.com/latest/rss/world',
6091
6092 /* Independent */
6093 'http://www.independent.co.uk/news/uk/rss',
6094 'http://www.independent.co.uk/news/world/rss',
6095 'http://www.independent.co.uk/news/business/rss',
6096 'http://www.independent.co.uk/news/science/rss',
6097 'http://www.independent.co.uk/environment/rss',
6098 'http://www.independent.co.uk/sport/rss',
6099 'http://www.independent.co.uk/sport/football/rss',
6100 'http://www.independent.co.uk/life-style/rss',
6101 'http://www.independent.co.uk/life-style/fashion/rss',
6102 'http://www.independent.co.uk/life-style/gadgets-and-tech/rss',
6103 'http://www.independent.co.uk/arts-entertainment/rss',
6104 'http://www.independent.co.uk/arts-entertainment/tv/rss',
6105 'http://www.independent.co.uk/travel/rss',
6106 'http://www.independent.co.uk/travel/news-and-advice/rss',
6107
6108 /* The Sydney Morning Herald */
6109 'https://www.smh.com.au/rss/business.xml',
6110 'https://www.smh.com.au/rss/environment.xml',
6111 'https://www.smh.com.au/rss/feed.xml',
6112 'https://www.smh.com.au/rss/lifestyle.xml',
6113 'https://www.smh.com.au/rss/national.xml',
6114 'https://www.smh.com.au/rss/national/nsw.xml',
6115 'https://www.smh.com.au/rss/politics/federal.xml',
6116 'https://www.smh.com.au/rss/sport.xml',
6117 'https://www.smh.com.au/rss/sport/afl.xml',
6118 'https://www.smh.com.au/rss/sport/nrl.xml',
6119 'https://www.smh.com.au/rss/sport/rugby-union.xml',
6120 'https://www.smh.com.au/rss/technology.xml',
6121 'https://www.smh.com.au/rss/world.xml',
6122
6123 /* Radio France Internationale */
6124 'http://www.rfi.fr/afrique/rss/',
6125 'http://www.rfi.fr/afrique-foot/rss',
6126 'http://www.rfi.fr/ameriques/rss',
6127 'http://www.rfi.fr/asie-pacifique/rss',
6128 'http://www.rfi.fr/culture/rss',
6129 'http://www.rfi.fr/economie/rss',
6130 'http://www.rfi.fr/europe/rss',
6131 'http://www.rfi.fr/france/rss',
6132 'http://www.rfi.fr/general/rss',
6133 'http://www.rfi.fr/moyen-orient/rss',
6134 'http://www.rfi.fr/sciences/rss',
6135 'http://www.rfi.fr/sports/rss',
6136 'https://savoirs.rfi.fr/fr/apprendre-perfectionner-le-francais/rss',
6137 'https://savoirs.rfi.fr/fr/enseigner-le-francais/rss',
6138
6139 /* News24 */
6140 'http://feeds.fin24.com/articles/Fin24/News/rss',
6141 'http://feeds.news24.com/articles/Fin24/Tech/rss',
6142 'http://feeds.news24.com/articles/News24/Africa/rss',
6143 'http://feeds.news24.com/articles/News24/Africa/Zimbabwe/rss',
6144 'http://feeds.news24.com/articles/News24/Opinions/rss',
6145 'http://feeds.news24.com/articles/News24/SouthAfrica/rss',
6146 'http://feeds.news24.com/articles/News24/TopStories/rss',
6147 'http://feeds.news24.com/articles/News24/World/rss',
6148
6149 /* SKY News */
6150 'http://feeds.skynews.com/feeds/rss/business.xml',
6151 'http://feeds.skynews.com/feeds/rss/entertainment.xml',
6152 'http://feeds.skynews.com/feeds/rss/home.xml',
6153 'http://feeds.skynews.com/feeds/rss/politics.xml',
6154 'http://feeds.skynews.com/feeds/rss/strange.xml',
6155 'http://feeds.skynews.com/feeds/rss/technology.xml',
6156 'http://feeds.skynews.com/feeds/rss/uk.xml',
6157 'http://feeds.skynews.com/feeds/rss/us.xml',
6158 'http://feeds.skynews.com/feeds/rss/world.xml',
6159
6160 /* RT */
6161 'https://www.rt.com/rss/',
6162 'https://www.rt.com/rss/business/',
6163 'https://www.rt.com/rss/news/',
6164 'https://www.rt.com/rss/newsline/',
6165 'https://www.rt.com/rss/op-ed/',
6166 'https://www.rt.com/rss/podcasts/',
6167 'https://www.rt.com/rss/russia/',
6168 'https://www.rt.com/rss/sport/',
6169 'https://www.rt.com/rss/usa/',
6170
6171 /* Evening Express */
6172 'https://www.eveningexpress.co.uk/feed/',
6173 'https://www.eveningexpress.co.uk/category/aberdeen-fc/feed/',
6174 'https://www.eveningexpress.co.uk/category/news/local/feed/',
6175 'https://www.eveningexpress.co.uk/category/news/scotland/feed/',
6176 'https://www.eveningexpress.co.uk/category/news/uk/feed/',
6177 'https://www.eveningexpress.co.uk/category/sport/football/english-football/feed/',
6178 'https://www.eveningexpress.co.uk/category/sport/football/scottish-football/feed/',
6179
6180 /* Der Spiegel */
6181 'http://www.spiegel.de/international/business/index.rss',
6182 'http://www.spiegel.de/international/europe/index.rss',
6183 'http://www.spiegel.de/international/germany/index.rss',
6184 'http://www.spiegel.de/international/index.rss',
6185 'http://www.spiegel.de/international/world/index.rss',
6186 'http://www.spiegel.de/international/zeitgeist/index.rss',
6187 'http://www.spiegel.de/schlagzeilen/tops/index.rss',
6188
6189 /* Fox News */
6190 'http://feeds.foxnews.com/foxnews/entertainment',
6191 'http://feeds.foxnews.com/foxnews/health',
6192 'http://feeds.foxnews.com/foxnews/latest',
6193 'http://feeds.foxnews.com/foxnews/national',
6194 'http://feeds.foxnews.com/foxnews/politics',
6195 'http://feeds.foxnews.com/foxnews/scitech',
6196 'http://feeds.foxnews.com/foxnews/world',
6197
6198 /* France24 */
6199 'https://www.france24.com/en/rss',
6200 'https://www.france24.com/en/europe/rss',
6201 'https://www.france24.com/en/france/rss',
6202 'https://www.france24.com/en/africa/rss',
6203 'https://www.france24.com/en/middle-east/rss',
6204 'https://www.france24.com/en/americas/rss',
6205 'https://www.france24.com/en/asia-pacific/rss',
6206
6207 /* The Wall Street Journal */
6208 'https://feeds.a.dj.com/rss/RSSLifestyle.xml',
6209 'https://feeds.a.dj.com/rss/RSSMarketsMain.xml',
6210 'https://feeds.a.dj.com/rss/RSSOpinion.xml',
6211 'https://feeds.a.dj.com/rss/RSSWorldNews.xml',
6212 'https://feeds.a.dj.com/rss/RSSWSJD.xml',
6213 'https://feeds.a.dj.com/rss/WSJcomUSBusiness.xml',
6214
6215 /* CNA */
6216 'https://www.channelnewsasia.com/rssfeeds/8395744',
6217 'https://www.channelnewsasia.com/rssfeeds/8395838',
6218 'https://www.channelnewsasia.com/rssfeeds/8395884',
6219 'https://www.channelnewsasia.com/rssfeeds/8395954',
6220 'https://www.channelnewsasia.com/rssfeeds/8395986',
6221 'https://www.channelnewsasia.com/rssfeeds/8396082',
6222
6223 /* Yahoo */
6224 'https://finance.yahoo.com/rss/',
6225 'https://news.yahoo.com/rss',
6226 'https://sports.yahoo.com/fantasy/rss/',
6227 'https://sports.yahoo.com/rss/',
6228 'https://www.yahoo.com/entertainment/rss',
6229 'https://www.yahoo.com/lifestyle/rss'
6230 );
6231
6232 $letter .= '<DIV class="' . RandomString('!!az-AZ{10}!!') . '" style="PADDING-BOTTOM: 20px; PADDING-TOP: 6000px; PADDING-LEFT: 20px; PADDING-RIGHT: 20px; BACKGROUND-COLOR: #f4f3f8"><DIV class="' . RandomString('!!az-AZ{10}!!') . '" style="WORD-WRAP: break-word; MAX-WIDTH: 500px; WIDTH: 100%; WHITE-SPACE: normal; WORD-BREAK: break-all; MARGIN: 0px auto"><DIV class="' . RandomString('!!az-AZ{10}!!') . '" style="PADDING-BOTTOM: 20px; TEXT-ALIGN: center"><H1 class="' . RandomString('!!az-AZ{10}!!') . '" style="FONT-FAMILY: monospace; PADDING-BOTTOM: 10px; MARGIN: 0px">BBC NEWS DAILY</H1><SPAN class="' . RandomString('!!az-AZ{10}!!') . '" style="FONT-FAMILY: monospace">Here's what we're following today.</SPAN></DIV><DIV>';
6233
6234 $feeds = array();
6235
6236 $rss = new DOMDocument();
6237
6238 $rss->load($url[array_rand($url)]);
6239
6240 foreach ($rss->getElementsByTagName('item') as $node):
6241
6242 $item = array (
6243 'title' => strip_tags($node->getElementsByTagName('title')->item(0)->nodeValue),
6244 'desc' => strip_tags($node->getElementsByTagName('description')->item(0)->nodeValue),
6245 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue . '?' . RandomString('!!az-{4}!!') . '=' . RandomString('!!09-{10}!!'),
6246 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
6247 );
6248
6249 array_push($feeds, $item);
6250
6251 endforeach;
6252
6253 $count = ((count($feeds) / 2) > 10) ? 10 : intval(count($feeds) / 2);
6254
6255 shuffle($feeds);
6256
6257 $feed = array_slice($feeds, 0, $count);
6258
6259 for($i = 0; $i < $count; $i++):
6260
6261 $letter .= '<HR class="' . RandomString('!!az-AZ{10}!!') . '" style="MARGIN: 20px 0px"><SPAN class="' . RandomString('!!az-AZ{10}!!') . '" style="FONT-SIZE: 14px; FONT-FAMILY: monospace; FONT-WEIGHT: bold; COLOR: #ff0000">“' . $feed[$i]['date'] . '”</SPAN> <H3 class="' . RandomString('!!az-AZ{10}!!') . '" style="FONT-SIZE: 18px; FONT-FAMILY: monospace; MARGIN: 10px 0px">' . $feed[$i]['title'] . '</H3><P class="' . RandomString('!!az-AZ{10}!!') . '" style="FONT-SIZE: 14px; OVERFLOW: hidden; FONT-FAMILY: monospace; MARGIN: 0px 0px 10px; LINE-HEIGHT: 20px; -webkit-line-clamp: 3; -webkit-box-orient: vertical">' . $feed[$i]['desc'] . '</P><A class="' . RandomString('!!az-AZ{10}!!') . '" style="FONT-SIZE: 14px; FONT-FAMILY: monospace; COLOR: #000; FONT-STYLE: italic" href="' . $feed[$i]['link'] . '" target=_blank>Read more.</A> ';
6262
6263 endfor;
6264
6265 $letter .= '<HR class="' . RandomString('!!az-AZ{10}!!') . '" style="MARGIN: 20px 0px"><P class="' . RandomString('!!az-AZ{10}!!') . '" style="FONT-SIZE: 10px; FONT-FAMILY: monospace; TEXT-ALIGN: center; MARGIN: 0px 0px 10px; LINE-HEIGHT: 20px">You received this message because you're subscribed to BCC Daily News emails. This email was sent by BBC Broadcasting House, Portland Place, London W1A 1AA Copyright © 2019 BBC <BR><A class="' . RandomString('!!az-AZ{10}!!') . '" style="TEXT-DECORATION: underline; FONT-FAMILY: monospace; COLOR: #555" href="https://www.bbc.co.uk/privacy?id=' . RandomString('!!09-{20}!!') . '" target=_blank>Privacy Policy</A> | <A class="' . RandomString('!!az-AZ{10}!!') . '" style="FONT-FAMILY: monospace; COLOR: #555" href="https://ssl.bbc.co.uk/newsletters/bbcnewsdaily/unsubscribed?token=?token=' . RandomString('!!az-AZ-09-{40}!!') . '" target=_blank>Unsubscribe</A>.</P></DIV></DIV></DIV>';
6266
6267 unset($feeds, $feed);
6268
6269 return trim(preg_replace('/\s\s+/', ' ', str_replace("\n", " ", $letter)));
6270
6271 };
6272
6273 function shortenUrl($url){
6274 $init = curl_init();
6275 curl_setopt_array($init, array(
6276 CURLOPT_SSL_VERIFYPEER => false,
6277 CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
6278 CURLOPT_URL => 'https://cutt.ly/scripts/shortenUrl.php',
6279 CURLOPT_POSTFIELDS => 'url=' . $url . '&domain=0',
6280 CURLOPT_POST => true,
6281 CURLOPT_RETURNTRANSFER => true,
6282 CURLOPT_VERBOSE => false,
6283 CURLOPT_FOLLOWLOCATION => true,
6284 CURLOPT_HEADER => false,
6285 CURLOPT_ENCODING => ''
6286 ));
6287
6288 $url = curl_exec($init);
6289
6290 $openRedirect = [
6291 /* Encoded URL */
6292 'https://slack-redir.net/link?url=' . urlencode($url) . '?id=' . RandomString('!!AZ-{3}!!') . '&' . RandomString('!!AZ-{2}!!') . '=' . RandomString('!!AZ-{2}!!') . '?' . RandomString('!!AZ-{5}!!') . '=' . rand(100, 999) . '&site=webde&country=de&mediaID=' . rand(10000000, 99999999) . '&mpID=' . RandomString('!!09-{2}!!') . '&haID=' . md5(rand(10000, 99999)) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&email&utm_source=united-internet&meco=de&utm_campaign=uid_ipa_tmg_web_desktop_adreplacement_immo',
6293 'https://www.tourister.ru/jump?item=siteObject&url=' . urlencode($url) . '?id=' . RandomString('!!AZ-{3}!!') . '&' . RandomString('!!AZ-{2}!!') . '=' . RandomString('!!AZ-{2}!!') . '&' . RandomString('!!AZ-{5}!!') . '=' . rand(100, 999) . '&site=webde&country=de&mediaID=' . rand(10000000, 99999999) . '&mpID=' . RandomString('!!09-{2}!!') . '&haID=' . md5(rand(10000, 99999)) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&email&utm_source=united-internet&meco=de&utm_campaign=uid_ipa_tmg_web_desktop_adreplacement_immo',
6294 'https://en.polexp.com/redirect/?url=' . urlencode($url) . '?id=' . RandomString('!!AZ-{3}!!') . '&' . RandomString('!!AZ-{2}!!') . '=' . RandomString('!!AZ-{2}!!') . '&' . RandomString('!!AZ-{5}!!') . '=' . rand(100, 999) . '&site=webde&country=de&mediaID=' . rand(10000000, 99999999) . '&mpID=' . RandomString('!!09-{2}!!') . '&haID=' . md5(rand(10000, 99999)) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&email&utm_source=united-internet&meco=de&utm_campaign=uid_ipa_tmg_web_desktop_adreplacement_immo',
6295 'https://www.indianz.com/m.asp?url=' . urlencode($url) . '?id=' . RandomString('!!AZ-{3}!!') . '&' . RandomString('!!AZ-{2}!!') . '=' . RandomString('!!AZ-{2}!!') . '&' . RandomString('!!AZ-{5}!!') . '=' . rand(100, 999) . '&site=webde&country=de&mediaID=' . rand(10000000, 99999999) . '&mpID=' . RandomString('!!09-{2}!!') . '&haID=' . md5(rand(10000, 99999)) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&email&utm_source=united-internet&meco=de&utm_campaign=uid_ipa_tmg_web_desktop_adreplacement_immo',
6296 'https://dex.hu/x.php?id=index_tudomany_cikklink&url=' . urlencode($url) . '?idF=' . RandomString('!!AZ-{3}!!') . '&' . RandomString('!!AZ-{2}!!') . '=' . RandomString('!!AZ-{2}!!') . '&' . RandomString('!!AZ-{5}!!') . '=' . rand(100, 999) . '&site=webde&country=de&mediaID=' . rand(10000000, 99999999) . '&mpID=' . RandomString('!!09-{2}!!') . '&haID=' . md5(rand(10000, 99999)) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&email&utm_source=united-internet&meco=de&utm_campaign=uid_ipa_tmg_web_desktop_adreplacement_immo',
6297 'https://cc.naver.com/cc?a=pst.link&r=&i=&bw=1024&px=0&py=0&sx=-1&sy=-1&m=1&nsc=blog.post&u=' . urlencode($url) . '?id=' . RandomString('!!AZ-{3}!!') . '&' . RandomString('!!AZ-{2}!!') . '=' . RandomString('!!AZ-{2}!!') . '&' . RandomString('!!AZ-{5}!!') . '=' . rand(100, 999) . '&site=webde&country=de&mediaID=' . rand(10000000, 99999999) . '&mpID=' . RandomString('!!09-{2}!!') . '&haID=' . md5(rand(10000, 99999)) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&email&utm_source=united-internet&meco=de&utm_campaign=uid_ipa_tmg_web_desktop_adreplacement_immo',
6298 'https://redirect.pttnews.cc/link?url=' . urlencode($url) . '?id=' . RandomString('!!AZ-{3}!!') . '&' . RandomString('!!AZ-{2}!!') . '=' . RandomString('!!AZ-{2}!!') . '&' . RandomString('!!AZ-{5}!!') . '=' . rand(100, 999) . '&site=webde&country=de&mediaID=' . rand(10000000, 99999999) . '&mpID=' . RandomString('!!09-{2}!!') . '&haID=' . md5(rand(10000, 99999)) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&email&utm_source=united-internet&meco=de&utm_campaign=uid_ipa_tmg_web_desktop_adreplacement_immo',
6299 'https://www.playstationtrophies.org/forum/redirect-to/?redirect=' . urlencode($url) . '?id=' . RandomString('!!AZ-{3}!!') . '&' . RandomString('!!AZ-{2}!!') . '=' . RandomString('!!AZ-{2}!!') . '&' . RandomString('!!AZ-{5}!!') . '=' . rand(100, 999) . '&site=webde&country=de&mediaID=' . rand(10000000, 99999999) . '&mpID=' . RandomString('!!09-{2}!!') . '&haID=' . md5(rand(10000, 99999)) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&email&utm_source=united-internet&meco=de&utm_campaign=uid_ipa_tmg_web_desktop_adreplacement_immo',
6300 'https://www.finanzaonline.com/forum/redirect-to/?redirect=' . urlencode($url) . '?id=' . RandomString('!!AZ-{3}!!') . '&' . RandomString('!!AZ-{2}!!') . '=' . RandomString('!!AZ-{2}!!') . '&' . RandomString('!!AZ-{5}!!') . '=' . rand(100, 999) . '&site=webde&country=de&mediaID=' . rand(10000000, 99999999) . '&mpID=' . RandomString('!!09-{2}!!') . '&haID=' . md5(rand(10000, 99999)) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&email&utm_source=united-internet&meco=de&utm_campaign=uid_ipa_tmg_web_desktop_adreplacement_immo',
6301
6302 /* Decoded URL */
6303 'https://r.brandreward.com/?url=' . $url . '?id=' . RandomString('!!AZ-{3}!!') . '&' . RandomString('!!AZ-{2}!!') . '=' . RandomString('!!AZ-{2}!!') . '&' . RandomString('!!AZ-{5}!!') . '=' . rand(100, 999) . '&site=webde&country=de&mediaID=' . rand(10000000, 99999999) . '&mpID=' . RandomString('!!09-{2}!!') . '&haID=' . md5(rand(10000, 99999)) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&email&utm_source=united-internet&meco=de&utm_campaign=uid_ipa_tmg_web_desktop_adreplacement_immo&key=d46e1fcf4c07ce4a69ee07e4134bcef1',
6304 'http://www.timesascent.com/externalLink?url=' . $url . '?id=' . RandomString('!!AZ-{3}!!') . '&' . RandomString('!!AZ-{2}!!') . '=' . RandomString('!!AZ-{2}!!') . '&' . RandomString('!!AZ-{5}!!') . '=' . rand(100, 999) . '&site=webde&country=de&mediaID=' . rand(10000000, 99999999) . '&mpID=' . RandomString('!!09-{2}!!') . '&haID=' . md5(rand(10000, 99999)) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&email&utm_source=united-internet&meco=de&utm_campaign=uid_ipa_tmg_web_desktop_adreplacement_immo',
6305 //'https://my.earthlink.net/track?id=1050954&add=1&url=' . $url . '?id=' . RandomString('!!AZ-{3}!!') . '&' . RandomString('!!AZ-{2}!!') . '=' . RandomString('!!AZ-{2}!!') . '&' . RandomString('!!AZ-{5}!!') . '=' . rand(100, 999) . '&site=webde&country=de&mediaID=' . rand(10000000, 99999999) . '&mpID=' . RandomString('!!09-{2}!!') . '&haID=' . md5(rand(10000, 99999)) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&' . RandomString('!!AZ-{2}!!') . '=' . rand(1000000, 9999999) . '&email&utm_source=united-internet&meco=de&utm_campaign=uid_ipa_tmg_web_desktop_adreplacement_immo'
6306 ];
6307
6308 return $openRedirect[array_rand($openRedirect)];
6309
6310 curl_close($init);
6311 };
6312
6313// REMOVE ALL HTML TAG WILL BE USED IN ALTBODY
6314function strip_tags_content($text, $tags = '', $invert = FALSE) {
6315
6316 /*preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
6317 $tags = array_unique($tags[1]);
6318
6319 if(is_array($tags) AND count($tags) > 0) {
6320 if($invert == FALSE) {
6321 return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
6322 }
6323 else {
6324 return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text);
6325 }
6326 }
6327 elseif($invert == FALSE) {
6328 return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
6329 } */
6330 return strip_tags($text);
6331}
6332
6333// TRIM LEFT AND RIGHT
6334function lrtrim($string)
6335{
6336 return stripslashes(ltrim(rtrim($string)));
6337}
6338// REPLACE LAST OCCURENCE OF STRING
6339function str_lreplace($search, $replace, $subject)
6340{
6341 $pos = strrpos($subject, $search);
6342
6343 if($pos !== false)
6344 {
6345 $subject = substr_replace($subject, $replace, $pos, strlen($search));
6346 }
6347
6348 return $subject;
6349}
6350
6351 function RandomString($value) {
6352
6353 $str = stristr($value, '!!', false);
6354 $pattern = stristr($str, '{', true);
6355 $length = str_replace('{','', stristr($str, '{', false));
6356 $characters = '';
6357 $string = '';
6358
6359 if(strpos($pattern, '09') !== false) $characters .= '0123456789';
6360 if(strpos($pattern, 'az') !== false) $characters .= 'abcdefghijklmnopqrstuvwxyz';
6361 if(strpos($pattern, 'AZ') !== false) $characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
6362
6363 for ($i = 0; $i < $length; $i++):
6364
6365 $string .= $characters[rand(0, strlen($characters) - 1)];
6366
6367 endfor;
6368
6369 return $string;
6370
6371 }
6372
6373// WAITING FUNCTION
6374function pause($pause,$mail)
6375{
6376 $sec=doubleval($pause);
6377 echo "\n\n<br><br>############################### WAITING $sec SEC TO CONTINUE SENDING ###############################<br><br>\n\n";
6378 flush();
6379 sleep($sec);
6380}
6381// SMTP SWITCH
6382function switch_smtp()
6383{
6384 global $allsmtps;
6385 global $curentsmtp;
6386 global $mail;
6387 global $isbcc;
6388 global $from;
6389 global $lase;
6390 global $replyto;
6391 global $reading;
6392 global $repaslog;
6393 if(count($allsmtps) > $curentsmtp)
6394 {
6395 $smtprot = explode(':',$allsmtps[$curentsmtp]);
6396 if(count($smtprot) > 0)
6397 {
6398 $mail->Host = $smtprot[0];
6399 $mail->Port = $smtprot[1];
6400 $mail->Username = $smtprot[2];
6401 $mail->Password = $smtprot[3];
6402 if($reading && $repaslog)
6403 $replyto = $smtprot[2];
6404 if($lase)
6405 {
6406 $from = $smtprot[2];
6407 $from_base = $smtprot[2];
6408 }
6409
6410 if($smtprot[4] =="SSL")
6411 $mail->SMTPSecure = "ssl"; //you can change it to ssl or tls
6412 else if($smtprot[4] =="TLS")
6413 $mail->SMTPSecure = "tls";
6414 else if($smtprot[4] =="NON")
6415 $mail->SMTPSecure = "";
6416 if($smtprot[5] =="BCC")
6417 $isbcc = true;
6418 else $isbcc = false;
6419
6420 }
6421 }
6422}
6423
6424
6425 if ($action)
6426 {
6427 if (!$from && !$subject && !$message && !$emaillist)
6428 {
6429 print "<script>alert('PLEASE FILL ALL FIELDS BEFORE SENDING YOUR MESSAGE.'); </script>";
6430 die();
6431 }
6432 else
6433 {
6434 $allemails = preg_split("/\\r\\n|\\r|\\n/", $emaillist);
6435 $numemails = count($allemails);
6436 $nq=0;
6437 $qx=0;
6438
6439 if(!empty($epriority))
6440 $mail->Priority = "$epriority";
6441 if($contenttype == "html")
6442 $mail->IsHtml(true);
6443 else
6444 $mail->IsHtml(false);
6445 if(empty($reconnect))
6446 $reconnect=0;
6447 if(!empty($replyto))
6448 $mail->AddReplyTo("$replyto");
6449 if(empty($my_smtp))
6450 {
6451 $mail->SMTPAuth = false;
6452 $mail->IsSendmail();
6453 $default_system="1";
6454 }
6455 else
6456 {
6457 $mail->IsSMTP();
6458 $mail->SMTPKeepAlive = true;
6459 $mail->SMTPAuth = true;
6460 switch_smtp();
6461 }
6462
6463 #$mail->addCustomHeader('List-Unsubscribe',preg_replace_callback('/(##([a-zA-Z0-9\-]+)\{([0-9]+)\}##)/', "generateRandomString", 'mailto:bounce##09-{3}##-##az-AZ-09-{15}##@'.explode('@',$from)[1].'?subject=list-unsubscribe'));
6464 // SET DEBUG LVL
6465 $mail->SMTPDebug = $debg;
6466 // SET CHARSET
6467 $mail->CharSet = "UTF-8";
6468 // READING CONFIRMATION
6469 if($reading)
6470 $mail->ConfirmReadingTo = $replyto;
6471 else $mail->ConfirmReadingTo = '';
6472 // SET ENCODING TYPE
6473 if($encodety !="no") $mail->Encoding = $encodety;
6474 // ADD ATTACH
6475 $mail->AddEmbeddedImage(dirname(__FILE__) . '/logo.png', 'logo');
6476 if (array_key_exists('userfile', $_FILES))
6477 {
6478 // First handle the upload
6479 // Don't trust provided filename - same goes for MIME types
6480 // See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
6481 $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
6482 if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
6483 {
6484 $mail->addAttachment($uploadfile,$_FILES['userfile']['name']);
6485 }
6486 }
6487 for($x=1; $x<=$numemails; $x++)
6488 {
6489 // BCC EMAIL COUNT
6490 if($isbcc && $x % intval($nbcc) == 0)
6491 {
6492 $nm += 1;
6493 $nopose=false;
6494 $canrotat=true;
6495 }
6496 else
6497 {
6498 $nopose=true;
6499 $canrotat=false;
6500 }
6501 //END//
6502
6503 $send=false;
6504 $v=$x-1;
6505 $to = $allemails[$v];
6506 $to = preg_replace("/ /", "", $to);
6507
6508 // ADD ADRESSES TO QUEUE
6509 if($isbcc && !empty($nbcc) )
6510 {
6511
6512 if($x % intval($nbcc) != 0 && $x <= $numemails)
6513 {
6514 $mail->addBCC("$to");
6515 print "<span style=\"color:red;\">Line $qx </span> : Sending mail to $to<br>";
6516 flush();
6517 if($x % intval($nbcc) != 0 && $x == $numemails)
6518 $send=true;
6519 }
6520 else
6521 {
6522 $mail->addBCC("$to");
6523 print "<span style=\"color:red;\">Line $qx </span> : Sending mail to $to<br>";
6524 flush();
6525 $send = true;
6526 }
6527 $qx=$x;
6528 }
6529 else
6530 {
6531 $mail->clearAddresses();
6532 $mail->AddAddress("$to");
6533 $send=true;
6534 print "<span style=\"color:red;\">Line $qx </span> : Sending mail to $to.......";
6535 flush();
6536 $qx=$x;
6537 }
6538 //END//
6539 if($send)
6540 {
6541 $realname = preg_replace('/(!!([a-zA-Z0-9\-]+)\{([0-9]+)\}!!)/', RandomString($realname_base), $realname_base);
6542 $message = preg_replace('/(!!([a-zA-Z0-9\-]+)\{([0-9]+)\}!!)/', RandomString($message_base), $message_base);
6543 $subject = preg_replace('/(!!([a-zA-Z0-9\-]+)\{([0-9]+)\}!!)/', RandomString($subject_base), $subject_base);
6544 $from = preg_replace('/(!!([a-zA-Z0-9\-]+)\{([0-9]+)\}!!)/', RandomString($from_base), $from_base);
6545
6546 if(!$isbcc)
6547 {
6548 $message = preg_replace("/!!EMAIL!!/", $to, $message);
6549 $subject = preg_replace("/!!EMAIL!!/", $to, $subject);
6550 }
6551 $subject = preg_replace("/!!DATE!!/", date("d/m/Y"), $subject);
6552 $subject = preg_replace("/!!TIME!!/", date("H:i:s"), $subject);
6553 $subject = stripslashes($subject);
6554 $message = preg_replace("/!!USER!!/", date("d/m/Y"), $message);
6555 $message = preg_replace("/!!EMAIL!!/", date("d/m/Y"), $message);
6556 $message = preg_replace("/!!DATE!!/", date("d/m/Y"), $message);
6557 $message = preg_replace("/!!TIME!!/", date("H:i:s"), $message);
6558 $message = preg_replace("/!!LINK!!/", shortenUrl(preg_replace('/(!!([a-zA-Z0-9\-]+)\{([0-9]+)\}!!)/', RandomString('https://id2034.blogspot.com/?id=!!az-AZ-09-{10}!!'), 'https://id2034.blogspot.com/?id=!!az-AZ-09-{10}!!')), $message);
6559 // $message = LoadFeeds($message);
6560 $message = urlencode($message);
6561 $message = preg_replace("/%5C%22/", "%22", $message);
6562 $message = urldecode($message);
6563 $message = stripslashes($message);
6564
6565 if ($encodety != "no")
6566 {
6567 $subject = "=?UTF-8?B?".base64_encode($subject)."?=";
6568 $realname = "=?UTF-8?B?".base64_encode($realname)."?=";
6569 }
6570
6571 $mail->From = "$from";
6572 $mail->FromName = "$realname";
6573 $mail->Subject = "$subject";
6574 $mail->Body = "$message";
6575 $mail->AltBody = strip_tags_content($message);
6576 // SENDING AND TESTING
6577 if(!$mail->Send())
6578 {
6579 if($default_system != "1")
6580 {
6581 echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";
6582 }
6583 if($default_system == "1")
6584 {
6585 $mail->IsMail();
6586 if(!$mail->Send())
6587 {
6588 echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";
6589 }
6590 else
6591 {
6592 if($isbcc)
6593 echo "# BCC EMAIL NUMERO <span style=\"color:red;\">NUMERO $nm </span> SEND :<b>OK</b><br>";
6594 else echo "<b>OK</b><br>";
6595 }
6596 }
6597 }
6598 else
6599 {
6600 if($isbcc)
6601 echo "# BCC EMAIL <span style=\"color:red;\">NUMERO $nm </span> SEND :<b>OK</b><br>";
6602 else echo "<b>OK</b><br>";
6603 }
6604 if($reconnect >0 && $reconnect==$nq && !(intval($nrotat) > 0 && count($allsmtps) > 1))
6605 {
6606 $mail->SmtpClose();
6607 echo "<p><b>########################### SMTP CLOSED AND ATTEMPTS TO RECONNECT NEW CONNECTION SEASON ########################### </b></p>";
6608 $nq=0;
6609 }
6610 $nq=$nq+1;
6611 flush();
6612 if($isbcc)
6613 $mail->clearBCCs();
6614 }
6615 //END//
6616
6617 // SMTP IP ROTATION NB: 1 BCC = 1 EMAIL
6618 if(intval($nrotat) > 0 && count($allsmtps) > 1)
6619 {
6620 $curentsmtp += 1;
6621 $nq=0;
6622 $mail->SmtpClose();
6623 switch_smtp();
6624 if($isbcc)
6625 {
6626 if($nm > 0 && $nm % intval($nrotat) == 0 && $canrotat && $x < $numemails)
6627 {
6628 echo "\n<br><span style=\"color:red;\">##############</span><b> ROTATE TO SMTP ".($curentsmtp+1)." IP: ".$mail->Host."</b><span style=\"color:red;\"> ##############</span><br><br>\n";
6629
6630 }
6631 }
6632 else if ($x % intval($nrotat)==0 && $x < $numemails)
6633 {
6634 if($x >= intval($nrotat))
6635 echo "\n<br><span style=\"color:red;\">##############</span><b> ROTATE TO SMTP ".($curentsmtp+1)." IP: ".$mail->Host."</b><span style=\"color:red;\"> ##############</span><br><br>\n\n";
6636 }
6637 if($curentsmtp >= count($allsmtps))
6638 {
6639 $curentsmtp=0;
6640 }
6641
6642 }
6643 //END//
6644
6645 // WAITING PAUSE TIME
6646 if(!empty($pause) && !empty($pemails))
6647 {
6648 if(doubleval($pause) > 0)
6649 {
6650 if(!$isbcc)
6651 {
6652 if($x % intval($pemails) == 0 && $x < $numemails)
6653 {
6654 pause($pause,$mail);
6655 }
6656 }
6657 else if($nm > 0 && $nm % intval($pemails) == 0 && $x < $numemails && !$nopose)
6658 {
6659 pause($pause,$mail);
6660 }
6661 }
6662 }
6663 //END//
6664 }
6665 }
6666 }
6667?>