PageRenderTime 67ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/mail/smtp.php

https://bitbucket.org/wopkevries/blizzlike-313-website
PHP | 1436 lines | 1321 code | 92 blank | 23 comment | 471 complexity | f508cc96579913ad7e2c341376f4e6df MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /***************************************************************************************
  3. * *
  4. * This file is part of the XPertMailer package (http://xpertmailer.sourceforge.net/) *
  5. * *
  6. * XPertMailer is free software; you can redistribute it and/or modify it under the *
  7. * terms of the GNU General Public License as published by the Free Software *
  8. * Foundation; either version 2 of the License, or (at your option) any later version. *
  9. * *
  10. * XPertMailer is distributed in the hope that it will be useful, but WITHOUT ANY *
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
  12. * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
  13. * *
  14. * You should have received a copy of the GNU General Public License along with *
  15. * XPertMailer; if not, write to the Free Software Foundation, Inc., 51 Franklin St, *
  16. * Fifth Floor, Boston, MA 02110-1301 USA *
  17. * *
  18. * XPertMailer SMTP & POP3 PHP Mail Client. Can send and read messages in MIME Format. *
  19. * Copyright (C) 2006 Tanase Laurentiu Iulian *
  20. * *
  21. ***************************************************************************************/
  22. require_once 'func.php';
  23. require_once 'mime.php';
  24. class SMTP extends MIME {
  25. var $_smtpconn;
  26. var $_subject;
  27. var $_content;
  28. var $_arrcon;
  29. var $_arrenc;
  30. var $_port = 25;
  31. var $_unique = 0;
  32. var $_timeout = 30;
  33. var $max_cl = 99;
  34. var $max_sl = 1024;
  35. var $result = 'unknown';
  36. var $_header = false;
  37. var $_attach = false;
  38. var $_toaddrs = false;
  39. var $_ccaddrs = false;
  40. var $_bccaddrs = false;
  41. var $_fromaddr = false;
  42. var $_fromhost = false;
  43. var $_relay = false;
  44. var $_chunk = false;
  45. var $_atext = false;
  46. var $_ahtml = false;
  47. function SMTP(){
  48. //parent::MIME();
  49. $this->_smtpconn = array('local');
  50. $this->_arrcon = array('local' => '', 'client' => '', 'relay' => '');
  51. $this->_arrenc = array('7bit' => '', '8bit' => '', 'quoted-printable' => '', 'base64' => '');
  52. }
  53. function delivery($conn){
  54. $ret = false;
  55. if(is_string($conn)){
  56. $conn = trim($conn);
  57. if(FUNC::is_alpha($conn, false, '-')){
  58. $exp = explode('-', $conn);
  59. $rep = array();
  60. foreach($exp as $val){
  61. $val = strtolower($val);
  62. if(isset($this->_arrcon[$val])) $rep[] = $val;
  63. else trigger_error('Invalid connection type value "'.$val.'", on class SMTP::delivery()', 512);
  64. }
  65. if(count($rep) > 0){
  66. $this->_smtpconn = $rep;
  67. $ret = true;
  68. }
  69. }else trigger_error('Invalid parameter value, on class SMTP::delivery()', 512);
  70. }else trigger_error('Invalid parameter type value, on class SMTP::delivery()', 512);
  71. return $ret;
  72. }
  73. function port($num){
  74. $ret = false;
  75. if(is_int($num)){
  76. $this->_port = $num;
  77. $ret = true;
  78. }else trigger_error('Invalid parameter type value, on class SMTP::port()', 512);
  79. return $ret;
  80. }
  81. function timeout($num){
  82. $ret = false;
  83. if(is_int($num)){
  84. $this->_timeout = $num;
  85. $ret = true;
  86. }else trigger_error('Invalid parameter type value, on class SMTP::timeout()', 512);
  87. return $ret;
  88. }
  89. function relay($raddr, $ruser = false, $rpass = false, $rport = 25, $rauth = 'autodetect', $rvssl = false){
  90. $ret = false;
  91. if(is_string($raddr)){
  92. $raddr = FUNC::str_clear($raddr, array(' '));
  93. $raddr = trim(strtolower($raddr));
  94. if($raddr != ""){
  95. $ret = true;
  96. if(FUNC::is_ipv4($raddr)) $rvip = $raddr;
  97. else{
  98. $rvip = gethostbyname($raddr);
  99. if($rvip == $raddr){
  100. $ret = false;
  101. trigger_error('Invalid hostname value "'.$raddr.'", on class SMTP::relay()', 512);
  102. }
  103. }
  104. }else trigger_error('Invalid hostname/ip value, on class SMTP::relay()', 512);
  105. }else trigger_error('Invalid hostname/ip type value, on class SMTP::relay()', 512);
  106. if($ret){
  107. if(is_bool($ruser)){
  108. if(!$ruser) $ruser = '';
  109. else trigger_error('Invalid username 1 type value, on class SMTP::relay()', 512);
  110. }elseif(is_string($ruser)){
  111. $ruser = FUNC::str_clear($ruser);
  112. $ruser = trim($ruser);
  113. }else{
  114. $ruser = '';
  115. trigger_error('Invalid username 2 type value, on class SMTP::relay()', 512);
  116. }
  117. if(is_bool($rpass)){
  118. if(!$rpass) $rpass = '';
  119. else trigger_error('Invalid password 1 type value, on class SMTP::relay()', 512);
  120. }elseif(is_string($rpass)){
  121. $rpass = FUNC::str_clear($rpass);
  122. $rpass = trim($rpass);
  123. }else{
  124. $rpass = '';
  125. trigger_error('Invalid password type value, on class SMTP::relay()', 512);
  126. }
  127. if(($ruser != "" && $rpass == "") || ($ruser == "" && $rpass != "")){
  128. $ruser = $rpass = '';
  129. trigger_error('Invalid username and password combination value, on class SMTP::relay()', 512);
  130. }
  131. if(!is_int($rport)){
  132. $rport = 25;
  133. trigger_error('Invalid port type value, on class SMTP::relay()', 512);
  134. }
  135. if(is_string($rauth)){
  136. $rauth = trim(strtolower($rauth));
  137. if(!($rauth == "autodetect" || $rauth == "login" || $rauth == "plain")){
  138. $rauth = 'autodetect';
  139. trigger_error('Invalid auth value, on class SMTP::relay()', 512);
  140. }
  141. }else{
  142. $rauth = 'autodetect';
  143. trigger_error('Invalid auth type value, on class SMTP::relay()', 512);
  144. }
  145. if(is_string($rvssl)){
  146. $rvssl = FUNC::str_clear($rvssl);
  147. $rvssl = trim(strtolower($rvssl));
  148. if(!($rvssl == "tls" || $rvssl == "ssl")){
  149. $rvssl = false;
  150. //trigger_error('Invalid TLS/SSL value, on class SMTP::relay()', 512);
  151. }
  152. }else{
  153. if(is_bool($rvssl)){
  154. $rvssl = $rvssl ? 'tls' : false;
  155. }else{
  156. $rvssl = false;
  157. //trigger_error('Invalid TLS/SSL type value, on class SMTP::relay()', 512);
  158. }
  159. }
  160. $this->_relay = array('host' => $raddr, 'ip' => $rvip, 'user' => $ruser, 'pass' => $rpass, 'port' => $rport, 'auth' => $rauth, 'ssl' => $rvssl);
  161. }
  162. return $ret;
  163. }
  164. function addheader($hname, $hvalue, $charset = 'utf-8', $encoding = 'quoted-printable'){
  165. $ret = false;
  166. if(is_string($charset)){
  167. $charset = FUNC::str_clear($charset, array(' '));
  168. $charset = trim($charset);
  169. $charlen = strlen($charset);
  170. if(!($charlen > 1 && $charlen < 60)){
  171. $charset = 'utf-8';
  172. trigger_error('Invalid charset value, on class SMTP::addheader()', 512);
  173. }
  174. }else{
  175. $charset = 'utf-8';
  176. trigger_error('Invalid charset type value, on class SMTP::addheader()', 512);
  177. }
  178. if(is_string($encoding)){
  179. $encoding = FUNC::str_clear($encoding, array(' '));
  180. $encoding = trim(strtolower($encoding));
  181. if(!($encoding != 'quoted-printable' || $encoding != 'base64')){
  182. $encoding = 'quoted-printable';
  183. trigger_error('Invalid encoding value, on class SMTP::addheader()', 512);
  184. }
  185. }else{
  186. $encoding = 'quoted-printable';
  187. trigger_error('Invalid encoding type value, on class SMTP::addheader()', 512);
  188. }
  189. if(is_string($hname)){
  190. $hname = FUNC::str_clear($hname, array(' '));
  191. $hname = trim($hname);
  192. if($hname != ""){
  193. if(is_string($hvalue)){
  194. $hvalue = str_replace("\r\n\t", " ", $hvalue);
  195. $hvalue = FUNC::str_clear($hvalue);
  196. $hvalue = trim($hvalue);
  197. if($hvalue != ""){
  198. $vname = strtolower($hname);
  199. if($vname == "subject") trigger_error('Can not set "Subject" header value, for this, use function "Send()", on class SMTP::addheader()', 512);
  200. elseif($vname == "from") trigger_error('Can not set "From" header value, for this, use function "From()", on class SMTP::addheader()', 512);
  201. elseif($vname == "to") trigger_error('Can not set "To" header value, for this, use function "AddTo()", on class SMTP::addheader()', 512);
  202. elseif($vname == "cc") trigger_error('Can not set "Cc" header value, for this, use function "AddCc()", on class SMTP::addheader()', 512);
  203. elseif($vname == "bcc") trigger_error('Can not set "Bcc" header value, for this, use function "AddBcc()", on class SMTP::addheader()', 512);
  204. elseif($vname == "date") trigger_error('Can not set "Date" header value, this value is automaticaly set, on class SMTP::addheader()', 512);
  205. elseif($vname == "x-mailer") trigger_error('Can not set "X-Mailer" header value, this value is automaticaly set, on class SMTP::addheader()', 512);
  206. elseif($vname == "content-type") trigger_error('Can not set "Content-Type" header value, this value is automaticaly set, on class SMTP::addheader()', 512);
  207. elseif($vname == "content-transfer-encoding") trigger_error('Can not set "Content-Transfer-Encoding" header value, this value is automaticaly set, on class SMTP::addheader()', 512);
  208. elseif($vname == "content-disposition") trigger_error('Can not set "Content-Disposition" header value, this value is automaticaly set, on class SMTP::addheader()', 512);
  209. elseif($vname == "x-priority") trigger_error('Can not set "X-Priority" header value, for this, use function "Priority()", on class SMTP::addheader()', 512);
  210. elseif($vname == "x-msmail-priority") trigger_error('Can not set "X-MSMail-Priority" header value, for this, use function "Priority()", on class SMTP::addheader()', 512);
  211. elseif($vname == "mime-version") trigger_error('Can not set "MIME-Version" header value, this value is automaticaly set, on class SMTP::addheader()', 512);
  212. else{
  213. $ret = true;
  214. $this->_header[] = array('name' => ucfirst($hname), 'value' => $this->enc_header($hvalue, $charset, $encoding));
  215. }
  216. }else trigger_error('Invalid 2\'nd parameter value, on class SMTP::addheader()', 512);
  217. }else trigger_error('Invalid 2\'nd parameter type value, on class SMTP::addheader()', 512);
  218. }else trigger_error('Invalid 1\'st parameter value, on class SMTP::addheader()', 512);
  219. }else trigger_error('Invalid 1\'st parameter type value, on class SMTP::addheader()', 512);
  220. return $ret;
  221. }
  222. function delheader($hname){
  223. $ret = false;
  224. if(is_string($hname)){
  225. $hname = FUNC::str_clear($hname, array(' '));
  226. $hname = trim($hname);
  227. if($hname != ""){
  228. if($this->_header && count($this->_header) > 0){
  229. $reparr = array();
  230. foreach($this->_header as $harr){
  231. if(strtolower($harr['name']) != strtolower($hname)) $reparr[] = $harr;
  232. else $ret = true;
  233. }
  234. $this->_header = $reparr;
  235. }
  236. }else trigger_error('Invalid parameter value, on class SMTP::delheader()', 512);
  237. }else trigger_error('Invalid parameter type value, on class SMTP::delheader()', 512);
  238. return $ret;
  239. }
  240. function addto($adrr, $name = ''){
  241. $ret = false;
  242. if(is_string($adrr)){
  243. $adrr = FUNC::str_clear($adrr, array(' '));
  244. $adrr = strtolower(trim($adrr));
  245. if($adrr != "" && FUNC::is_mail($adrr)){
  246. if(!isset($this->_toaddrs[$adrr])){
  247. $this->_toaddrs[$adrr] = '';
  248. $ret = true;
  249. if(is_string($name)){
  250. $name = FUNC::str_clear($name);
  251. $name = trim($name);
  252. if($name != "") $this->_toaddrs[$adrr] = $name;
  253. }else trigger_error('Invalid 2\'nd parameter type value, on class SMTP::addto()', 512);
  254. }else trigger_error('Already exists, on class SMTP::addto()', 512);
  255. }else trigger_error('Invalid 1\'st parameter value, on class SMTP::addto()', 512);
  256. }else trigger_error('Invalid 1\'st parameter type value, on class SMTP::addto()', 512);
  257. return $ret;
  258. }
  259. function delto($adrr = 'all'){
  260. $ret = false;
  261. if(is_string($adrr)){
  262. $adrr = FUNC::str_clear($adrr, array(' '));
  263. $adrr = strtolower(trim($adrr));
  264. if($adrr != ""){
  265. if($adrr == "all"){
  266. $this->_toaddrs = false;
  267. $ret = true;
  268. }elseif(FUNC::is_mail($adrr)){
  269. if(is_array($this->_toaddrs) && count($this->_toaddrs) > 0){
  270. $reb = array();
  271. foreach($this->_toaddrs as $num => $val){
  272. if($num != $adrr) $reb[$num] = $val;
  273. else $ret = true;
  274. }
  275. $this->_toaddrs = $reb;
  276. }
  277. }else trigger_error('Invalid 2 parameter value, on class SMTP::delto()', 512);
  278. }else trigger_error('Invalid 1 parameter value, on class SMTP::delto()', 512);
  279. }else trigger_error('Invalid parameter type value, on class SMTP::delto()', 512);
  280. return $ret;
  281. }
  282. function addcc($adrr, $name = ''){
  283. $ret = false;
  284. if(is_string($adrr)){
  285. $adrr = FUNC::str_clear($adrr, array(' '));
  286. $adrr = strtolower(trim($adrr));
  287. if($adrr != "" && FUNC::is_mail($adrr)){
  288. if(!isset($this->_ccaddrs[$adrr])){
  289. $this->_ccaddrs[$adrr] = '';
  290. $ret = true;
  291. if(is_string($name)){
  292. $name = FUNC::str_clear($name);
  293. $name = trim($name);
  294. if($name != "") $this->_ccaddrs[$adrr] = $name;
  295. }else trigger_error('Invalid 2\'nd parameter type value, on class SMTP::addcc()', 512);
  296. }else trigger_error('Already exists, on class SMTP::addcc()', 512);
  297. }else trigger_error('Invalid 1\'st parameter value, on class SMTP::addcc()', 512);
  298. }else trigger_error('Invalid 1\'st parameter type value, on class SMTP::addcc()', 512);
  299. return $ret;
  300. }
  301. function delcc($adrr = 'all'){
  302. $ret = false;
  303. if(is_string($adrr)){
  304. $adrr = FUNC::str_clear($adrr, array(' '));
  305. $adrr = strtolower(trim($adrr));
  306. if($adrr != ""){
  307. if($adrr == "all"){
  308. $this->_ccaddrs = false;
  309. $ret = true;
  310. }elseif(FUNC::is_mail($adrr)){
  311. if(is_array($this->_ccaddrs) && count($this->_ccaddrs) > 0){
  312. $reb = array();
  313. foreach($this->_ccaddrs as $num => $val){
  314. if($num != $adrr) $reb[$num] = $val;
  315. else $ret = true;
  316. }
  317. $this->_ccaddrs = $reb;
  318. }
  319. }else trigger_error('Invalid 2 parameter value, on class SMTP::delcc()', 512);
  320. }else trigger_error('Invalid 1 parameter value, on class SMTP::delcc()', 512);
  321. }else trigger_error('Invalid parameter type value, on class SMTP::delcc()', 512);
  322. return $ret;
  323. }
  324. function addbcc($adrr){
  325. $ret = false;
  326. if(is_string($adrr)){
  327. $adrr = FUNC::str_clear($adrr, array(' '));
  328. $adrr = strtolower(trim($adrr));
  329. if($adrr != "" && FUNC::is_mail($adrr)){
  330. if(!isset($this->_bccaddrs[$adrr])){
  331. $this->_bccaddrs[$adrr] = '';
  332. $ret = true;
  333. }else trigger_error('Already exists, on class SMTP::addbcc()', 512);
  334. }else trigger_error('Invalid parameter value, on class SMTP::addbcc()', 512);
  335. }else trigger_error('Invalid parameter type value, on class SMTP::addbcc()', 512);
  336. return $ret;
  337. }
  338. function delbcc($adrr = 'all'){
  339. $ret = false;
  340. if(is_string($adrr)){
  341. $adrr = FUNC::str_clear($adrr, array(' '));
  342. $adrr = strtolower(trim($adrr));
  343. if($adrr != ""){
  344. if($adrr == "all"){
  345. $this->_bccaddrs = false;
  346. $ret = true;
  347. }elseif(FUNC::is_mail($adrr)){
  348. if(is_array($this->_bccaddrs) && count($this->_bccaddrs) > 0){
  349. $reb = array();
  350. foreach($this->_bccaddrs as $num => $val){
  351. if($num != $adrr) $reb[$num] = $val;
  352. else $ret = true;
  353. }
  354. $this->_bccaddrs = $reb;
  355. }
  356. }else trigger_error('Invalid 2 parameter value, on class SMTP::delbcc()', 512);
  357. }else trigger_error('Invalid 1 parameter value, on class SMTP::delbcc()', 512);
  358. }else trigger_error('Invalid parameter type value, on class SMTP::delbcc()', 512);
  359. return $ret;
  360. }
  361. function from($adrr, $name = ''){
  362. $this->_fromaddr = $ret = false;
  363. if(is_string($adrr)){
  364. $adrr = FUNC::str_clear($adrr, array(' '));
  365. $adrr = strtolower(trim($adrr));
  366. if($adrr != "" && FUNC::is_mail($adrr)){
  367. $ret = true;
  368. $this->_fromaddr = array('address' => $adrr, 'name' => '');
  369. if(is_string($name)){
  370. $name = FUNC::str_clear($name);
  371. $name = trim($name);
  372. if($name != "") $this->_fromaddr = array('address' => $adrr, 'name' => $name);
  373. }else trigger_error('Invalid 2\'nd parameter type value, on class SMTP::from()', 512);
  374. }else trigger_error('Invalid mail address format, on class SMTP::from()', 512);
  375. }else trigger_error('Invalid first parameter type value, on class SMTP::from()', 512);
  376. return $ret;
  377. }
  378. function fromhost($server, &$havemx){
  379. $this->_fromhost = $ret = $havemx = false;
  380. if(is_string($server)){
  381. $server = FUNC::str_clear($server, array(' '));
  382. $server = strtolower(trim($server));
  383. if($server != ""){
  384. $ret = true;
  385. $this->_fromhost = $server;
  386. if(FUNC::is_hostname($server)){
  387. $havemx = FUNC::is_win() ? FUNC::getmxrr_win($server, $mxhost) : getmxrr($server, $mxhost);
  388. }
  389. }else trigger_error('Invalid parameter value, on class SMTP::fromhost()', 512);
  390. }else trigger_error('Invalid parameter type value, on class SMTP::fromhost()', 512);
  391. return $ret;
  392. }
  393. function text($text, $charset = 'us-ascii', $encoding = 'quoted-printable', $disposition = 'inline'){
  394. $this->_atext = $ret = false;
  395. if(is_string($charset)){
  396. $charset = FUNC::str_clear($charset, array(' '));
  397. $charset = trim($charset);
  398. $charlen = strlen($charset);
  399. if(!($charlen > 1 && $charlen < 60)){
  400. $charset = 'us-ascii';
  401. trigger_error('Invalid charset value, on class SMTP::text()', 512);
  402. }
  403. }else{
  404. $charset = 'us-ascii';
  405. trigger_error('Invalid charset type value, on class SMTP::text()', 512);
  406. }
  407. if(is_string($encoding)){
  408. $encoding = FUNC::str_clear($encoding, array(' '));
  409. $encoding = trim(strtolower($encoding));
  410. if(!($encoding != "" && isset($this->_arrenc[$encoding]))){
  411. $encoding = 'quoted-printable';
  412. trigger_error('Invalid encoding value, on class SMTP::text()', 512);
  413. }
  414. }else{
  415. $encoding = 'quoted-printable';
  416. trigger_error('Invalid encoding type value, on class SMTP::text()', 512);
  417. }
  418. if(is_string($disposition)){
  419. $disposition = FUNC::str_clear($disposition, array(' '));
  420. $disposition = trim(strtolower($disposition));
  421. if(!($disposition == "attachment" || $disposition == "inline")){
  422. $disposition = 'inline';
  423. trigger_error('Invalid disposition value, on class SMTP::text()', 512);
  424. }
  425. }else{
  426. $disposition = 'inline';
  427. trigger_error('Invalid disposition type value, on class SMTP::text()', 512);
  428. }
  429. if(is_string($text)){
  430. $text = trim($text);
  431. if($text != ""){
  432. $htext = 'Content-Type: text/plain;'.$this->_crlf."\t".'charset="'.$charset.'"'.$this->_crlf.
  433. 'Content-Transfer-Encoding: '.$encoding.$this->_crlf.
  434. 'Content-Disposition: '.$disposition;
  435. $this->_atext = array($htext, $encoding, $text);
  436. $ret = true;
  437. }else trigger_error('Invalid text/plain value, on class SMTP::text()', 512);
  438. }else trigger_error('Invalid text/plain type value, on class SMTP::text()', 512);
  439. return $ret;
  440. }
  441. function html($html, $charset = 'us-ascii', $encoding = 'quoted-printable', $disposition = 'inline'){
  442. $this->_ahtml = $ret = false;
  443. if(is_string($charset)){
  444. $charset = FUNC::str_clear($charset, array(' '));
  445. $charset = trim($charset);
  446. $charlen = strlen($charset);
  447. if(!($charlen > 1 && $charlen < 60)){
  448. $charset = 'us-ascii';
  449. trigger_error('Invalid charset value, on class SMTP::html()', 512);
  450. }
  451. }else{
  452. $charset = 'us-ascii';
  453. trigger_error('Invalid charset type value, on class SMTP::html()', 512);
  454. }
  455. if(is_string($encoding)){
  456. $encoding = FUNC::str_clear($encoding, array(' '));
  457. $encoding = trim(strtolower($encoding));
  458. if(!($encoding != "" && isset($this->_arrenc[$encoding]))){
  459. $encoding = 'quoted-printable';
  460. trigger_error('Invalid encoding value, on class SMTP::html()', 512);
  461. }
  462. }else{
  463. $encoding = 'quoted-printable';
  464. trigger_error('Invalid encoding type value, on class SMTP::html()', 512);
  465. }
  466. if(is_string($disposition)){
  467. $disposition = FUNC::str_clear($disposition, array(' '));
  468. $disposition = trim(strtolower($disposition));
  469. if(!($disposition == "attachment" || $disposition == "inline")){
  470. $disposition = 'inline';
  471. trigger_error('Invalid disposition value, on class SMTP::html()', 512);
  472. }
  473. }else{
  474. $disposition = 'inline';
  475. trigger_error('Invalid disposition type value, on class SMTP::html()', 512);
  476. }
  477. if(is_string($html)){
  478. $html = trim($html);
  479. if($html != ""){
  480. $hhtml = 'Content-Type: text/html;'.$this->_crlf."\t".'charset="'.$charset.'"'.$this->_crlf.
  481. 'Content-Transfer-Encoding: '.$encoding.$this->_crlf.
  482. 'Content-Disposition: '.$disposition;
  483. $this->_ahtml = array($hhtml, $encoding, $html);
  484. $ret = true;
  485. }else trigger_error('Invalid text/html value, on class SMTP::html()', 512);
  486. }else trigger_error('Invalid text/html type value, on class SMTP::html()', 512);
  487. return $ret;
  488. }
  489. function attachsource($source, $name, $mimetype = 'autodetect', $disposition = 'attachment', $encoding = 'base64'){
  490. $ret = false;
  491. if(is_string($source) && $source != ""){
  492. if(is_string($name)){
  493. $name = FUNC::str_clear($name);
  494. $name = trim($name);
  495. if($name != ""){
  496. $ret = true;
  497. $mime = 'application/octet-stream';
  498. if(is_string($mimetype)){
  499. $mimetype = FUNC::str_clear($mimetype, array(' '));
  500. $mimetype = trim(strtolower($mimetype));
  501. $mime = ($mimetype == "autodetect" || $mimetype == "") ? FUNC::mimetype($name) : $mimetype;
  502. }
  503. $disp = 'attachment';
  504. if(is_string($disposition)){
  505. $disposition = FUNC::str_clear($disposition, array(' '));
  506. $disposition = trim(strtolower($disposition));
  507. if($disposition == "attachment" || $disposition == "inline") $disp = $disposition;
  508. else trigger_error('Invalid disposition value, on class SMTP::attachsource()', 512);
  509. }else trigger_error('Invalid disposition type value, on class SMTP::attachsource()', 512);
  510. $encode = 'base64';
  511. if(is_string($encoding)){
  512. $encoding = FUNC::str_clear($encoding, array(' '));
  513. $encoding = trim(strtolower($encoding));
  514. if($encoding != "" && isset($this->_arrenc[$encoding])) $encode = $encoding;
  515. else trigger_error('Invalid encoding value, on class SMTP::attachsource()', 512);
  516. }else trigger_error('Invalid encoding type value, on class SMTP::attachsource()', 512);
  517. $this->_attach[] = array('name' => $name, 'mime' => $mime, 'disp' => $disp, 'encode' => $encode, 'source' => $source);
  518. }else trigger_error('Invalid name value, on class SMTP::attachsource()', 512);
  519. }else trigger_error('Invalid name type value, on class SMTP::attachsource()', 512);
  520. }else trigger_error('Invalid source value, on class SMTP::attachsource()', 512);
  521. return $ret;
  522. }
  523. function attachfile($file, $name = false, $mimetype = 'autodetect', $disposition = 'attachment', $encoding = 'base64'){
  524. $ret = false;
  525. if(is_string($file)){
  526. $file = FUNC::str_clear($file);
  527. $file = trim($file);
  528. if($file != "" && is_file($file) && is_readable($file)){
  529. if((is_bool($name) && !$name) || (is_string($name) && $name == '')){
  530. $exp1 = explode("/", $file);
  531. $name = $exp1[count($exp1)-1];
  532. $exp2 = explode("\\", $name);
  533. $name = $exp2[count($exp2)-1];
  534. }
  535. $ret = $this->attachsource(file_get_contents($file), $name, $mimetype, $disposition, $encoding);
  536. }else trigger_error('Invalid file source, on class SMTP::attachfile()', 512);
  537. }else trigger_error('Invalid file type value, on class SMTP::attachfile()', 512);
  538. return $ret;
  539. }
  540. function delattach($name = true){
  541. $ret = false;
  542. if(is_bool($name)){
  543. if($name){
  544. $this->_attach = false;
  545. $ret = true;
  546. }else trigger_error('Invalid 2 file name type value, on class SMTP::delattach()', 512);
  547. }elseif(is_string($name)){
  548. $name = trim($name);
  549. if($name != ""){
  550. if($this->_attach && count($this->_attach) > 0){
  551. $rebatt = array();
  552. foreach($this->_attach as $attarr){
  553. if($attarr['name'] != $name) $rebatt[] = $attarr;
  554. else $ret = true;
  555. }
  556. if($ret) $this->_attach = $rebatt;
  557. }
  558. }else trigger_error('Invalid file name value, on class SMTP::delattach()', 512);
  559. }else trigger_error('Invalid file name type value, on class SMTP::delattach()', 512);
  560. return $ret;
  561. }
  562. function priority($level = 3){
  563. $ret = $set = false;
  564. if(is_int($level)){
  565. if($level == 1) $set = array('1', 'High');
  566. elseif($level == 3) $set = array('3', 'Normal');
  567. elseif($level == 5) $set = array('5', 'Low');
  568. else trigger_error('Invalid 1 parameter value, on class SMTP::priority()', 512);
  569. }elseif(is_string($level)){
  570. $level = FUNC::str_clear($level, array(' '));
  571. $level = trim(strtolower($level));
  572. if($level == "high") $set = array('1', 'High');
  573. elseif($level == "normal") $set = array('3', 'Normal');
  574. elseif($level == "low") $set = array('5', 'Low');
  575. else trigger_error('Invalid 2 parameter value, on class SMTP::priority()', 512);
  576. }else trigger_error('Invalid parameter type value, on class SMTP::priority()', 512);
  577. if($set){
  578. $this->delheader('X-Priority');
  579. $this->delheader('X-MSMail-Priority');
  580. $this->_header[] = array('name' => 'X-Priority', 'value' => $set[0]);
  581. $this->_header[] = array('name' => 'X-MSMail-Priority', 'value' => $set[1]);
  582. $ret = true;
  583. }
  584. return $ret;
  585. }
  586. function _sendtoip($ip, $arrto, $isrelay){
  587. $ssl = '';
  588. $pnm = $this->_port;
  589. if($isrelay){
  590. $ssl = $this->_relay['ssl'] ? $this->_relay['ssl'].'://' : '';
  591. $pnm = $this->_relay['port'];
  592. }
  593. if(!$sock = fsockopen($ssl.$ip, $pnm, $errnum, $errmsg, $this->_timeout)){
  594. $this->result = 'Error 10: '.$errmsg;
  595. return false;
  596. }
  597. stream_set_timeout($sock, $this->_timeout);
  598. $loop = $rcv = 0;
  599. while(!feof($sock)){
  600. $loop++;
  601. if($rcv = fgets($sock, $this->max_sl)){
  602. if($loop == $this->max_cl || substr($rcv, 0, 4) != "220-") break;
  603. }else break;
  604. }
  605. if(!$rcv){
  606. $this->result = 'Error 11: can\'t read';
  607. return false;
  608. }
  609. if(substr($rcv, 0, 4) != "220 "){
  610. $this->result = 'Error 12: '.$rcv;
  611. return false;
  612. }
  613. if(!FUNC::is_connection($sock)){
  614. $this->result = 'Error 13: invalid resource connection';
  615. return false;
  616. }
  617. if($isrelay && $this->_relay['user'] != "" && $this->_relay['pass'] != ""){
  618. if(!fputs($sock, 'EHLO '.$this->_fromhost.$this->_crlf)){
  619. $this->result = 'Error 20: can\'t write';
  620. return false;
  621. }
  622. $loop = $rcv = 0;
  623. $getinfo = '';
  624. while(!feof($sock)){
  625. $loop++;
  626. if($rcv = fgets($sock, $this->max_sl)){
  627. $getinfo .= $rcv;
  628. if($loop == $this->max_cl || substr($rcv, 0, 4) != "250-") break;
  629. }else break;
  630. }
  631. if(!$rcv){
  632. $this->result = 'Error 21: can\'t read';
  633. return false;
  634. }
  635. if(substr($rcv, 0, 4) != "250 "){
  636. if(!FUNC::is_connection($sock)){
  637. $this->result = 'Error 22: invalid resource connection';
  638. return false;
  639. }
  640. if(!fputs($sock, 'HELO '.$this->_fromhost.$this->_crlf)){
  641. $this->result = 'Error 23: can\'t write';
  642. return false;
  643. }
  644. $loop = $rcv = 0;
  645. $getinfo = '';
  646. while(!feof($sock)){
  647. $loop++;
  648. if($rcv = fgets($sock, $this->max_sl)){
  649. $getinfo .= $rcv;
  650. if($loop == $this->max_cl || substr($rcv, 0, 4) != "250-") break;
  651. }else break;
  652. }
  653. if(!$rcv){
  654. $this->result = 'Error 24: can\'t read';
  655. return false;
  656. }
  657. if(substr($rcv, 0, 4) != "250 "){
  658. $this->result = 'Error 25: '.$rcv;
  659. return false;
  660. }
  661. }
  662. $authlogin = strstr($getinfo, 'LOGIN');
  663. $authplain = strstr($getinfo, 'PLAIN');
  664. $authtype = 'login';
  665. if($this->_relay['auth'] == "autodetect" || $this->_relay['auth'] == "login"){
  666. if(!$authlogin){
  667. if($authplain) $authtype = 'plain';
  668. }
  669. }elseif($this->_relay['auth'] == "plain"){
  670. if($authplain) $authtype = 'plain';
  671. }
  672. if(!FUNC::is_connection($sock)){
  673. $this->result = 'Error 26: invalid resource connection';
  674. return false;
  675. }
  676. if($authtype == "login"){
  677. if(!fputs($sock, 'AUTH LOGIN'.$this->_crlf)){
  678. $this->result = 'Error 270: can\'t write';
  679. return false;
  680. }
  681. if(!$rcv = fgets($sock, $this->max_sl)){
  682. $this->result = 'Error 271: can\'t read';
  683. return false;
  684. }
  685. if(substr($rcv, 0, 4) != "334 "){
  686. $this->result = 'Error 272: '.$rcv;
  687. return false;
  688. }
  689. if(!FUNC::is_connection($sock)){
  690. $this->result = 'Error 273: invalid resource connection';
  691. return false;
  692. }
  693. if(!fputs($sock, base64_encode($this->_relay['user']).$this->_crlf)){
  694. $this->result = 'Error 274: can\'t write';
  695. return false;
  696. }
  697. if(!$rcv = fgets($sock, $this->max_sl)){
  698. $this->result = 'Error 275: can\'t read';
  699. return false;
  700. }
  701. if(substr($rcv, 0, 4) != "334 "){
  702. $this->result = 'Error 276: '.$rcv;
  703. return false;
  704. }
  705. if(!FUNC::is_connection($sock)){
  706. $this->result = 'Error 277: invalid resource connection';
  707. return false;
  708. }
  709. if(!fputs($sock, base64_encode($this->_relay['pass']).$this->_crlf)){
  710. $this->result = 'Error 278: can\'t write';
  711. return false;
  712. }
  713. if(!$rcv = fgets($sock, $this->max_sl)){
  714. $this->result = 'Error 279: can\'t read';
  715. return false;
  716. }
  717. if(substr($rcv, 0, 4) != "235 "){
  718. $this->result = 'Error 280: '.$rcv;
  719. return false;
  720. }
  721. }elseif($authtype == "plain"){
  722. if(!FUNC::is_connection($sock)){
  723. $this->result = 'Error 281: invalid resource connection';
  724. return false;
  725. }
  726. if(!fputs($sock, 'AUTH PLAIN '.base64_encode($this->_relay['user'].chr(0).$this->_relay['user'].chr(0).$this->_relay['pass']).$this->_crlf)){
  727. $this->result = 'Error 282: can\'t write';
  728. return false;
  729. }
  730. if(!$rcv = fgets($sock, $this->max_sl)){
  731. $this->result = 'Error 283: can\'t read';
  732. return false;
  733. }
  734. if(substr($rcv, 0, 4) != "235 "){
  735. $this->result = 'Error 284: '.$rcv;
  736. return false;
  737. }
  738. }
  739. }else{
  740. if(!fputs($sock, 'HELO '.$this->_fromhost.$this->_crlf)){
  741. $this->result = 'Error 30: can\'t write';
  742. return false;
  743. }
  744. $loop = $rcv = 0;
  745. while(!feof($sock)){
  746. $loop++;
  747. if(!$rcv = fgets($sock, $this->max_sl)){
  748. if($loop == $this->max_cl || substr($rcv, 0, 4) != "250-") break;
  749. }else break;
  750. }
  751. if(!$rcv){
  752. $this->result = 'Error 31: can\'t read';
  753. return false;
  754. }
  755. if(substr($rcv, 0, 4) != "250 "){
  756. if(!FUNC::is_connection($sock)){
  757. $this->result = 'Error 32: invalid resource connection';
  758. return false;
  759. }
  760. if(!fputs($sock, 'EHLO '.$this->_fromhost.$this->_crlf)){
  761. $this->result = 'Error 33: can\'t write';
  762. return false;
  763. }
  764. $loop = $rcv = 0;
  765. while(!feof($sock)){
  766. $loop++;
  767. if(!$rcv = fgets($sock, $this->max_sl)){
  768. if($loop == $this->max_cl || substr($rcv, 0, 4) != "250-") break;
  769. }else break;
  770. }
  771. if(!$rcv){
  772. $this->result = 'Error 34: can\'t read';
  773. return false;
  774. }
  775. if(substr($rcv, 0, 4) != "250 "){
  776. $this->result = 'Error 35: '.$rcv;
  777. return false;
  778. }
  779. }
  780. }
  781. if(!FUNC::is_connection($sock)){
  782. $this->result = 'Error 40: invalid resource connection';
  783. return false;
  784. }
  785. if(!fputs($sock, 'MAIL FROM:<'.$this->_fromaddr['address'].'>'.$this->_crlf)){
  786. $this->result = 'Error 41: can\'t write';
  787. return false;
  788. }
  789. if(!$rcv = fgets($sock, $this->max_sl)){
  790. $this->result = 'Error 42: can\'t read';
  791. return false;
  792. }
  793. if(substr($rcv, 0, 4) != "250 "){
  794. $this->result = 'Error 43: '.$rcv;
  795. return false;
  796. }
  797. $relayh = $isrelay ? '@'.$this->_relay['host'].':' : '';
  798. $setver = true;
  799. foreach($arrto as $arrval){
  800. if(!FUNC::is_connection($sock)){
  801. $this->result = 'Error 50: invalid resource connection';
  802. $setver = false;
  803. break;
  804. }
  805. if(!fputs($sock, 'RCPT TO:<'.$relayh.$arrval.'>'.$this->_crlf)){
  806. $this->result = 'Error 51: can\'t write';
  807. $setver = false;
  808. break;
  809. }
  810. if(!$rcv = fgets($sock, $this->max_sl)){
  811. $this->result = 'Error 52: can\'t read';
  812. $setver = false;
  813. break;
  814. }
  815. $submsg = substr($rcv, 0, 4);
  816. if(!($submsg == "250 " || $submsg == "251 ")){
  817. $this->result = 'Error 53: '.$rcv;
  818. $setver = false;
  819. break;
  820. }
  821. }
  822. if(!$setver) return false;
  823. if(!FUNC::is_connection($sock)){
  824. $this->result = 'Error 60: invalid resource connection';
  825. return false;
  826. }
  827. if(!fputs($sock, 'DATA'.$this->_crlf)){
  828. $this->result = 'Error 61: can\'t write';
  829. return false;
  830. }
  831. if(!$rcv = fgets($sock, $this->max_sl)){
  832. $this->result = 'Error 62: can\'t read';
  833. return false;
  834. }
  835. if(substr($rcv, 0, 4) != "354 "){
  836. $this->result = 'Error 63: '.$rcv;
  837. return false;
  838. }
  839. if(!FUNC::is_connection($sock)){
  840. $this->result = 'Error 70: invalid resource connection';
  841. return false;
  842. }
  843. if(!fputs($sock, $this->_content['header']['client'])){
  844. $this->result = 'Error 71: can\'t write';
  845. return false;
  846. }
  847. $setver = true;
  848. foreach($this->_content['body'] as $partmsg){
  849. if(!FUNC::is_connection($sock)){
  850. $this->result = 'Error 72: invalid resource connection';
  851. $setver = false;
  852. break;
  853. }
  854. if(!fputs($sock, $partmsg)){
  855. $this->result = 'Error 73: can\'t write';
  856. $setver = false;
  857. break;
  858. }
  859. }
  860. if(!$setver) return false;
  861. if(!FUNC::is_connection($sock)){
  862. $this->result = 'Error 80: invalid resource connection';
  863. return false;
  864. }
  865. if(!fputs($sock, $this->_crlf.'.'.$this->_crlf)){
  866. $this->result = 'Error 81: can\'t write';
  867. return false;
  868. }
  869. if(!$rcv = fgets($sock, $this->max_sl)){
  870. $this->result = 'Error 82: can\'t read';
  871. return false;
  872. }
  873. if(substr($rcv, 0, 4) != "250 "){
  874. $this->result = 'Error 83: '.$rcv;
  875. return false;
  876. }
  877. if(FUNC::is_connection($sock)){
  878. if(fputs($sock, 'RSET'.$this->_crlf)){
  879. if(FUNC::is_connection($sock)){
  880. if($rcvr = @fgets($sock, $this->max_sl)){
  881. if(substr($rcvr, 0, 3) == "250"){
  882. if(fputs($sock, 'QUIT'.$this->_crlf)){
  883. if(FUNC::is_connection($sock)){
  884. if($rcvq = @fgets($sock, $this->max_sl)) $rcv = $rcvq;
  885. FUNC::close($sock);
  886. }
  887. }
  888. }
  889. }
  890. }
  891. }
  892. }
  893. $this->result = 'Success: '.$rcv;
  894. return true;
  895. }
  896. function _sendtohost($hname, $arrto, $isrelay){
  897. $ret = false;
  898. if($hname == "localhost"){
  899. $ret = mail($this->_content['header']['to'], $this->_subject, implode('', $this->_content['body']), $this->_content['header']['local']);
  900. if(!$ret) $ret = $this->_sendtoip('127.0.0.1', $arrto, $isrelay);
  901. }else{
  902. if($isrelay) $ret = $this->_sendtoip($hname, $arrto, $isrelay);
  903. else{
  904. if(FUNC::is_ipv4($hname)) $ret = $this->_sendtoip($hname, $arrto, $isrelay);
  905. else{
  906. $resmx = FUNC::is_win() ? FUNC::getmxrr_win($hname, $mxhost) : getmxrr($hname, $mxhost);
  907. $iparr = array();
  908. if($resmx){
  909. foreach($mxhost as $hostname){
  910. $iphost = gethostbyname($hostname);
  911. if($iphost != $hname && FUNC::is_ipv4($iphost) && !isset($iparr[$iphost])) $iparr[$iphost] = $iphost;
  912. }
  913. }else{
  914. $iphost = gethostbyname($hname);
  915. if($iphost != $hname && FUNC::is_ipv4($iphost)) $iparr[$iphost] = $iphost;
  916. }
  917. if(count($iparr) > 0){
  918. foreach($iparr as $ipaddr) if($ret = $this->_sendtoip($ipaddr, $arrto, $isrelay)) break;
  919. }else trigger_error('Can not find any valid ip address for hostname "'.$hname.'", on class SMTP::_sendtohost()', 512);
  920. }
  921. }
  922. }
  923. return $ret;
  924. }
  925. function _splitmsg($longmsg, $approx = 10240){
  926. $longmsg = str_replace(array(".\r\n", ".\n", ".\r"), ". ".$this->_crlf, $longmsg);
  927. $msgarr = explode($this->_crlf, $longmsg);
  928. $addmsg = "";
  929. $arrmsg = array();
  930. foreach($msgarr as $inline){
  931. $addmsg .= $inline.$this->_crlf;
  932. if(strlen($addmsg) >= $approx){
  933. $arrmsg[] = $addmsg;
  934. $addmsg = "";
  935. }
  936. }
  937. if(count($arrmsg) > 0 && $addmsg != "") $arrmsg[] = $addmsg;
  938. else $arrmsg[] = $longmsg;
  939. return $arrmsg;
  940. }
  941. function _getunique(){
  942. return md5(microtime(1).$this->_unique++);
  943. }
  944. function _putcid($str, $ids){
  945. $find1 = $repl1 = array();
  946. foreach($ids as $name => $code){
  947. $find1[] = "=\"".$name;
  948. $repl1[] = "=\"cid:".$code;
  949. $find2[] = "=".$name;
  950. $repl2[] = "=cid:".$code;
  951. }
  952. $res = str_replace($find1, $repl1, $str);
  953. $res = str_replace($find2, $repl2, $res);
  954. return $res;
  955. }
  956. function _encodemsg($src, $enc){
  957. $res = '';
  958. if($enc == "7bit" || $enc == "8bit") $res .= chunk_split($src, $this->_chunklen, $this->_crlf);
  959. elseif($enc == "base64") $res .= chunk_split(base64_encode($src), $this->_chunklen, $this->_crlf);
  960. elseif($enc == "quoted-printable") $res .= $this->qpencode($src, $this->_chunklen, $this->_crlf);
  961. return $res;
  962. }
  963. function _writemsg(){
  964. if(!$this->_fromaddr){
  965. $fromaddr = ini_get('sendmail_from');
  966. if($fromaddr == ""){
  967. if(isset($_SERVER['SERVER_ADMIN']) && FUNC::is_mail($_SERVER['SERVER_ADMIN'])) $fromaddr = $_SERVER['SERVER_ADMIN'];
  968. elseif(isset($_SERVER['SERVER_NAME'])) $fromaddr = 'postmaster@'.$_SERVER['SERVER_NAME'];
  969. elseif(isset($_SERVER['HTTP_HOST'])) $fromaddr = 'postmaster@'.$_SERVER['HTTP_HOST'];
  970. elseif(isset($_SERVER['REMOTE_ADDR'])) $fromaddr = 'postmaster@'.$_SERVER['REMOTE_ADDR'];
  971. elseif(isset($_SERVER['SERVER_ADDR'])) $fromaddr = 'postmaster@'.$_SERVER['SERVER_ADDR'];
  972. else $fromaddr = 'postmaster@localhost';
  973. }
  974. $this->_fromaddr = array('address' => $fromaddr, 'name' => '');
  975. }
  976. if(!$this->_fromhost){
  977. if(isset($_SERVER['SERVER_NAME'])) $this->_fromhost = $_SERVER['SERVER_NAME'];
  978. elseif(isset($_SERVER['HTTP_HOST'])) $this->_fromhost = $_SERVER['HTTP_HOST'];
  979. elseif(isset($_SERVER['REMOTE_ADDR'])) $this->_fromhost = $_SERVER['REMOTE_ADDR'];
  980. elseif(isset($_SERVER['SERVER_ADDR'])) $this->_fromhost = $_SERVER['SERVER_ADDR'];
  981. else{
  982. $fexp = explode('@', $this->_fromaddr['address']);
  983. $this->_fromhost = $fexp[1];
  984. }
  985. }
  986. $tostr = $ccstr = $bccstr = '';
  987. foreach($this->_toaddrs as $taddr => $tname){
  988. if($tname == "") $tostr .= $taddr.', ';
  989. else $tostr .= '"'.str_replace('"', '\\"', $tname).'" <'.$taddr.'>, ';
  990. }
  991. $tostr = $hto = substr($tostr, 0, -2);
  992. if($this->_ccaddrs && count($this->_ccaddrs) > 0){
  993. foreach($this->_ccaddrs as $caddr => $cname){
  994. if($cname == "") $ccstr .= $caddr.', ';
  995. else $ccstr .= '"'.str_replace('"', '\\"', $cname).'" <'.$caddr.'>, ';
  996. }
  997. $ccstr = substr($ccstr, 0, -2);
  998. }
  999. if($this->_bccaddrs && count($this->_bccaddrs) > 0){
  1000. foreach($this->_bccaddrs as $baddr => $bname) $bccstr .= $baddr.', ';
  1001. $bccstr = substr($bccstr, 0, -2);
  1002. }
  1003. if($this->_fromaddr['name'] == "") $fromstr = $this->_fromaddr['address'];
  1004. else $fromstr = '"'.str_replace('"', '\\"', $this->_fromaddr['name']).'" <'.$this->_fromaddr['address'].'>';
  1005. $arrval1 = $arrval2 = array();
  1006. $arrval1[] = array('name' => 'From', 'value' => $fromstr);
  1007. $arrval2[] = array('name' => 'From', 'value' => $fromstr);
  1008. $arrval2[] = array('name' => 'To', 'value' => $tostr);
  1009. $arrval2[] = array('name' => 'Subject', 'value' => $this->_subject);
  1010. if($ccstr != ""){
  1011. $arrval1[] = array('name' => 'Cc', 'value' => $ccstr);
  1012. $arrval2[] = array('name' => 'Cc', 'value' => $ccstr);
  1013. }
  1014. if($bccstr != "") $arrval1[] = array('name' => 'Bcc', 'value' => $bccstr);
  1015. $arrval2[] = array('name' => 'Date', 'value' => date('r'));
  1016. if($this->_header && count($this->_header) > 0){
  1017. foreach($this->_header as $hvarr){
  1018. $arrval1[] = $hvarr;
  1019. $arrval2[] = $hvarr;
  1020. }
  1021. }
  1022. $xmail = array('name' => base64_decode('WC1NYWlsZXI='), 'value' => base64_decode('WFBNMiB2LjAuMiA8d3d3LnhwZXJ0bWFpbGVyLmNvbT4='));
  1023. $arrval1[] = $xmail;
  1024. $arrval2[] = $xmail;
  1025. $hval1 = $hval2 = $bval = '';
  1026. foreach($arrval1 as $heach1) $hval1 .= $heach1['name'].': '.$heach1['value'].$this->_crlf;
  1027. foreach($arrval2 as $heach2) $hval2 .= $heach2['name'].': '.$heach2['value'].$this->_crlf;
  1028. $multipart = false;
  1029. if($this->_atext && $this->_ahtml) $multipart = true;
  1030. if($this->_attach && count($this->_attach) > 0) $multipart = true;
  1031. if($multipart){
  1032. $bval .= 'This is a message in MIME Format. If you see this, your mail reader does not support this format.'.$this->_crlf.$this->_crlf;
  1033. $boundary1 = '=_'.$this->_getunique();
  1034. $boundary2 = '=_'.$this->_getunique();
  1035. $boundary3 = '=_'.$this->_getunique();
  1036. $haveatt = ($this->_attach && count($this->_attach) > 0) ? true : false;
  1037. $inline = $attachment = false;
  1038. $idarr = array();
  1039. if($haveatt){
  1040. foreach($this->_attach as $attdesc){
  1041. if($attdesc['disp'] == "inline"){
  1042. $inline = true;
  1043. $fname = $attdesc['name'];
  1044. if(!isset($idarr[$fname])) $idarr[$fname] = $this->_getunique();
  1045. }else $attachment = true;
  1046. }
  1047. }
  1048. $hadd = '';
  1049. if($this->_atext && $this->_ahtml){
  1050. $vhtml = (count($idarr) > 0) ? $this->_putcid($this->_ahtml[2], $idarr) : $this->_ahtml[2];
  1051. if($inline && $attachment){
  1052. $hadd .= 'Content-Type: multipart/mixed;'.$this->_crlf."\t".'boundary="'.$boundary1.'"'.$this->_crlf;
  1053. $bval .= '--'.$boundary1.$this->_crlf.
  1054. 'Content-Type: multipart/related;'.$this->_crlf."\t".'boundary="'.$boundary2.'"'.$this->_crlf.$this->_crlf.
  1055. '--'.$boundary2.$this->_crlf.
  1056. 'Content-Type: multipart/alternative;'.$this->_crlf."\t".'boundary="'.$boundary3.'"'.$this->_crlf.$this->_crlf.
  1057. '--'.$boundary3.$this->_crlf.
  1058. $this->_atext[0].$this->_crlf.$this->_crlf.
  1059. $this->_encodemsg($this->_atext[2], $this->_atext[1]).
  1060. $this->_crlf.'--'.$boundary3.$this->_crlf.
  1061. $this->_ahtml[0].$this->_crlf.$this->_crlf.
  1062. $this->_encodemsg($vhtml, $this->_ahtml[1]).
  1063. $this->_crlf.'--'.$boundary3.'--'.$this->_crlf;
  1064. foreach($this->_attach as $attdesc){
  1065. if($attdesc['disp'] == "inline"){
  1066. $bval .= '--'.$boundary2.$this->_crlf.
  1067. 'Content-Type: '.$attdesc['mime'].$this->_crlf.
  1068. 'Content-Transfer-Encoding: '.$attdesc['encode'].$this->_crlf.
  1069. 'Content-Disposition: '.$attdesc['disp'].';'.$this->_crlf."\t".'filename="'.$attdesc['name'].'"'.$this->_crlf.
  1070. 'Content-ID: <'.$idarr[$attdesc['name']].'>'.$this->_crlf.$this->_crlf.
  1071. $this->_encodemsg($attdesc['source'], $attdesc['encode']);
  1072. }
  1073. }
  1074. $bval .= '--'.$boundary2.'--'.$this->_crlf;
  1075. foreach($this->_attach as $attdesc){
  1076. if($attdesc['disp'] == "attachment"){
  1077. $bval .= '--'.$boundary1.$this->_crlf.
  1078. 'Content-Type: '.$attdesc['mime'].$this->_crlf.
  1079. 'Content-Transfer-Encoding: '.$attdesc['encode'].$this->_crlf.
  1080. 'Content-Disposition: '.$attdesc['disp'].';'.$this->_crlf."\t".'filename="'.$attdesc['name'].'"'.$this->_crlf.$this->_crlf.
  1081. $this->_encodemsg($attdesc['source'], $attdesc['encode']);
  1082. }
  1083. }
  1084. $bval .= '--'.$boundary1.'--';
  1085. }elseif($inline){
  1086. $hadd .= 'Content-Type: multipart/related;'.$this->_crlf."\t".'boundary="'.$boundary1.'"'.$this->_crlf;
  1087. $bval .= '--'.$boundary1.$this->_crlf.
  1088. 'Content-Type: multipart/alternative;'.$this->_crlf."\t".'boundary="'.$boundary2.'"'.$this->_crlf.$this->_crlf.
  1089. '--'.$boundary2.$this->_crlf.
  1090. $this->_atext[0].$this->_crlf.$this->_crlf.
  1091. $this->_encodemsg($this->_atext[2], $this->_atext[1]).
  1092. $this->_crlf.'--'.$boundary2.$this->_crlf.
  1093. $this->_ahtml[0].$this->_crlf.$this->_crlf.
  1094. $this->_encodemsg($vhtml, $this->_ahtml[1]).
  1095. $this->_crlf.'--'.$boundary2.'--'.$this->_crlf;
  1096. foreach($this->_attach as $attdesc){
  1097. $bval .= '--'.$boundary1.$this->_crlf.
  1098. 'Content-Type: '.$attdesc['mime'].$this->_crlf.
  1099. 'Content-Transfer-Encoding: '.$attdesc['encode'].$this->_crlf.
  1100. 'Content-Disposition: '.$attdesc['disp'].';'.$this->_crlf."\t".'filename="'.$attdesc['name'].'"'.$this->_crlf.
  1101. 'Content-ID: <'.$idarr[$attdesc['name']].'>'.$this->_crlf.$this->_crlf.
  1102. $this->_encodemsg($attdesc['source'], $attdesc['encode']);
  1103. }
  1104. $bval .= '--'.$boundary1.'--';
  1105. }elseif($attachment){
  1106. $hadd .= 'Content-Type: multipart/mixed;'.$this->_crlf."\t".'boundary="'.$boundary1.'"'.$this->_crlf;
  1107. $bval .= '--'.$boundary1.$this->_crlf.
  1108. 'Content-Type: multipart/alternative;'.$this->_crlf."\t".'boundary="'.$boundary2.'"'.$this->_crlf.$this->_crlf.
  1109. '--'.$boundary2.$this->_crlf.
  1110. $this->_atext[0].$this->_crlf.$this->_crlf.
  1111. $this->_encodemsg($this->_atext[2], $this->_atext[1]).
  1112. $this->_crlf.'--'.$boundary2.$this->_crlf.
  1113. $this->_ahtml[0].$this->_crlf.$this->_crlf.
  1114. $this->_encodemsg($vhtml, $this->_ahtml[1]).
  1115. $this->_crlf.'--'.$boundary2.'--'.$this->_crlf;
  1116. foreach($this->_attach as $attdesc){
  1117. $bval .= '--'.$boundary1.$this->_crlf.
  1118. 'Content-Type: '.$attdesc['mime'].$this->_crlf.
  1119. 'Content-Transfer-Encoding: '.$attdesc['encode'].$this->_crlf.
  1120. 'Content-Disposition: '.$attdesc['disp'].';'.$this->_crlf."\t".'filename="'.$attdesc['name'].'"'.$this->_crlf.$this->_crlf.
  1121. $this->_encodemsg($attdesc['source'], $attdesc['encode']);
  1122. }
  1123. $bval .= '--'.$boundary1.'--';
  1124. }else{
  1125. $hadd .= 'Content-Type: multipart/alternative;'.$this->_crlf."\t".'boundary="'.$boundary1.'"'.$this->_crlf;
  1126. $bval .= '--'.$boundary1.$this->_crlf.
  1127. $this->_atext[0].$this->_crlf.$this->_crlf.
  1128. $this->_encodemsg($this->_atext[2], $this->_atext[1]).
  1129. $this->_crlf.'--'.$boundary1.$this->_crlf.
  1130. $this->_ahtml[0].$this->_crlf.$this->_crlf.
  1131. $this->_encodemsg($vhtml, $this->_ahtml[1]).
  1132. $this->_crlf.'--'.$boundary1.'--';
  1133. }
  1134. }elseif($this->_atext){
  1135. $hadd .= 'Content-Type: multipart/mixed;'.$this->_crlf."\t".'boundary="'.$boundary1.'"'.$this->_crlf;
  1136. $bval .= '--'.$boundary1.$this->_crlf.
  1137. $this->_atext[0].$this->_crlf.$this->_crlf.
  1138. $this->_encodemsg($this->_atext[2], $this->_atext[1]).$this->_crlf;
  1139. foreach($this->_attach as $attdesc){
  1140. $bval .= '--'.$boundary1.$this->_crlf.
  1141. 'Content-Type: '.$attdesc['mime'].$this->_crlf.
  1142. 'Content-Transfer-Encoding: '.$attdesc['encode'].$this->_crlf.
  1143. 'Content-Disposition: '.$attdesc['disp'].';'.$this->_crlf."\t".'filename="'.$attdesc['name'].'"'.$this->_crlf.$this->_crlf.
  1144. $this->_encodemsg($attdesc['source'], $attdesc['encode']);
  1145. }
  1146. $bval .= '--'.$boundary1.'--';
  1147. }elseif($this->_ahtml){
  1148. $vhtml = (count($idarr) > 0) ? $this->_putcid($this->_ahtml[2], $idarr) : $this->_ahtml[2];
  1149. if($inline && $attachment){
  1150. $hadd .= 'Content-Type: multipart/mixed;'.$this->_crlf."\t".'boundary="'.$boundary1.'"'.$this->_crlf;
  1151. $bval .= '--'.$boundary1.$this->_crlf.
  1152. 'Content-Type: multipart/related;'.$this->_crlf."\t".'boundary="'.$boundary2.'"'.$this->_crlf.$this->_crlf.
  1153. '--'.$boundary2.$this->_crlf.
  1154. $this->_ahtml[0].$this->_crlf.$this->_crlf.
  1155. $this->_encodemsg($vhtml, $this->_ahtml[1]).$this->_crlf;
  1156. foreach($this->_attach as $attdesc){
  1157. if($attdesc['disp'] == "inline"){
  1158. $bval .= '--'.$boundary2.$this->_crlf.
  1159. 'Content-Type: '.$attdesc['mime'].$this->_crlf.
  1160. 'Content-Transfer-Encoding: '.$attdesc['encode'].$this->_crlf.
  1161. 'Content-Disposition: '.$attdesc['disp'].';'.$this->_crlf."\t".'filename="'.$attdesc['name'].'"'.$this->_crlf.
  1162. 'Content-ID: <'.$idarr[$attdesc['name']].'>'.$this->_crlf.$this->_crlf.
  1163. $this->_encodemsg($attdesc['source'], $attdesc['encode']);
  1164. }
  1165. }
  1166. $bval .= '--'.$boundary2.'--'.$this->_crlf;
  1167. foreach($this->_attach as $attdesc){
  1168. if($attdesc['disp'] == "attachment"){
  1169. $bval .= '--'.$boundary1.$this->_crlf.
  1170. 'Content-Type: '.$attdesc['mime'].$this->_crlf.
  1171. 'Content-Transfer-Encoding: '.$attdesc['encode'].$this->_crlf.
  1172. 'Content-Disposition: '.$attdesc['disp'].';'.$this->_crlf."\t".'filename="'.$attdesc['name'].'"'.$this->_crlf.$this->_crlf.
  1173. $this->_encodemsg($attdesc['source'], $attdesc['encode']);
  1174. }
  1175. }
  1176. $bval .= '--'.$boundary1.'--';
  1177. }elseif($inline){
  1178. $hadd .= 'Content-Type: multipart/related;'.$this->_crlf."\t".'boundary="'.$boundary1.'"'.$this->_crlf;
  1179. $bval .= '--'.$boundary1.$this->_crlf.
  1180. $this->_ahtml[0].$this->_crlf.$this->_crlf.
  1181. $this->_encodemsg($vhtml, $this->_ahtml[1]).$this->_crlf;
  1182. foreach($this->_attach as $attdesc){
  1183. $bval .= '--'.$boundary1.$this->_crlf.
  1184. 'Content-Type: '.$attdesc['mime'].$this->_crlf.
  1185. 'Content-Transfer-Encoding: '.$attdesc['encode'].$this->_crlf.
  1186. 'Content-Disposition: '.$attdesc['disp'].';'.$this->_crlf."\t".'filename="'.$attdesc['name'].'"'.$this->_crlf.
  1187. 'Content-ID: <'.$idarr[$attdesc['name']].'>'.$this->_crlf.$this->_crlf.
  1188. $this->_encodemsg($attdesc['source'], $attdesc['encode']);
  1189. }
  1190. $bval .= '--'.$boundary1.'--';
  1191. }elseif($attachment){
  1192. $hadd .= 'Content-Type: multipart/mixed;'.$this->_crlf."\t".'boundary="'.$boundary1.'"'.$this->_crlf;
  1193. $bval .= '--'.$boundary1.$this->_crlf.
  1194. $this->_ahtml[0].$this->_crlf.$this->_crlf.
  1195. $this->_encodemsg($vhtml, $this->_ahtml[1]).$this->_crlf;
  1196. foreach($this->_attach as $attdesc){
  1197. $bval .= '--'.$boundary1.$this->_crlf.
  1198. 'Content-Type: '.$attdesc['mime'].$this->_crlf.
  1199. 'Content-Transfer-Encoding: '.$attdesc['encode'].$this->_crlf.
  1200. 'Content-Disposition: '.$attdesc['disp'].';'.$this->_crlf."\t".'filename="'.$attdesc['name'].'"'.$this->_crlf.$this->_crlf.
  1201. $this->_encodemsg($attdesc['source'], $attdesc['encode']);
  1202. }
  1203. $bval .= '--'.$boundary1.'--';
  1204. }
  1205. }
  1206. $hadd .= 'MIME-Version: 1.0';
  1207. $hval1 .= $hadd;
  1208. $hval2 .= $hadd;
  1209. }else{
  1210. if($this->_atext){
  1211. $hval1 .= $this->_atext[0];
  1212. $hval2 .= $this->_atext[0];
  1213. $bval .= $this->_encodemsg($this->_atext[2], $this->_atext[1]);
  1214. }else{
  1215. $hval1 .= $this->_ahtml[0];
  1216. $hval2 .= $this->_ahtml[0];
  1217. $bval .= $this->_encodemsg($this->_ahtml[2], $this->_ahtml[1]);
  1218. }
  1219. }
  1220. return array('header' => array('to' => $hto, 'local' => $hval1, 'client' => $hval2.$this->_crlf.$this->_crlf), 'body' => $this->_splitmsg($bval));
  1221. }
  1222. function send($subject, $charset = 'utf-8', $encoding = 'quoted-printable'){
  1223. $ret = false;
  1224. if(is_string($charset)){
  1225. $charset = FUNC::str_clear($charset, array(' '));
  1226. $charset = trim($charset);
  1227. $charlen = strlen($charset);
  1228. if(!($charlen > 1 && $charlen < 60)){
  1229. $charset = 'utf-8';
  1230. trigger_error('Invalid charset value, on cla…

Large files files are truncated, but you can click here to view the full file