class.phpmailer.php 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474
  1. <?php
  2. /*~ class.phpmailer.php
  3. .---------------------------------------------------------------------------.
  4. | Software: PHPMailer - PHP email class |
  5. | Version: 5.2 |
  6. | Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ |
  7. | ------------------------------------------------------------------------- |
  8. | Admin: Jim Jagielski (project admininistrator) |
  9. | Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
  10. | : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
  11. | : Jim Jagielski (jimjag) jimjag@gmail.com |
  12. | Founder: Brent R. Matzelle (original founder) |
  13. | Copyright (c) 2010-2011, Jim Jagielski. All Rights Reserved. |
  14. | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
  15. | Copyright (c) 2001-2003, Brent R. Matzelle |
  16. | ------------------------------------------------------------------------- |
  17. | License: Distributed under the Lesser General Public License (LGPL) |
  18. | http://www.gnu.org/copyleft/lesser.html |
  19. | This program is distributed in the hope that it will be useful - WITHOUT |
  20. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
  21. | FITNESS FOR A PARTICULAR PURPOSE. |
  22. '---------------------------------------------------------------------------'
  23. */
  24. /**
  25. * PHPMailer - PHP email transport class
  26. * NOTE: Requires PHP version 5 or later
  27. * @package PHPMailer
  28. * @author Andy Prevost
  29. * @author Marcus Bointon
  30. * @author Jim Jagielski
  31. * @copyright 2010 - 2011 Jim Jagielski
  32. * @copyright 2004 - 2009 Andy Prevost
  33. * @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $
  34. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  35. */
  36. if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n");
  37. class PHPMailer {
  38. /////////////////////////////////////////////////
  39. // PROPERTIES, PUBLIC
  40. /////////////////////////////////////////////////
  41. /**
  42. * Email priority (1 = High, 3 = Normal, 5 = low).
  43. * @var int
  44. */
  45. public $Priority = 3;
  46. /**
  47. * Sets the CharSet of the message.
  48. * @var string
  49. */
  50. public $CharSet = 'iso-8859-1';
  51. /**
  52. * Sets the Content-type of the message.
  53. * @var string
  54. */
  55. public $ContentType = 'text/plain';
  56. /**
  57. * Sets the Encoding of the message. Options for this are
  58. * "8bit", "7bit", "binary", "base64", and "quoted-printable".
  59. * @var string
  60. */
  61. public $Encoding = '8bit';
  62. /**
  63. * Holds the most recent mailer error message.
  64. * @var string
  65. */
  66. public $ErrorInfo = '';
  67. /**
  68. * Sets the From email address for the message.
  69. * @var string
  70. */
  71. public $From = 'root@localhost';
  72. /**
  73. * Sets the From name of the message.
  74. * @var string
  75. */
  76. public $FromName = 'Root User';
  77. /**
  78. * Sets the Sender email (Return-Path) of the message. If not empty,
  79. * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  80. * @var string
  81. */
  82. public $Sender = '';
  83. /**
  84. * Sets the Subject of the message.
  85. * @var string
  86. */
  87. public $Subject = '';
  88. /**
  89. * Sets the Body of the message. This can be either an HTML or text body.
  90. * If HTML then run IsHTML(true).
  91. * @var string
  92. */
  93. public $Body = '';
  94. /**
  95. * Sets the text-only body of the message. This automatically sets the
  96. * email to multipart/alternative. This body can be read by mail
  97. * clients that do not have HTML email capability such as mutt. Clients
  98. * that can read HTML will view the normal Body.
  99. * @var string
  100. */
  101. public $AltBody = '';
  102. /**
  103. * Stores the complete compiled MIME message body.
  104. * @var string
  105. * @access protected
  106. */
  107. protected $MIMEBody = '';
  108. /**
  109. * Stores the complete compiled MIME message headers.
  110. * @var string
  111. * @access protected
  112. */
  113. protected $MIMEHeader = '';
  114. /**
  115. * Sets word wrapping on the body of the message to a given number of
  116. * characters.
  117. * @var int
  118. */
  119. public $WordWrap = 0;
  120. /**
  121. * Method to send mail: ("mail", "sendmail", or "smtp").
  122. * @var string
  123. */
  124. public $Mailer = 'mail';
  125. /**
  126. * Sets the path of the sendmail program.
  127. * @var string
  128. */
  129. public $Sendmail = '/usr/sbin/sendmail';
  130. /**
  131. * Path to PHPMailer plugins. Useful if the SMTP class
  132. * is in a different directory than the PHP include path.
  133. * @var string
  134. */
  135. public $PluginDir = '';
  136. /**
  137. * Sets the email address that a reading confirmation will be sent.
  138. * @var string
  139. */
  140. public $ConfirmReadingTo = '';
  141. /**
  142. * Sets the hostname to use in Message-Id and Received headers
  143. * and as default HELO string. If empty, the value returned
  144. * by SERVER_NAME is used or 'localhost.localdomain'.
  145. * @var string
  146. */
  147. public $Hostname = '';
  148. /**
  149. * Sets the message ID to be used in the Message-Id header.
  150. * If empty, a unique id will be generated.
  151. * @var string
  152. */
  153. public $MessageID = '';
  154. /////////////////////////////////////////////////
  155. // PROPERTIES FOR SMTP
  156. /////////////////////////////////////////////////
  157. /**
  158. * Sets the SMTP hosts. All hosts must be separated by a
  159. * semicolon. You can also specify a different port
  160. * for each host by using this format: [hostname:port]
  161. * (e.g. "smtp1.example.com:25;smtp2.example.com").
  162. * Hosts will be tried in order.
  163. * @var string
  164. */
  165. public $Host = 'localhost';
  166. /**
  167. * Sets the default SMTP server port.
  168. * @var int
  169. */
  170. public $Port = 25;
  171. /**
  172. * Sets the SMTP HELO of the message (Default is $Hostname).
  173. * @var string
  174. */
  175. public $Helo = '';
  176. /**
  177. * Sets connection prefix.
  178. * Options are "", "ssl" or "tls"
  179. * @var string
  180. */
  181. public $SMTPSecure = '';
  182. /**
  183. * Sets SMTP authentication. Utilizes the Username and Password variables.
  184. * @var bool
  185. */
  186. public $SMTPAuth = false;
  187. /**
  188. * Sets SMTP username.
  189. * @var string
  190. */
  191. public $Username = '';
  192. /**
  193. * Sets SMTP password.
  194. * @var string
  195. */
  196. public $Password = '';
  197. /**
  198. * Sets the SMTP server timeout in seconds.
  199. * This function will not work with the win32 version.
  200. * @var int
  201. */
  202. public $Timeout = 10;
  203. /**
  204. * Sets SMTP class debugging on or off.
  205. * @var bool
  206. */
  207. public $SMTPDebug = false;
  208. /**
  209. * Prevents the SMTP connection from being closed after each mail
  210. * sending. If this is set to true then to close the connection
  211. * requires an explicit call to SmtpClose().
  212. * @var bool
  213. */
  214. public $SMTPKeepAlive = false;
  215. /**
  216. * Provides the ability to have the TO field process individual
  217. * emails, instead of sending to entire TO addresses
  218. * @var bool
  219. */
  220. public $SingleTo = false;
  221. /**
  222. * If SingleTo is true, this provides the array to hold the email addresses
  223. * @var bool
  224. */
  225. public $SingleToArray = array();
  226. /**
  227. * Provides the ability to change the line ending
  228. * @var string
  229. */
  230. public $LE = "\n";
  231. /**
  232. * Used with DKIM DNS Resource Record
  233. * @var string
  234. */
  235. public $DKIM_selector = 'phpmailer';
  236. /**
  237. * Used with DKIM DNS Resource Record
  238. * optional, in format of email address 'you@yourdomain.com'
  239. * @var string
  240. */
  241. public $DKIM_identity = '';
  242. /**
  243. * Used with DKIM DNS Resource Record
  244. * @var string
  245. */
  246. public $DKIM_passphrase = '';
  247. /**
  248. * Used with DKIM DNS Resource Record
  249. * optional, in format of email address 'you@yourdomain.com'
  250. * @var string
  251. */
  252. public $DKIM_domain = '';
  253. /**
  254. * Used with DKIM DNS Resource Record
  255. * optional, in format of email address 'you@yourdomain.com'
  256. * @var string
  257. */
  258. public $DKIM_private = '';
  259. /**
  260. * Callback Action function name
  261. * the function that handles the result of the send email action. Parameters:
  262. * bool $result result of the send action
  263. * string $to email address of the recipient
  264. * string $cc cc email addresses
  265. * string $bcc bcc email addresses
  266. * string $subject the subject
  267. * string $body the email body
  268. * @var string
  269. */
  270. public $action_function = ''; //'callbackAction';
  271. /**
  272. * Sets the PHPMailer Version number
  273. * @var string
  274. */
  275. public $Version = '5.2';
  276. /**
  277. * What to use in the X-Mailer header
  278. * @var string
  279. */
  280. public $XMailer = '';
  281. /////////////////////////////////////////////////
  282. // PROPERTIES, PRIVATE AND PROTECTED
  283. /////////////////////////////////////////////////
  284. protected $smtp = NULL;
  285. protected $to = array();
  286. protected $cc = array();
  287. protected $bcc = array();
  288. protected $ReplyTo = array();
  289. protected $all_recipients = array();
  290. protected $attachment = array();
  291. protected $CustomHeader = array();
  292. protected $message_type = '';
  293. protected $boundary = array();
  294. protected $language = array();
  295. protected $error_count = 0;
  296. protected $sign_cert_file = '';
  297. protected $sign_key_file = '';
  298. protected $sign_key_pass = '';
  299. protected $exceptions = false;
  300. /////////////////////////////////////////////////
  301. // CONSTANTS
  302. /////////////////////////////////////////////////
  303. const STOP_MESSAGE = 0; // message only, continue processing
  304. const STOP_CONTINUE = 1; // message?, likely ok to continue processing
  305. const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
  306. /////////////////////////////////////////////////
  307. // METHODS, VARIABLES
  308. /////////////////////////////////////////////////
  309. /**
  310. * Constructor
  311. * @param boolean $exceptions Should we throw external exceptions?
  312. */
  313. public function __construct($exceptions = false) {
  314. $this->exceptions = ($exceptions == true);
  315. }
  316. /**
  317. * Sets message type to HTML.
  318. * @param bool $ishtml
  319. * @return void
  320. */
  321. public function IsHTML($ishtml = true) {
  322. if ($ishtml) {
  323. $this->ContentType = 'text/html';
  324. } else {
  325. $this->ContentType = 'text/plain';
  326. }
  327. }
  328. /**
  329. * Sets Mailer to send message using SMTP.
  330. * @return void
  331. */
  332. public function IsSMTP() {
  333. $this->Mailer = 'smtp';
  334. }
  335. /**
  336. * Sets Mailer to send message using PHP mail() function.
  337. * @return void
  338. */
  339. public function IsMail() {
  340. $this->Mailer = 'mail';
  341. }
  342. /**
  343. * Sets Mailer to send message using the $Sendmail program.
  344. * @return void
  345. */
  346. public function IsSendmail() {
  347. if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
  348. $this->Sendmail = '/var/qmail/bin/sendmail';
  349. }
  350. $this->Mailer = 'sendmail';
  351. }
  352. /**
  353. * Sets Mailer to send message using the qmail MTA.
  354. * @return void
  355. */
  356. public function IsQmail() {
  357. if (stristr(ini_get('sendmail_path'), 'qmail')) {
  358. $this->Sendmail = '/var/qmail/bin/sendmail';
  359. }
  360. $this->Mailer = 'sendmail';
  361. }
  362. /////////////////////////////////////////////////
  363. // METHODS, RECIPIENTS
  364. /////////////////////////////////////////////////
  365. /**
  366. * Adds a "To" address.
  367. * @param string $address
  368. * @param string $name
  369. * @return boolean true on success, false if address already used
  370. */
  371. public function AddAddress($address, $name = '') {
  372. return $this->AddAnAddress('to', $address, $name);
  373. }
  374. /**
  375. * Adds a "Cc" address.
  376. * Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
  377. * @param string $address
  378. * @param string $name
  379. * @return boolean true on success, false if address already used
  380. */
  381. public function AddCC($address, $name = '') {
  382. return $this->AddAnAddress('cc', $address, $name);
  383. }
  384. /**
  385. * Adds a "Bcc" address.
  386. * Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
  387. * @param string $address
  388. * @param string $name
  389. * @return boolean true on success, false if address already used
  390. */
  391. public function AddBCC($address, $name = '') {
  392. return $this->AddAnAddress('bcc', $address, $name);
  393. }
  394. /**
  395. * Adds a "Reply-to" address.
  396. * @param string $address
  397. * @param string $name
  398. * @return boolean
  399. */
  400. public function AddReplyTo($address, $name = '') {
  401. return $this->AddAnAddress('ReplyTo', $address, $name);
  402. }
  403. /**
  404. * Adds an address to one of the recipient arrays
  405. * Addresses that have been added already return false, but do not throw exceptions
  406. * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
  407. * @param string $address The email address to send to
  408. * @param string $name
  409. * @return boolean true on success, false if address already used or invalid in some way
  410. * @access protected
  411. */
  412. protected function AddAnAddress($kind, $address, $name = '') {
  413. if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
  414. $this->SetError($this->Lang('Invalid recipient array').': '.$kind);
  415. if ($this->exceptions) {
  416. throw new phpmailerException('Invalid recipient array: ' . $kind);
  417. }
  418. echo $this->Lang('Invalid recipient array').': '.$kind;
  419. return false;
  420. }
  421. $address = trim($address);
  422. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  423. if (!self::ValidateAddress($address)) {
  424. $this->SetError($this->Lang('invalid_address').': '. $address);
  425. if ($this->exceptions) {
  426. throw new phpmailerException($this->Lang('invalid_address').': '.$address);
  427. }
  428. echo $this->Lang('invalid_address').': '.$address;
  429. return false;
  430. }
  431. if ($kind != 'ReplyTo') {
  432. if (!isset($this->all_recipients[strtolower($address)])) {
  433. array_push($this->$kind, array($address, $name));
  434. $this->all_recipients[strtolower($address)] = true;
  435. return true;
  436. }
  437. } else {
  438. if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  439. $this->ReplyTo[strtolower($address)] = array($address, $name);
  440. return true;
  441. }
  442. }
  443. return false;
  444. }
  445. /**
  446. * Set the From and FromName properties
  447. * @param string $address
  448. * @param string $name
  449. * @return boolean
  450. */
  451. public function SetFrom($address, $name = '', $auto = 1) {
  452. $address = trim($address);
  453. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  454. if (!self::ValidateAddress($address)) {
  455. $this->SetError($this->Lang('invalid_address').': '. $address);
  456. if ($this->exceptions) {
  457. throw new phpmailerException($this->Lang('invalid_address').': '.$address);
  458. }
  459. echo $this->Lang('invalid_address').': '.$address;
  460. return false;
  461. }
  462. $this->From = $address;
  463. $this->FromName = $name;
  464. if ($auto) {
  465. if (empty($this->ReplyTo)) {
  466. $this->AddAnAddress('ReplyTo', $address, $name);
  467. }
  468. if (empty($this->Sender)) {
  469. $this->Sender = $address;
  470. }
  471. }
  472. return true;
  473. }
  474. /**
  475. * Check that a string looks roughly like an email address should
  476. * Static so it can be used without instantiation
  477. * Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator
  478. * Conforms approximately to RFC2822
  479. * @link http://www.hexillion.com/samples/#Regex Original pattern found here
  480. * @param string $address The email address to check
  481. * @return boolean
  482. * @static
  483. * @access public
  484. */
  485. public static function ValidateAddress($address) {
  486. if (function_exists('filter_var')) { //Introduced in PHP 5.2
  487. if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
  488. return false;
  489. } else {
  490. return true;
  491. }
  492. } else {
  493. return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
  494. }
  495. }
  496. /////////////////////////////////////////////////
  497. // METHODS, MAIL SENDING
  498. /////////////////////////////////////////////////
  499. /**
  500. * Creates message and assigns Mailer. If the message is
  501. * not sent successfully then it returns false. Use the ErrorInfo
  502. * variable to view description of the error.
  503. * @return bool
  504. */
  505. public function Send() {
  506. try {
  507. if(!$this->PreSend()) return false;
  508. return $this->PostSend();
  509. } catch (phpmailerException $e) {
  510. $this->SetError($e->getMessage());
  511. if ($this->exceptions) {
  512. throw $e;
  513. }
  514. return false;
  515. }
  516. }
  517. protected function PreSend() {
  518. try {
  519. if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  520. throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
  521. }
  522. // Set whether the message is multipart/alternative
  523. if(!empty($this->AltBody)) {
  524. $this->ContentType = 'multipart/alternative';
  525. }
  526. $this->error_count = 0; // reset errors
  527. $this->SetMessageType();
  528. //Refuse to send an empty message
  529. if (empty($this->Body)) {
  530. throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
  531. }
  532. $this->MIMEHeader = $this->CreateHeader();
  533. $this->MIMEBody = $this->CreateBody();
  534. // digitally sign with DKIM if enabled
  535. if ($this->DKIM_domain && $this->DKIM_private) {
  536. $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody);
  537. $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
  538. }
  539. return true;
  540. } catch (phpmailerException $e) {
  541. $this->SetError($e->getMessage());
  542. if ($this->exceptions) {
  543. throw $e;
  544. }
  545. return false;
  546. }
  547. }
  548. protected function PostSend() {
  549. try {
  550. // Choose the mailer and send through it
  551. switch($this->Mailer) {
  552. case 'sendmail':
  553. return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
  554. case 'smtp':
  555. return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
  556. default:
  557. return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
  558. }
  559. } catch (phpmailerException $e) {
  560. $this->SetError($e->getMessage());
  561. if ($this->exceptions) {
  562. throw $e;
  563. }
  564. echo $e->getMessage()."\n";
  565. return false;
  566. }
  567. }
  568. /**
  569. * Sends mail using the $Sendmail program.
  570. * @param string $header The message headers
  571. * @param string $body The message body
  572. * @access protected
  573. * @return bool
  574. */
  575. protected function SendmailSend($header, $body) {
  576. if ($this->Sender != '') {
  577. $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  578. } else {
  579. $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
  580. }
  581. if ($this->SingleTo === true) {
  582. foreach ($this->SingleToArray as $key => $val) {
  583. if(!@$mail = popen($sendmail, 'w')) {
  584. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  585. }
  586. fputs($mail, "To: " . $val . "\n");
  587. fputs($mail, $header);
  588. fputs($mail, $body);
  589. $result = pclose($mail);
  590. // implement call back function if it exists
  591. $isSent = ($result == 0) ? 1 : 0;
  592. $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
  593. if($result != 0) {
  594. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  595. }
  596. }
  597. } else {
  598. if(!@$mail = popen($sendmail, 'w')) {
  599. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  600. }
  601. fputs($mail, $header);
  602. fputs($mail, $body);
  603. $result = pclose($mail);
  604. // implement call back function if it exists
  605. $isSent = ($result == 0) ? 1 : 0;
  606. $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body);
  607. if($result != 0) {
  608. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  609. }
  610. }
  611. return true;
  612. }
  613. /**
  614. * Sends mail using the PHP mail() function.
  615. * @param string $header The message headers
  616. * @param string $body The message body
  617. * @access protected
  618. * @return bool
  619. */
  620. protected function MailSend($header, $body) {
  621. $toArr = array();
  622. foreach($this->to as $t) {
  623. $toArr[] = $this->AddrFormat($t);
  624. }
  625. $to = implode(', ', $toArr);
  626. if (empty($this->Sender)) {
  627. $params = "-oi -f %s";
  628. } else {
  629. $params = sprintf("-oi -f %s", $this->Sender);
  630. }
  631. if ($this->Sender != '' and !ini_get('safe_mode')) {
  632. $old_from = ini_get('sendmail_from');
  633. ini_set('sendmail_from', $this->Sender);
  634. if ($this->SingleTo === true && count($toArr) > 1) {
  635. foreach ($toArr as $key => $val) {
  636. $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  637. // implement call back function if it exists
  638. $isSent = ($rt == 1) ? 1 : 0;
  639. $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
  640. }
  641. } else {
  642. $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  643. // implement call back function if it exists
  644. $isSent = ($rt == 1) ? 1 : 0;
  645. $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
  646. }
  647. } else {
  648. if ($this->SingleTo === true && count($toArr) > 1) {
  649. foreach ($toArr as $key => $val) {
  650. $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  651. // implement call back function if it exists
  652. $isSent = ($rt == 1) ? 1 : 0;
  653. $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
  654. }
  655. } else {
  656. $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
  657. // implement call back function if it exists
  658. $isSent = ($rt == 1) ? 1 : 0;
  659. $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
  660. }
  661. }
  662. if (isset($old_from)) {
  663. ini_set('sendmail_from', $old_from);
  664. }
  665. if(!$rt) {
  666. throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL);
  667. }
  668. return true;
  669. }
  670. /**
  671. * Sends mail via SMTP using PhpSMTP
  672. * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
  673. * @param string $header The message headers
  674. * @param string $body The message body
  675. * @uses SMTP
  676. * @access protected
  677. * @return bool
  678. */
  679. protected function SmtpSend($header, $body) {
  680. require_once $this->PluginDir . 'class.smtp.php';
  681. $bad_rcpt = array();
  682. if(!$this->SmtpConnect()) {
  683. throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL);
  684. }
  685. $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
  686. if(!$this->smtp->Mail($smtp_from)) {
  687. throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL);
  688. }
  689. // Attempt to send attach all recipients
  690. foreach($this->to as $to) {
  691. if (!$this->smtp->Recipient($to[0])) {
  692. $bad_rcpt[] = $to[0];
  693. // implement call back function if it exists
  694. $isSent = 0;
  695. $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
  696. } else {
  697. // implement call back function if it exists
  698. $isSent = 1;
  699. $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
  700. }
  701. }
  702. foreach($this->cc as $cc) {
  703. if (!$this->smtp->Recipient($cc[0])) {
  704. $bad_rcpt[] = $cc[0];
  705. // implement call back function if it exists
  706. $isSent = 0;
  707. $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
  708. } else {
  709. // implement call back function if it exists
  710. $isSent = 1;
  711. $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
  712. }
  713. }
  714. foreach($this->bcc as $bcc) {
  715. if (!$this->smtp->Recipient($bcc[0])) {
  716. $bad_rcpt[] = $bcc[0];
  717. // implement call back function if it exists
  718. $isSent = 0;
  719. $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
  720. } else {
  721. // implement call back function if it exists
  722. $isSent = 1;
  723. $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
  724. }
  725. }
  726. if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses
  727. $badaddresses = implode(', ', $bad_rcpt);
  728. throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses);
  729. }
  730. if(!$this->smtp->Data($header . $body)) {
  731. throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL);
  732. }
  733. if($this->SMTPKeepAlive == true) {
  734. $this->smtp->Reset();
  735. }
  736. return true;
  737. }
  738. /**
  739. * Initiates a connection to an SMTP server.
  740. * Returns false if the operation failed.
  741. * @uses SMTP
  742. * @access public
  743. * @return bool
  744. */
  745. public function SmtpConnect() {
  746. if(is_null($this->smtp)) {
  747. $this->smtp = new SMTP();
  748. }
  749. $this->smtp->do_debug = $this->SMTPDebug;
  750. $hosts = explode(';', $this->Host);
  751. $index = 0;
  752. $connection = $this->smtp->Connected();
  753. // Retry while there is no connection
  754. try {
  755. while($index < count($hosts) && !$connection) {
  756. $hostinfo = array();
  757. if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
  758. $host = $hostinfo[1];
  759. $port = $hostinfo[2];
  760. } else {
  761. $host = $hosts[$index];
  762. $port = $this->Port;
  763. }
  764. $tls = ($this->SMTPSecure == 'tls');
  765. $ssl = ($this->SMTPSecure == 'ssl');
  766. if ($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) {
  767. $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname());
  768. $this->smtp->Hello($hello);
  769. if ($tls) {
  770. if (!$this->smtp->StartTLS()) {
  771. throw new phpmailerException($this->Lang('tls'));
  772. }
  773. //We must resend HELO after tls negotiation
  774. $this->smtp->Hello($hello);
  775. }
  776. $connection = true;
  777. if ($this->SMTPAuth) {
  778. if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
  779. throw new phpmailerException($this->Lang('authenticate'));
  780. }
  781. }
  782. }
  783. $index++;
  784. if (!$connection) {
  785. throw new phpmailerException($this->Lang('connect_host'));
  786. }
  787. }
  788. } catch (phpmailerException $e) {
  789. $this->smtp->Reset();
  790. throw $e;
  791. }
  792. return true;
  793. }
  794. /**
  795. * Closes the active SMTP session if one exists.
  796. * @return void
  797. */
  798. public function SmtpClose() {
  799. if(!is_null($this->smtp)) {
  800. if($this->smtp->Connected()) {
  801. $this->smtp->Quit();
  802. $this->smtp->Close();
  803. }
  804. }
  805. }
  806. /**
  807. * Sets the language for all class error messages.
  808. * Returns false if it cannot load the language file. The default language is English.
  809. * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
  810. * @param string $lang_path Path to the language file directory
  811. * @access public
  812. */
  813. function SetLanguage($langcode = 'en', $lang_path = 'language/') {
  814. //Define full set of translatable strings
  815. $PHPMAILER_LANG = array(
  816. 'provide_address' => 'You must provide at least one recipient email address.',
  817. 'mailer_not_supported' => ' mailer is not supported.',
  818. 'execute' => 'Could not execute: ',
  819. 'instantiate' => 'Could not instantiate mail function.',
  820. 'authenticate' => 'SMTP Error: Could not authenticate.',
  821. 'from_failed' => 'The following From address failed: ',
  822. 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  823. 'data_not_accepted' => 'SMTP Error: Data not accepted.',
  824. 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  825. 'file_access' => 'Could not access file: ',
  826. 'file_open' => 'File Error: Could not open file: ',
  827. 'encoding' => 'Unknown encoding: ',
  828. 'signing' => 'Signing Error: ',
  829. 'smtp_error' => 'SMTP server error: ',
  830. 'empty_message' => 'Message body empty',
  831. 'invalid_address' => 'Invalid address',
  832. 'variable_set' => 'Cannot set or reset variable: '
  833. );
  834. //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"!
  835. $l = true;
  836. if ($langcode != 'en') { //There is no English translation file
  837. $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php';
  838. }
  839. $this->language = $PHPMAILER_LANG;
  840. return ($l == true); //Returns false if language not found
  841. }
  842. /**
  843. * Return the current array of language strings
  844. * @return array
  845. */
  846. public function GetTranslations() {
  847. return $this->language;
  848. }
  849. /////////////////////////////////////////////////
  850. // METHODS, MESSAGE CREATION
  851. /////////////////////////////////////////////////
  852. /**
  853. * Creates recipient headers.
  854. * @access public
  855. * @return string
  856. */
  857. public function AddrAppend($type, $addr) {
  858. $addr_str = $type . ': ';
  859. $addresses = array();
  860. foreach ($addr as $a) {
  861. $addresses[] = $this->AddrFormat($a);
  862. }
  863. $addr_str .= implode(', ', $addresses);
  864. $addr_str .= $this->LE;
  865. return $addr_str;
  866. }
  867. /**
  868. * Formats an address correctly.
  869. * @access public
  870. * @return string
  871. */
  872. public function AddrFormat($addr) {
  873. if (empty($addr[1])) {
  874. return $this->SecureHeader($addr[0]);
  875. } else {
  876. return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
  877. }
  878. }
  879. /**
  880. * Wraps message for use with mailers that do not
  881. * automatically perform wrapping and for quoted-printable.
  882. * Original written by philippe.
  883. * @param string $message The message to wrap
  884. * @param integer $length The line length to wrap to
  885. * @param boolean $qp_mode Whether to run in Quoted-Printable mode
  886. * @access public
  887. * @return string
  888. */
  889. public function WrapText($message, $length, $qp_mode = false) {
  890. $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  891. // If utf-8 encoding is used, we will need to make sure we don't
  892. // split multibyte characters when we wrap
  893. $is_utf8 = (strtolower($this->CharSet) == "utf-8");
  894. $message = $this->FixEOL($message);
  895. if (substr($message, -1) == $this->LE) {
  896. $message = substr($message, 0, -1);
  897. }
  898. $line = explode($this->LE, $message);
  899. $message = '';
  900. for ($i = 0 ;$i < count($line); $i++) {
  901. $line_part = explode(' ', $line[$i]);
  902. $buf = '';
  903. for ($e = 0; $e<count($line_part); $e++) {
  904. $word = $line_part[$e];
  905. if ($qp_mode and (strlen($word) > $length)) {
  906. $space_left = $length - strlen($buf) - 1;
  907. if ($e != 0) {
  908. if ($space_left > 20) {
  909. $len = $space_left;
  910. if ($is_utf8) {
  911. $len = $this->UTF8CharBoundary($word, $len);
  912. } elseif (substr($word, $len - 1, 1) == "=") {
  913. $len--;
  914. } elseif (substr($word, $len - 2, 1) == "=") {
  915. $len -= 2;
  916. }
  917. $part = substr($word, 0, $len);
  918. $word = substr($word, $len);
  919. $buf .= ' ' . $part;
  920. $message .= $buf . sprintf("=%s", $this->LE);
  921. } else {
  922. $message .= $buf . $soft_break;
  923. }
  924. $buf = '';
  925. }
  926. while (strlen($word) > 0) {
  927. $len = $length;
  928. if ($is_utf8) {
  929. $len = $this->UTF8CharBoundary($word, $len);
  930. } elseif (substr($word, $len - 1, 1) == "=") {
  931. $len--;
  932. } elseif (substr($word, $len - 2, 1) == "=") {
  933. $len -= 2;
  934. }
  935. $part = substr($word, 0, $len);
  936. $word = substr($word, $len);
  937. if (strlen($word) > 0) {
  938. $message .= $part . sprintf("=%s", $this->LE);
  939. } else {
  940. $buf = $part;
  941. }
  942. }
  943. } else {
  944. $buf_o = $buf;
  945. $buf .= ($e == 0) ? $word : (' ' . $word);
  946. if (strlen($buf) > $length and $buf_o != '') {
  947. $message .= $buf_o . $soft_break;
  948. $buf = $word;
  949. }
  950. }
  951. }
  952. $message .= $buf . $this->LE;
  953. }
  954. return $message;
  955. }
  956. /**
  957. * Finds last character boundary prior to maxLength in a utf-8
  958. * quoted (printable) encoded string.
  959. * Original written by Colin Brown.
  960. * @access public
  961. * @param string $encodedText utf-8 QP text
  962. * @param int $maxLength find last character boundary prior to this length
  963. * @return int
  964. */
  965. public function UTF8CharBoundary($encodedText, $maxLength) {
  966. $foundSplitPos = false;
  967. $lookBack = 3;
  968. while (!$foundSplitPos) {
  969. $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  970. $encodedCharPos = strpos($lastChunk, "=");
  971. if ($encodedCharPos !== false) {
  972. // Found start of encoded character byte within $lookBack block.
  973. // Check the encoded byte value (the 2 chars after the '=')
  974. $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  975. $dec = hexdec($hex);
  976. if ($dec < 128) { // Single byte character.
  977. // If the encoded char was found at pos 0, it will fit
  978. // otherwise reduce maxLength to start of the encoded char
  979. $maxLength = ($encodedCharPos == 0) ? $maxLength :
  980. $maxLength - ($lookBack - $encodedCharPos);
  981. $foundSplitPos = true;
  982. } elseif ($dec >= 192) { // First byte of a multi byte character
  983. // Reduce maxLength to split at start of character
  984. $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  985. $foundSplitPos = true;
  986. } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
  987. $lookBack += 3;
  988. }
  989. } else {
  990. // No encoded character found
  991. $foundSplitPos = true;
  992. }
  993. }
  994. return $maxLength;
  995. }
  996. /**
  997. * Set the body wrapping.
  998. * @access public
  999. * @return void
  1000. */
  1001. public function SetWordWrap() {
  1002. if($this->WordWrap < 1) {
  1003. return;
  1004. }
  1005. switch($this->message_type) {
  1006. case 'alt':
  1007. case 'alt_inline':
  1008. case 'alt_attach':
  1009. case 'alt_inline_attach':
  1010. $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  1011. break;
  1012. default:
  1013. $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  1014. break;
  1015. }
  1016. }
  1017. /**
  1018. * Assembles message header.
  1019. * @access public
  1020. * @return string The assembled header
  1021. */
  1022. public function CreateHeader() {
  1023. $result = '';
  1024. // Set the boundaries
  1025. $uniq_id = md5(uniqid(time()));
  1026. $this->boundary[1] = 'b1_' . $uniq_id;
  1027. $this->boundary[2] = 'b2_' . $uniq_id;
  1028. $this->boundary[3] = 'b3_' . $uniq_id;
  1029. $result .= $this->HeaderLine('Date', self::RFCDate());
  1030. if($this->Sender == '') {
  1031. $result .= $this->HeaderLine('Return-Path', trim($this->From));
  1032. } else {
  1033. $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
  1034. }
  1035. // To be created automatically by mail()
  1036. if($this->Mailer != 'mail') {
  1037. if ($this->SingleTo === true) {
  1038. foreach($this->to as $t) {
  1039. $this->SingleToArray[] = $this->AddrFormat($t);
  1040. }
  1041. } else {
  1042. if(count($this->to) > 0) {
  1043. $result .= $this->AddrAppend('To', $this->to);
  1044. } elseif (count($this->cc) == 0) {
  1045. $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
  1046. }
  1047. }
  1048. }
  1049. $from = array();
  1050. $from[0][0] = trim($this->From);
  1051. $from[0][1] = $this->FromName;
  1052. $result .= $this->AddrAppend('From', $from);
  1053. // sendmail and mail() extract Cc from the header before sending
  1054. if(count($this->cc) > 0) {
  1055. $result .= $this->AddrAppend('Cc', $this->cc);
  1056. }
  1057. // sendmail and mail() extract Bcc from the header before sending
  1058. if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
  1059. $result .= $this->AddrAppend('Bcc', $this->bcc);
  1060. }
  1061. if(count($this->ReplyTo) > 0) {
  1062. $result .= $this->AddrAppend('Reply-to', $this->ReplyTo);
  1063. }
  1064. // mail() sets the subject itself
  1065. if($this->Mailer != 'mail') {
  1066. $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
  1067. }
  1068. if($this->MessageID != '') {
  1069. $result .= $this->HeaderLine('Message-ID', $this->MessageID);
  1070. } else {
  1071. $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  1072. }
  1073. $result .= $this->HeaderLine('X-Priority', $this->Priority);
  1074. if($this->XMailer) {
  1075. $result .= $this->HeaderLine('X-Mailer', $this->XMailer);
  1076. } else {
  1077. $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
  1078. }
  1079. if($this->ConfirmReadingTo != '') {
  1080. $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  1081. }
  1082. // Add custom headers
  1083. for($index = 0; $index < count($this->CustomHeader); $index++) {
  1084. $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  1085. }
  1086. if (!$this->sign_key_file) {
  1087. $result .= $this->HeaderLine('MIME-Version', '1.0');
  1088. $result .= $this->GetMailMIME();
  1089. }
  1090. return $result;
  1091. }
  1092. /**
  1093. * Returns the message MIME.
  1094. * @access public
  1095. * @return string
  1096. */
  1097. public function GetMailMIME() {
  1098. $result = '';
  1099. switch($this->message_type) {
  1100. case 'plain':
  1101. $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
  1102. $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset="'.$this->CharSet.'"');
  1103. break;
  1104. case 'inline':
  1105. $result .= $this->HeaderLine('Content-Type', 'multipart/related;');
  1106. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  1107. break;
  1108. case 'attach':
  1109. case 'inline_attach':
  1110. case 'alt_attach':
  1111. case 'alt_inline_attach':
  1112. $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
  1113. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  1114. break;
  1115. case 'alt':
  1116. case 'alt_inline':
  1117. $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
  1118. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  1119. break;
  1120. }
  1121. if($this->Mailer != 'mail') {
  1122. $result .= $this->LE.$this->LE;
  1123. }
  1124. return $result;
  1125. }
  1126. /**
  1127. * Assembles the message body. Returns an empty string on failure.
  1128. * @access public
  1129. * @return string The assembled message body
  1130. */
  1131. public function CreateBody() {
  1132. $body = '';
  1133. if ($this->sign_key_file) {
  1134. $body .= $this->GetMailMIME();
  1135. }
  1136. $this->SetWordWrap();
  1137. switch($this->message_type) {
  1138. case 'plain':
  1139. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1140. break;
  1141. case 'inline':
  1142. $body .= $this->GetBoundary($this->boundary[1], '', '', '');
  1143. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1144. $body .= $this->LE.$this->LE;
  1145. $body .= $this->AttachAll("inline", $this->boundary[1]);
  1146. break;
  1147. case 'attach':
  1148. $body .= $this->GetBoundary($this->boundary[1], '', '', '');
  1149. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1150. $body .= $this->LE.$this->LE;
  1151. $body .= $this->AttachAll("attachment", $this->boundary[1]);
  1152. break;
  1153. case 'inline_attach':
  1154. $body .= $this->TextLine("--" . $this->boundary[1]);
  1155. $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
  1156. $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
  1157. $body .= $this->LE;
  1158. $body .= $this->GetBoundary($this->boundary[2], '', '', '');
  1159. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1160. $body .= $this->LE.$this->LE;
  1161. $body .= $this->AttachAll("inline", $this->boundary[2]);
  1162. $body .= $this->LE;
  1163. $body .= $this->AttachAll("attachment", $this->boundary[1]);
  1164. break;
  1165. case 'alt':
  1166. $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
  1167. $body .= $this->EncodeString($this->AltBody, $this->Encoding);
  1168. $body .= $this->LE.$this->LE;
  1169. $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
  1170. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1171. $body .= $this->LE.$this->LE;
  1172. $body .= $this->EndBoundary($this->boundary[1]);
  1173. break;
  1174. case 'alt_inline':
  1175. $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
  1176. $body .= $this->EncodeString($this->AltBody, $this->Encoding);
  1177. $body .= $this->LE.$this->LE;
  1178. $body .= $this->TextLine("--" . $this->boundary[1]);
  1179. $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
  1180. $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
  1181. $body .= $this->LE;
  1182. $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
  1183. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1184. $body .= $this->LE.$this->LE;
  1185. $body .= $this->AttachAll("inline", $this->boundary[2]);
  1186. $body .= $this->LE;
  1187. $body .= $this->EndBoundary($this->boundary[1]);
  1188. break;
  1189. case 'alt_attach':
  1190. $body .= $this->TextLine("--" . $this->boundary[1]);
  1191. $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
  1192. $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
  1193. $body .= $this->LE;
  1194. $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
  1195. $body .= $this->EncodeString($this->AltBody, $this->Encoding);
  1196. $body .= $this->LE.$this->LE;
  1197. $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
  1198. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1199. $body .= $this->LE.$this->LE;
  1200. $body .= $this->EndBoundary($this->boundary[2]);
  1201. $body .= $this->LE;
  1202. $body .= $this->AttachAll("attachment", $this->boundary[1]);
  1203. break;
  1204. case 'alt_inline_attach':
  1205. $body .= $this->TextLine("--" . $this->boundary[1]);
  1206. $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
  1207. $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
  1208. $body .= $this->LE;
  1209. $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
  1210. $body .= $this->EncodeString($this->AltBody, $this->Encoding);
  1211. $body .= $this->LE.$this->LE;
  1212. $body .= $this->TextLine("--" . $this->boundary[2]);
  1213. $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
  1214. $body .= $this->TextLine("\tboundary=\"" . $this->boundary[3] . '"');
  1215. $body .= $this->LE;
  1216. $body .= $this->GetBoundary($this->boundary[3], '', 'text/html', '');
  1217. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1218. $body .= $this->LE.$this->LE;
  1219. $body .= $this->AttachAll("inline", $this->boundary[3]);
  1220. $body .= $this->LE;
  1221. $body .= $this->EndBoundary($this->boundary[2]);
  1222. $body .= $this->LE;
  1223. $body .= $this->AttachAll("attachment", $this->boundary[1]);
  1224. break;
  1225. }
  1226. if ($this->IsError()) {
  1227. $body = '';
  1228. } elseif ($this->sign_key_file) {
  1229. try {
  1230. $file = tempnam('', 'mail');
  1231. file_put_contents($file, $body); //TODO check this worked
  1232. $signed = tempnam("", "signed");
  1233. if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
  1234. @unlink($file);
  1235. @unlink($signed);
  1236. $body = file_get_contents($signed);
  1237. } else {
  1238. @unlink($file);
  1239. @unlink($signed);
  1240. throw new phpmailerException($this->Lang("signing").openssl_error_string());
  1241. }
  1242. } catch (phpmailerException $e) {
  1243. $body = '';
  1244. if ($this->exceptions) {
  1245. throw $e;
  1246. }
  1247. }
  1248. }
  1249. return $body;
  1250. }
  1251. /**
  1252. * Returns the start of a message boundary.
  1253. * @access protected
  1254. * @return string
  1255. */
  1256. protected function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  1257. $result = '';
  1258. if($charSet == '') {
  1259. $charSet = $this->CharSet;
  1260. }
  1261. if($contentType == '') {
  1262. $contentType = $this->ContentType;
  1263. }
  1264. if($encoding == '') {
  1265. $encoding = $this->Encoding;
  1266. }
  1267. $result .= $this->TextLine('--' . $boundary);
  1268. $result .= sprintf("Content-Type: %s; charset=\"%s\"", $contentType, $charSet);
  1269. $result .= $this->LE;
  1270. $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
  1271. $result .= $this->LE;
  1272. return $result;
  1273. }
  1274. /**
  1275. * Returns the end of a message boundary.
  1276. * @access protected
  1277. * @return string
  1278. */
  1279. protected function EndBoundary($boundary) {
  1280. return $this->LE . '--' . $boundary . '--' . $this->LE;
  1281. }
  1282. /**
  1283. * Sets the message type.
  1284. * @access protected
  1285. * @return void
  1286. */
  1287. protected function SetMessageType() {
  1288. $this->message_type = array();
  1289. if($this->AlternativeExists()) $this->message_type[] = "alt";
  1290. if($this->InlineImageExists()) $this->message_type[] = "inline";
  1291. if($this->AttachmentExists()) $this->message_type[] = "attach";
  1292. $this->message_type = implode("_", $this->message_type);
  1293. if($this->message_type == "") $this->message_type = "plain";
  1294. }
  1295. /**
  1296. * Returns a formatted header line.
  1297. * @access public
  1298. * @return string
  1299. */
  1300. public function HeaderLine($name, $value) {
  1301. return $name . ': ' . $value . $this->LE;
  1302. }
  1303. /**
  1304. * Returns a formatted mail line.
  1305. * @access public
  1306. * @return string
  1307. */
  1308. public function TextLine($value) {
  1309. return $value . $this->LE;
  1310. }
  1311. /////////////////////////////////////////////////
  1312. // CLASS METHODS, ATTACHMENTS
  1313. /////////////////////////////////////////////////
  1314. /**
  1315. * Adds an attachment from a path on the filesystem.
  1316. * Returns false if the file could not be found
  1317. * or accessed.
  1318. * @param string $path Path to the attachment.
  1319. * @param string $name Overrides the attachment name.
  1320. * @param string $encoding File encoding (see $Encoding).
  1321. * @param string $type File extension (MIME) type.
  1322. * @return bool
  1323. */
  1324. public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1325. try {
  1326. if ( !@is_file($path) ) {
  1327. throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE);
  1328. }
  1329. $filename = basename($path);
  1330. if ( $name == '' ) {
  1331. $name = $filename;
  1332. }
  1333. $this->attachment[] = array(
  1334. 0 => $path,
  1335. 1 => $filename,
  1336. 2 => $name,
  1337. 3 => $encoding,
  1338. 4 => $type,
  1339. 5 => false, // isStringAttachment
  1340. 6 => 'attachment',
  1341. 7 => 0
  1342. );
  1343. } catch (phpmailerException $e) {
  1344. $this->SetError($e->getMessage());
  1345. if ($this->exceptions) {
  1346. throw $e;
  1347. }
  1348. echo $e->getMessage()."\n";
  1349. if ( $e->getCode() == self::STOP_CRITICAL ) {
  1350. return false;
  1351. }
  1352. }
  1353. return true;
  1354. }
  1355. /**
  1356. * Return the current array of attachments
  1357. * @return array
  1358. */
  1359. public function GetAttachments() {
  1360. return $this->attachment;
  1361. }
  1362. /**
  1363. * Attaches all fs, string, and binary attachments to the message.
  1364. * Returns an empty string on failure.
  1365. * @access protected
  1366. * @return string
  1367. */
  1368. protected function AttachAll($disposition_type, $boundary) {
  1369. // Return text of body
  1370. $mime = array();
  1371. $cidUniq = array();
  1372. $incl = array();
  1373. // Add all attachments
  1374. foreach ($this->attachment as $attachment) {
  1375. // CHECK IF IT IS A VALID DISPOSITION_FILTER
  1376. if($attachment[6] == $disposition_type) {
  1377. // Check for string attachment
  1378. $bString = $attachment[5];
  1379. if ($bString) {
  1380. $string = $attachment[0];
  1381. } else {
  1382. $path = $attachment[0];
  1383. }
  1384. $inclhash = md5(serialize($attachment));
  1385. if (in_array($inclhash, $incl)) { continue; }
  1386. $incl[] = $inclhash;
  1387. $filename = $attachment[1];
  1388. $name = $attachment[2];
  1389. $encoding = $attachment[3];
  1390. $type = $attachment[4];
  1391. $disposition = $attachment[6];
  1392. $cid = $attachment[7];
  1393. if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
  1394. $cidUniq[$cid] = true;
  1395. $mime[] = sprintf("--%s%s", $boundary, $this->LE);
  1396. $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
  1397. $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  1398. if($disposition == 'inline') {
  1399. $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  1400. }
  1401. $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
  1402. // Encode as string attachment
  1403. if($bString) {
  1404. $mime[] = $this->EncodeString($string, $encoding);
  1405. if($this->IsError()) {
  1406. return '';
  1407. }
  1408. $mime[] = $this->LE.$this->LE;
  1409. } else {
  1410. $mime[] = $this->EncodeFile($path, $encoding);
  1411. if($this->IsError()) {
  1412. return '';
  1413. }
  1414. $mime[] = $this->LE.$this->LE;
  1415. }
  1416. }
  1417. }
  1418. $mime[] = sprintf("--%s--%s", $boundary, $this->LE);
  1419. return implode("", $mime);
  1420. }
  1421. /**
  1422. * Encodes attachment in requested format.
  1423. * Returns an empty string on failure.
  1424. * @param string $path The full path to the file
  1425. * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  1426. * @see EncodeFile()
  1427. * @access protected
  1428. * @return string
  1429. */
  1430. protected function EncodeFile($path, $encoding = 'base64') {
  1431. try {
  1432. if (!is_readable($path)) {
  1433. throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
  1434. }
  1435. if (function_exists('get_magic_quotes')) {
  1436. function get_magic_quotes() {
  1437. return false;
  1438. }
  1439. }
  1440. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  1441. $magic_quotes = get_magic_quotes_runtime();
  1442. set_magic_quotes_runtime(0);
  1443. }
  1444. $file_buffer = file_get_contents($path);
  1445. $file_buffer = $this->EncodeString($file_buffer, $encoding);
  1446. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  1447. set_magic_quotes_runtime($magic_quotes);
  1448. }
  1449. return $file_buffer;
  1450. } catch (Exception $e) {
  1451. $this->SetError($e->getMessage());
  1452. return '';
  1453. }
  1454. }
  1455. /**
  1456. * Encodes string to requested format.
  1457. * Returns an empty string on failure.
  1458. * @param string $str The text to encode
  1459. * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  1460. * @access public
  1461. * @return string
  1462. */
  1463. public function EncodeString($str, $encoding = 'base64') {
  1464. $encoded = '';
  1465. switch(strtolower($encoding)) {
  1466. case 'base64':
  1467. $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  1468. break;
  1469. case '7bit':
  1470. case '8bit':
  1471. $encoded = $this->FixEOL($str);
  1472. //Make sure it ends with a line break
  1473. if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  1474. $encoded .= $this->LE;
  1475. break;
  1476. case 'binary':
  1477. $encoded = $str;
  1478. break;
  1479. case 'quoted-printable':
  1480. $encoded = $this->EncodeQP($str);
  1481. break;
  1482. default:
  1483. $this->SetError($this->Lang('encoding') . $encoding);
  1484. break;
  1485. }
  1486. return $encoded;
  1487. }
  1488. /**
  1489. * Encode a header string to best (shortest) of Q, B, quoted or none.
  1490. * @access public
  1491. * @return string
  1492. */
  1493. public function EncodeHeader($str, $position = 'text') {
  1494. $x = 0;
  1495. switch (strtolower($position)) {
  1496. case 'phrase':
  1497. if (!preg_match('/[\200-\377]/', $str)) {
  1498. // Can't use addslashes as we don't know what value has magic_quotes_sybase
  1499. $encoded = addcslashes($str, "\0..\37\177\\\"");
  1500. if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  1501. return ($encoded);
  1502. } else {
  1503. return ("\"$encoded\"");
  1504. }
  1505. }
  1506. $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  1507. break;
  1508. case 'comment':
  1509. $x = preg_match_all('/[()"]/', $str, $matches);
  1510. // Fall-through
  1511. case 'text':
  1512. default:
  1513. $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  1514. break;
  1515. }
  1516. if ($x == 0) {
  1517. return ($str);
  1518. }
  1519. $maxlen = 75 - 7 - strlen($this->CharSet);
  1520. // Try to select the encoding which should produce the shortest output
  1521. if (strlen($str)/3 < $x) {
  1522. $encoding = 'B';
  1523. if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
  1524. // Use a custom function which correctly encodes and wraps long
  1525. // multibyte strings without breaking lines within a character
  1526. $encoded = $this->Base64EncodeWrapMB($str);
  1527. } else {
  1528. $encoded = base64_encode($str);
  1529. $maxlen -= $maxlen % 4;
  1530. $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  1531. }
  1532. } else {
  1533. $encoding = 'Q';
  1534. $encoded = $this->EncodeQ($str, $position);
  1535. $encoded = $this->WrapText($encoded, $maxlen, true);
  1536. $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
  1537. }
  1538. $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  1539. $encoded = trim(str_replace("\n", $this->LE, $encoded));
  1540. return $encoded;
  1541. }
  1542. /**
  1543. * Checks if a string contains multibyte characters.
  1544. * @access public
  1545. * @param string $str multi-byte text to wrap encode
  1546. * @return bool
  1547. */
  1548. public function HasMultiBytes($str) {
  1549. if (function_exists('mb_strlen')) {
  1550. return (strlen($str) > mb_strlen($str, $this->CharSet));
  1551. } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  1552. return false;
  1553. }
  1554. }
  1555. /**
  1556. * Correctly encodes and wraps long multibyte strings for mail headers
  1557. * without breaking lines within a character.
  1558. * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
  1559. * @access public
  1560. * @param string $str multi-byte text to wrap encode
  1561. * @return string
  1562. */
  1563. public function Base64EncodeWrapMB($str) {
  1564. $start = "=?".$this->CharSet."?B?";
  1565. $end = "?=";
  1566. $encoded = "";
  1567. $mb_length = mb_strlen($str, $this->CharSet);
  1568. // Each line must have length <= 75, including $start and $end
  1569. $length = 75 - strlen($start) - strlen($end);
  1570. // Average multi-byte ratio
  1571. $ratio = $mb_length / strlen($str);
  1572. // Base64 has a 4:3 ratio
  1573. $offset = $avgLength = floor($length * $ratio * .75);
  1574. for ($i = 0; $i < $mb_length; $i += $offset) {
  1575. $lookBack = 0;
  1576. do {
  1577. $offset = $avgLength - $lookBack;
  1578. $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  1579. $chunk = base64_encode($chunk);
  1580. $lookBack++;
  1581. }
  1582. while (strlen($chunk) > $length);
  1583. $encoded .= $chunk . $this->LE;
  1584. }
  1585. // Chomp the last linefeed
  1586. $encoded = substr($encoded, 0, -strlen($this->LE));
  1587. return $encoded;
  1588. }
  1589. /**
  1590. * Encode string to quoted-printable.
  1591. * Only uses standard PHP, slow, but will always work
  1592. * @access public
  1593. * @param string $string the text to encode
  1594. * @param integer $line_max Number of chars allowed on a line before wrapping
  1595. * @return string
  1596. */
  1597. public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
  1598. $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
  1599. $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
  1600. $eol = "\r\n";
  1601. $escape = '=';
  1602. $output = '';
  1603. while( list(, $line) = each($lines) ) {
  1604. $linlen = strlen($line);
  1605. $newline = '';
  1606. for($i = 0; $i < $linlen; $i++) {
  1607. $c = substr( $line, $i, 1 );
  1608. $dec = ord( $c );
  1609. if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
  1610. $c = '=2E';
  1611. }
  1612. if ( $dec == 32 ) {
  1613. if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
  1614. $c = '=20';
  1615. } else if ( $space_conv ) {
  1616. $c = '=20';
  1617. }
  1618. } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
  1619. $h2 = floor($dec/16);
  1620. $h1 = floor($dec%16);
  1621. $c = $escape.$hex[$h2].$hex[$h1];
  1622. }
  1623. if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
  1624. $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
  1625. $newline = '';
  1626. // check if newline first character will be point or not
  1627. if ( $dec == 46 ) {
  1628. $c = '=2E';
  1629. }
  1630. }
  1631. $newline .= $c;
  1632. } // end of for
  1633. $output .= $newline.$eol;
  1634. } // end of while
  1635. return $output;
  1636. }
  1637. /**
  1638. * Encode string to RFC2045 (6.7) quoted-printable format
  1639. * Uses a PHP5 stream filter to do the encoding about 64x faster than the old version
  1640. * Also results in same content as you started with after decoding
  1641. * @see EncodeQPphp()
  1642. * @access public
  1643. * @param string $string the text to encode
  1644. * @param integer $line_max Number of chars allowed on a line before wrapping
  1645. * @param boolean $space_conv Dummy param for compatibility with existing EncodeQP function
  1646. * @return string
  1647. * @author Marcus Bointon
  1648. */
  1649. public function EncodeQP($string, $line_max = 76, $space_conv = false) {
  1650. if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3)
  1651. return quoted_printable_encode($string);
  1652. }
  1653. $filters = stream_get_filters();
  1654. if (!in_array('convert.*', $filters)) { //Got convert stream filter?
  1655. return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation
  1656. }
  1657. $fp = fopen('php://temp/', 'r+');
  1658. $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks
  1659. $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE);
  1660. $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
  1661. fputs($fp, $string);
  1662. rewind($fp);
  1663. $out = stream_get_contents($fp);
  1664. stream_filter_remove($s);
  1665. $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange
  1666. fclose($fp);
  1667. return $out;
  1668. }
  1669. /**
  1670. * Encode string to q encoding.
  1671. * @link http://tools.ietf.org/html/rfc2047
  1672. * @param string $str the text to encode
  1673. * @param string $position Where the text is going to be used, see the RFC for what that means
  1674. * @access public
  1675. * @return string
  1676. */
  1677. public function EncodeQ($str, $position = 'text') {
  1678. // There should not be any EOL in the string
  1679. $encoded = preg_replace('/[\r\n]*/', '', $str);
  1680. switch (strtolower($position)) {
  1681. case 'phrase':
  1682. $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1683. break;
  1684. case 'comment':
  1685. $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1686. case 'text':
  1687. default:
  1688. // Replace every high ascii, control =, ? and _ characters
  1689. //TODO using /e (equivalent to eval()) is probably not a good idea
  1690. $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
  1691. "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded);
  1692. break;
  1693. }
  1694. // Replace every spaces to _ (more readable than =20)
  1695. $encoded = str_replace(' ', '_', $encoded);
  1696. return $encoded;
  1697. }
  1698. /**
  1699. * Adds a string or binary attachment (non-filesystem) to the list.
  1700. * This method can be used to attach ascii or binary data,
  1701. * such as a BLOB record from a database.
  1702. * @param string $string String attachment data.
  1703. * @param string $filename Name of the attachment.
  1704. * @param string $encoding File encoding (see $Encoding).
  1705. * @param string $type File extension (MIME) type.
  1706. * @return void
  1707. */
  1708. public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
  1709. // Append to $attachment array
  1710. $this->attachment[] = array(
  1711. 0 => $string,
  1712. 1 => $filename,
  1713. 2 => basename($filename),
  1714. 3 => $encoding,
  1715. 4 => $type,
  1716. 5 => true, // isStringAttachment
  1717. 6 => 'attachment',
  1718. 7 => 0
  1719. );
  1720. }
  1721. /**
  1722. * Adds an embedded attachment. This can include images, sounds, and
  1723. * just about any other document. Make sure to set the $type to an
  1724. * image type. For JPEG images use "image/jpeg" and for GIF images
  1725. * use "image/gif".
  1726. * @param string $path Path to the attachment.
  1727. * @param string $cid Content ID of the attachment. Use this to identify
  1728. * the Id for accessing the image in an HTML form.
  1729. * @param string $name Overrides the attachment name.
  1730. * @param string $encoding File encoding (see $Encoding).
  1731. * @param string $type File extension (MIME) type.
  1732. * @return bool
  1733. */
  1734. public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1735. if ( !@is_file($path) ) {
  1736. $this->SetError($this->Lang('file_access') . $path);
  1737. return false;
  1738. }
  1739. $filename = basename($path);
  1740. if ( $name == '' ) {
  1741. $name = $filename;
  1742. }
  1743. // Append to $attachment array
  1744. $this->attachment[] = array(
  1745. 0 => $path,
  1746. 1 => $filename,
  1747. 2 => $name,
  1748. 3 => $encoding,
  1749. 4 => $type,
  1750. 5 => false, // isStringAttachment
  1751. 6 => 'inline',
  1752. 7 => $cid
  1753. );
  1754. return true;
  1755. }
  1756. public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1757. // Append to $attachment array
  1758. $this->attachment[] = array(
  1759. 0 => $string,
  1760. 1 => $filename,
  1761. 2 => basename($filename),
  1762. 3 => $encoding,
  1763. 4 => $type,
  1764. 5 => true, // isStringAttachment
  1765. 6 => 'inline',
  1766. 7 => $cid
  1767. );
  1768. }
  1769. /**
  1770. * Returns true if an inline attachment is present.
  1771. * @access public
  1772. * @return bool
  1773. */
  1774. public function InlineImageExists() {
  1775. foreach($this->attachment as $attachment) {
  1776. if ($attachment[6] == 'inline') {
  1777. return true;
  1778. }
  1779. }
  1780. return false;
  1781. }
  1782. public function AttachmentExists() {
  1783. foreach($this->attachment as $attachment) {
  1784. if ($attachment[6] == 'attachment') {
  1785. return true;
  1786. }
  1787. }
  1788. return false;
  1789. }
  1790. public function AlternativeExists() {
  1791. return strlen($this->AltBody)>0;
  1792. }
  1793. /////////////////////////////////////////////////
  1794. // CLASS METHODS, MESSAGE RESET
  1795. /////////////////////////////////////////////////
  1796. /**
  1797. * Clears all recipients assigned in the TO array. Returns void.
  1798. * @return void
  1799. */
  1800. public function ClearAddresses() {
  1801. foreach($this->to as $to) {
  1802. unset($this->all_recipients[strtolower($to[0])]);
  1803. }
  1804. $this->to = array();
  1805. }
  1806. /**
  1807. * Clears all recipients assigned in the CC array. Returns void.
  1808. * @return void
  1809. */
  1810. public function ClearCCs() {
  1811. foreach($this->cc as $cc) {
  1812. unset($this->all_recipients[strtolower($cc[0])]);
  1813. }
  1814. $this->cc = array();
  1815. }
  1816. /**
  1817. * Clears all recipients assigned in the BCC array. Returns void.
  1818. * @return void
  1819. */
  1820. public function ClearBCCs() {
  1821. foreach($this->bcc as $bcc) {
  1822. unset($this->all_recipients[strtolower($bcc[0])]);
  1823. }
  1824. $this->bcc = array();
  1825. }
  1826. /**
  1827. * Clears all recipients assigned in the ReplyTo array. Returns void.
  1828. * @return void
  1829. */
  1830. public function ClearReplyTos() {
  1831. $this->ReplyTo = array();
  1832. }
  1833. /**
  1834. * Clears all recipients assigned in the TO, CC and BCC
  1835. * array. Returns void.
  1836. * @return void
  1837. */
  1838. public function ClearAllRecipients() {
  1839. $this->to = array();
  1840. $this->cc = array();
  1841. $this->bcc = array();
  1842. $this->all_recipients = array();
  1843. }
  1844. /**
  1845. * Clears all previously set filesystem, string, and binary
  1846. * attachments. Returns void.
  1847. * @return void
  1848. */
  1849. public function ClearAttachments() {
  1850. $this->attachment = array();
  1851. }
  1852. /**
  1853. * Clears all custom headers. Returns void.
  1854. * @return void
  1855. */
  1856. public function ClearCustomHeaders() {
  1857. $this->CustomHeader = array();
  1858. }
  1859. /////////////////////////////////////////////////
  1860. // CLASS METHODS, MISCELLANEOUS
  1861. /////////////////////////////////////////////////
  1862. /**
  1863. * Adds the error message to the error container.
  1864. * @access protected
  1865. * @return void
  1866. */
  1867. protected function SetError($msg) {
  1868. $this->error_count++;
  1869. if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
  1870. $lasterror = $this->smtp->getError();
  1871. if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
  1872. $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
  1873. }
  1874. }
  1875. $this->ErrorInfo = $msg;
  1876. }
  1877. /**
  1878. * Returns the proper RFC 822 formatted date.
  1879. * @access public
  1880. * @return string
  1881. * @static
  1882. */
  1883. public static function RFCDate() {
  1884. $tz = date('Z');
  1885. $tzs = ($tz < 0) ? '-' : '+';
  1886. $tz = abs($tz);
  1887. $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
  1888. $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
  1889. return $result;
  1890. }
  1891. /**
  1892. * Returns the server hostname or 'localhost.localdomain' if unknown.
  1893. * @access protected
  1894. * @return string
  1895. */
  1896. protected function ServerHostname() {
  1897. if (!empty($this->Hostname)) {
  1898. $result = $this->Hostname;
  1899. } elseif (isset($_SERVER['SERVER_NAME'])) {
  1900. $result = $_SERVER['SERVER_NAME'];
  1901. } else {
  1902. $result = 'localhost.localdomain';
  1903. }
  1904. return $result;
  1905. }
  1906. /**
  1907. * Returns a message in the appropriate language.
  1908. * @access protected
  1909. * @return string
  1910. */
  1911. protected function Lang($key) {
  1912. if(count($this->language) < 1) {
  1913. $this->SetLanguage('en'); // set the default language
  1914. }
  1915. if(isset($this->language[$key])) {
  1916. return $this->language[$key];
  1917. } else {
  1918. return 'Language string failed to load: ' . $key;
  1919. }
  1920. }
  1921. /**
  1922. * Returns true if an error occurred.
  1923. * @access public
  1924. * @return bool
  1925. */
  1926. public function IsError() {
  1927. return ($this->error_count > 0);
  1928. }
  1929. /**
  1930. * Changes every end of line from CR or LF to CRLF.
  1931. * @access public
  1932. * @return string
  1933. */
  1934. public function FixEOL($str) {
  1935. $str = str_replace("\r\n", "\n", $str);
  1936. $str = str_replace("\r", "\n", $str);
  1937. $str = str_replace("\n", $this->LE, $str);
  1938. return $str;
  1939. }
  1940. /**
  1941. * Adds a custom header.
  1942. * @access public
  1943. * @return void
  1944. */
  1945. public function AddCustomHeader($custom_header) {
  1946. $this->CustomHeader[] = explode(':', $custom_header, 2);
  1947. }
  1948. /**
  1949. * Evaluates the message and returns modifications for inline images and backgrounds
  1950. * @access public
  1951. * @return $message
  1952. */
  1953. public function MsgHTML($message, $basedir = '') {
  1954. preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
  1955. if(isset($images[2])) {
  1956. foreach($images[2] as $i => $url) {
  1957. // do not change urls for absolute images (thanks to corvuscorax)
  1958. if (!preg_match('#^[A-z]+://#', $url)) {
  1959. $filename = basename($url);
  1960. $directory = dirname($url);
  1961. ($directory == '.') ? $directory='': '';
  1962. $cid = 'cid:' . md5($filename);
  1963. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  1964. $mimeType = self::_mime_types($ext);
  1965. if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; }
  1966. if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
  1967. if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) {
  1968. $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
  1969. }
  1970. }
  1971. }
  1972. }
  1973. $this->IsHTML(true);
  1974. $this->Body = $message;
  1975. $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
  1976. if (!empty($textMsg) && empty($this->AltBody)) {
  1977. $this->AltBody = html_entity_decode($textMsg);
  1978. }
  1979. if (empty($this->AltBody)) {
  1980. $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
  1981. }
  1982. }
  1983. /**
  1984. * Gets the MIME type of the embedded or inline image
  1985. * @param string File extension
  1986. * @access public
  1987. * @return string MIME type of ext
  1988. * @static
  1989. */
  1990. public static function _mime_types($ext = '') {
  1991. $mimes = array(
  1992. 'hqx' => 'application/mac-binhex40',
  1993. 'cpt' => 'application/mac-compactpro',
  1994. 'doc' => 'application/msword',
  1995. 'bin' => 'application/macbinary',
  1996. 'dms' => 'application/octet-stream',
  1997. 'lha' => 'application/octet-stream',
  1998. 'lzh' => 'application/octet-stream',
  1999. 'exe' => 'application/octet-stream',
  2000. 'class' => 'application/octet-stream',
  2001. 'psd' => 'application/octet-stream',
  2002. 'so' => 'application/octet-stream',
  2003. 'sea' => 'application/octet-stream',
  2004. 'dll' => 'application/octet-stream',
  2005. 'oda' => 'application/oda',
  2006. 'pdf' => 'application/pdf',
  2007. 'ai' => 'application/postscript',
  2008. 'eps' => 'application/postscript',
  2009. 'ps' => 'application/postscript',
  2010. 'smi' => 'application/smil',
  2011. 'smil' => 'application/smil',
  2012. 'mif' => 'application/vnd.mif',
  2013. 'xls' => 'application/vnd.ms-excel',
  2014. 'ppt' => 'application/vnd.ms-powerpoint',
  2015. 'wbxml' => 'application/vnd.wap.wbxml',
  2016. 'wmlc' => 'application/vnd.wap.wmlc',
  2017. 'dcr' => 'application/x-director',
  2018. 'dir' => 'application/x-director',
  2019. 'dxr' => 'application/x-director',
  2020. 'dvi' => 'application/x-dvi',
  2021. 'gtar' => 'application/x-gtar',
  2022. 'php' => 'application/x-httpd-php',
  2023. 'php4' => 'application/x-httpd-php',
  2024. 'php3' => 'application/x-httpd-php',
  2025. 'phtml' => 'application/x-httpd-php',
  2026. 'phps' => 'application/x-httpd-php-source',
  2027. 'js' => 'application/x-javascript',
  2028. 'swf' => 'application/x-shockwave-flash',
  2029. 'sit' => 'application/x-stuffit',
  2030. 'tar' => 'application/x-tar',
  2031. 'tgz' => 'application/x-tar',
  2032. 'xhtml' => 'application/xhtml+xml',
  2033. 'xht' => 'application/xhtml+xml',
  2034. 'zip' => 'application/zip',
  2035. 'mid' => 'audio/midi',
  2036. 'midi' => 'audio/midi',
  2037. 'mpga' => 'audio/mpeg',
  2038. 'mp2' => 'audio/mpeg',
  2039. 'mp3' => 'audio/mpeg',
  2040. 'aif' => 'audio/x-aiff',
  2041. 'aiff' => 'audio/x-aiff',
  2042. 'aifc' => 'audio/x-aiff',
  2043. 'ram' => 'audio/x-pn-realaudio',
  2044. 'rm' => 'audio/x-pn-realaudio',
  2045. 'rpm' => 'audio/x-pn-realaudio-plugin',
  2046. 'ra' => 'audio/x-realaudio',
  2047. 'rv' => 'video/vnd.rn-realvideo',
  2048. 'wav' => 'audio/x-wav',
  2049. 'bmp' => 'image/bmp',
  2050. 'gif' => 'image/gif',
  2051. 'jpeg' => 'image/jpeg',
  2052. 'jpg' => 'image/jpeg',
  2053. 'jpe' => 'image/jpeg',
  2054. 'png' => 'image/png',
  2055. 'tiff' => 'image/tiff',
  2056. 'tif' => 'image/tiff',
  2057. 'css' => 'text/css',
  2058. 'html' => 'text/html',
  2059. 'htm' => 'text/html',
  2060. 'shtml' => 'text/html',
  2061. 'txt' => 'text/plain',
  2062. 'text' => 'text/plain',
  2063. 'log' => 'text/plain',
  2064. 'rtx' => 'text/richtext',
  2065. 'rtf' => 'text/rtf',
  2066. 'xml' => 'text/xml',
  2067. 'xsl' => 'text/xml',
  2068. 'mpeg' => 'video/mpeg',
  2069. 'mpg' => 'video/mpeg',
  2070. 'mpe' => 'video/mpeg',
  2071. 'qt' => 'video/quicktime',
  2072. 'mov' => 'video/quicktime',
  2073. 'avi' => 'video/x-msvideo',
  2074. 'movie' => 'video/x-sgi-movie',
  2075. 'doc' => 'application/msword',
  2076. 'word' => 'application/msword',
  2077. 'xl' => 'application/excel',
  2078. 'eml' => 'message/rfc822'
  2079. );
  2080. return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
  2081. }
  2082. /**
  2083. * Set (or reset) Class Objects (variables)
  2084. *
  2085. * Usage Example:
  2086. * $page->set('X-Priority', '3');
  2087. *
  2088. * @access public
  2089. * @param string $name Parameter Name
  2090. * @param mixed $value Parameter Value
  2091. * NOTE: will not work with arrays, there are no arrays to set/reset
  2092. * @todo Should this not be using __set() magic function?
  2093. */
  2094. public function set($name, $value = '') {
  2095. try {
  2096. if (isset($this->$name) ) {
  2097. $this->$name = $value;
  2098. } else {
  2099. throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL);
  2100. }
  2101. } catch (Exception $e) {
  2102. $this->SetError($e->getMessage());
  2103. if ($e->getCode() == self::STOP_CRITICAL) {
  2104. return false;
  2105. }
  2106. }
  2107. return true;
  2108. }
  2109. /**
  2110. * Strips newlines to prevent header injection.
  2111. * @access public
  2112. * @param string $str String
  2113. * @return string
  2114. */
  2115. public function SecureHeader($str) {
  2116. $str = str_replace("\r", '', $str);
  2117. $str = str_replace("\n", '', $str);
  2118. return trim($str);
  2119. }
  2120. /**
  2121. * Set the private key file and password to sign the message.
  2122. *
  2123. * @access public
  2124. * @param string $key_filename Parameter File Name
  2125. * @param string $key_pass Password for private key
  2126. */
  2127. public function Sign($cert_filename, $key_filename, $key_pass) {
  2128. $this->sign_cert_file = $cert_filename;
  2129. $this->sign_key_file = $key_filename;
  2130. $this->sign_key_pass = $key_pass;
  2131. }
  2132. /**
  2133. * Set the private key file and password to sign the message.
  2134. *
  2135. * @access public
  2136. * @param string $key_filename Parameter File Name
  2137. * @param string $key_pass Password for private key
  2138. */
  2139. public function DKIM_QP($txt) {
  2140. $tmp = '';
  2141. $line = '';
  2142. for ($i = 0; $i < strlen($txt); $i++) {
  2143. $ord = ord($txt[$i]);
  2144. if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) {
  2145. $line .= $txt[$i];
  2146. } else {
  2147. $line .= "=".sprintf("%02X", $ord);
  2148. }
  2149. }
  2150. return $line;
  2151. }
  2152. /**
  2153. * Generate DKIM signature
  2154. *
  2155. * @access public
  2156. * @param string $s Header
  2157. */
  2158. public function DKIM_Sign($s) {
  2159. $privKeyStr = file_get_contents($this->DKIM_private);
  2160. if ($this->DKIM_passphrase != '') {
  2161. $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
  2162. } else {
  2163. $privKey = $privKeyStr;
  2164. }
  2165. if (openssl_sign($s, $signature, $privKey)) {
  2166. return base64_encode($signature);
  2167. }
  2168. }
  2169. /**
  2170. * Generate DKIM Canonicalization Header
  2171. *
  2172. * @access public
  2173. * @param string $s Header
  2174. */
  2175. public function DKIM_HeaderC($s) {
  2176. $s = preg_replace("/\r\n\s+/", " ", $s);
  2177. $lines = explode("\r\n", $s);
  2178. foreach ($lines as $key => $line) {
  2179. list($heading, $value) = explode(":", $line, 2);
  2180. $heading = strtolower($heading);
  2181. $value = preg_replace("/\s+/", " ", $value) ; // Compress useless spaces
  2182. $lines[$key] = $heading.":".trim($value) ; // Don't forget to remove WSP around the value
  2183. }
  2184. $s = implode("\r\n", $lines);
  2185. return $s;
  2186. }
  2187. /**
  2188. * Generate DKIM Canonicalization Body
  2189. *
  2190. * @access public
  2191. * @param string $body Message Body
  2192. */
  2193. public function DKIM_BodyC($body) {
  2194. if ($body == '') return "\r\n";
  2195. // stabilize line endings
  2196. $body = str_replace("\r\n", "\n", $body);
  2197. $body = str_replace("\n", "\r\n", $body);
  2198. // END stabilize line endings
  2199. while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
  2200. $body = substr($body, 0, strlen($body) - 2);
  2201. }
  2202. return $body;
  2203. }
  2204. /**
  2205. * Create the DKIM header, body, as new header
  2206. *
  2207. * @access public
  2208. * @param string $headers_line Header lines
  2209. * @param string $subject Subject
  2210. * @param string $body Body
  2211. */
  2212. public function DKIM_Add($headers_line, $subject, $body) {
  2213. $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
  2214. $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
  2215. $DKIMquery = 'dns/txt'; // Query method
  2216. $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
  2217. $subject_header = "Subject: $subject";
  2218. $headers = explode($this->LE, $headers_line);
  2219. foreach($headers as $header) {
  2220. if (strpos($header, 'From:') === 0) {
  2221. $from_header = $header;
  2222. } elseif (strpos($header, 'To:') === 0) {
  2223. $to_header = $header;
  2224. }
  2225. }
  2226. $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
  2227. $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
  2228. $subject = str_replace('|', '=7C', $this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable
  2229. $body = $this->DKIM_BodyC($body);
  2230. $DKIMlen = strlen($body) ; // Length of body
  2231. $DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body
  2232. $ident = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";";
  2233. $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n".
  2234. "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n".
  2235. "\th=From:To:Subject;\r\n".
  2236. "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n".
  2237. "\tz=$from\r\n".
  2238. "\t|$to\r\n".
  2239. "\t|$subject;\r\n".
  2240. "\tbh=" . $DKIMb64 . ";\r\n".
  2241. "\tb=";
  2242. $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
  2243. $signed = $this->DKIM_Sign($toSign);
  2244. return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
  2245. }
  2246. protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) {
  2247. if (!empty($this->action_function) && function_exists($this->action_function)) {
  2248. $params = array($isSent, $to, $cc, $bcc, $subject, $body);
  2249. call_user_func_array($this->action_function, $params);
  2250. }
  2251. }
  2252. }
  2253. class phpmailerException extends Exception {
  2254. public function errorMessage() {
  2255. $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  2256. return $errorMsg;
  2257. }
  2258. }
  2259. ?>