[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

PHPMAILER Autoresponder doesn't send email & not inserting data from form into mysql database

Asked by tpiccirillo in PHP and Databases, MySQL Server

Tags: Codeworx Technologies, phpmailer-fe, 3.1, php

How do I get autoresponder to send email to subscriber and also send data to a program so it gets entered into mysql database.

I am using phpmailer-fe.  Data is entered into a form on website.  Program sends me an email when data is entered.  I want the program to send letter to the subscriber.  I set variable $useAsAutoResponder to true.  PHPMAILER-FE is not sending the email to the subscriber after data is entered on the form.  I also need the data to be sent to a program emailsignup.php to enter the data into mysql database.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619:
620:
621:
622:
623:
624:
625:
626:
627:
628:
629:
630:
631:
632:
633:
634:
635:
636:
637:
638:
639:
640:
641:
642:
643:
644:
645:
646:
647:
648:
649:
650:
651:
652:
653:
654:
655:
656:
657:
658:
659:
660:
661:
662:
663:
664:
665:
666:
667:
668:
669:
670:
671:
672:
673:
674:
675:
676:
677:
678:
679:
680:
681:
682:
683:
684:
685:
686:
687:
688:
689:
690:
691:
692:
693:
694:
695:
696:
697:
698:
699:
700:
701:
702:
703:
704:
705:
706:
707:
708:
709:
710:
711:
712:
713:
714:
715:
716:
717:
718:
719:
720:
721:
722:
723:
724:
725:
726:
727:
728:
729:
730:
731:
732:
733:
734:
735:
736:
737:
738:
739:
740:
741:
742:
743:
744:
745:
746:
747:
748:
749:
750:
751:
752:
753:
754:
755:
756:
757:
758:
759:
760:
761:
762:
763:
764:
765:
766:
767:
768:
769:
770:
771:
772:
773:
774:
775:
776:
777:
778:
779:
780:
781:
782:
783:
784:
785:
786:
787:
788:
789:
790:
791:
792:
793:
794:
795:
796:
797:
798:
799:
800:
801:
802:
803:
804:
805:
806:
807:
808:
809:
810:
811:
812:
813:
814:
815:
816:
817:
818:
819:
820:
821:
822:
823:
824:
825:
826:
827:
828:
829:
830:
831:
832:
833:
834:
835:
836:
837:
838:
839:
840:
841:
842:
843:
844:
845:
846:
847:
848:
849:
850:
851:
852:
853:
854:
855:
856:
857:
858:
859:
860:
861:
862:
863:
864:
865:
866:
867:
868:
869:
870:
871:
872:
873:
874:
875:
876:
877:
878:
879:
880:
881:
882:
883:
884:
885:
886:
887:
888:
889:
890:
891:
892:
893:
894:
895:
896:
897:
898:
899:
900:
901:
902:
903:
904:
905:
906:
907:
908:
909:
910:
911:
912:
913:
914:
915:
916:
917:
918:
919:
920:
921:
922:
923:
924:
925:
926:
927:
928:
929:
930:
931:
932:
933:
934:
935:
936:
937:
938:
939:
940:
941:
942:
943:
944:
945:
946:
947:
948:
949:
950:
951:
952:
953:
954:
955:
956:
957:
958:
959:
960:
961:
962:
963:
964:
965:
966:
967:
968:
969:
970:
971:
972:
973:
974:
975:
976:
977:
978:
979:
980:
981:
982:
983:
984:
985:
986:
987:
988:
989:
990:
991:
992:
993:
994:
995:
996:
997:
998:
999:
1000:
1001:
1002:
1003:
1004:
1005:
1006:
1007:
1008:
1009:
1010:
1011:
1012:
1013:
1014:
1015:
1016:
1017:
1018:
1019:
1020:
1021:
1022:
1023:
1024:
1025:
1026:
1027:
1028:
1029:
1030:
1031:
1032:
1033:
1034:
1035:
1036:
1037:
1038:
1039:
1040:
1041:
1042:
1043:
1044:
1045:
1046:
1047:
1048:
1049:
1050:
1051:
1052:
1053:
1054:
1055:
1056:
1057:
1058:
1059:
1060:
1061:
1062:
1063:
1064:
1065:
1066:
1067:
1068:
1069:
1070:
1071:
1072:
1073:
1074:
1075:
1076:
1077:
1078:
1079:
1080:
1081:
1082:
1083:
1084:
1085:
1086:
1087:
1088:
1089:
1090:
1091:
1092:
1093:
1094:
1095:
1096:
1097:
1098:
1099:
1100:
1101:
1102:
1103:
1104:
1105:
1106:
1107:
1108:
1109:
1110:
1111:
1112:
1113:
1114:
1115:
1116:
1117:
1118:
1119:
1120:
1121:
1122:
1123:
1124:
1125:
1126:
1127:
1128:
1129:
1130:
1131:
1132:
1133:
1134:
1135:
1136:
1137:
1138:
1139:
1140:
1141:
1142:
1143:
1144:
1145:
1146:
1147:
1148:
1149:
1150:
1151:
1152:
1153:
1154:
1155:
1156:
1157:
1158:
1159:
1160:
1161:
1162:
1163:
1164:
1165:
1166:
1167:
1168:
1169:
1170:
1171:
1172:
1173:
1174:
1175:
1176:
1177:
1178:
1179:
1180:
1181:
1182:
1183:
1184:
1185:
1186:
1187:
1188:
1189:
1190:
1191:
1192:
1193:
1194:
1195:
1196:
1197:
1198:
1199:
1200:
1201:
1202:
1203:
1204:
1205:
1206:
1207:
1208:
1209:
1210:
1211:
1212:
1213:
1214:
1215:
1216:
1217:
1218:
1219:
1220:
1221:
1222:
1223:
1224:
1225:
1226:
1227:
1228:
1229:
1230:
1231:
1232:
1233:
1234:
1235:
1236:
1237:
1238:
1239:
1240:
1241:
1242:
1243:
1244:
1245:
1246:
1247:
1248:
1249:
1250:
1251:
1252:
1253:
1254:
1255:
1256:
1257:
1258:
1259:
1260:
1261:
1262:
1263:
1264:
1265:
1266:
1267:
1268:
1269:
1270:
1271:
1272:
1273:
1274:
1275:
1276:
1277:
1278:
1279:
1280:
1281:
1282:
1283:
1284:
1285:
1286:
1287:
1288:
1289:
1290:
1291:
1292:
1293:
1294:
1295:
1296:
1297:
1298:
1299:
1300:
1301:
1302:
1303:
1304:
1305:
1306:
1307:
1308:
1309:
1310:
1311:
1312:
1313:
1314:
1315:
1316:
1317:
1318:
1319:
1320:
1321:
1322:
1323:
1324:
1325:
1326:
1327:
1328:
1329:
1330:
1331:
1332:
1333:
1334:
1335:
1336:
1337:
1338:
1339:
1340:
1341:
1342:
1343:
1344:
1345:
1346:
1347:
1348:
1349:
1350:
1351:
1352:
1353:
1354:
1355:
1356:
1357:
1358:
1359:
1360:
1361:
1362:
1363:
1364:
1365:
1366:
1367:
1368:
1369:
1370:
1371:
1372:
1373:
1374:
1375:
1376:
1377:
1378:
1379:
1380:
1381:
1382:
1383:
1384:
1385:
1386:
1387:
1388:
1389:
1390:
1391:
1392:
1393:
1394:
1395:
1396:
1397:
1398:
1399:
1400:
1401:
1402:
1403:
1404:
1405:
1406:
1407:
1408:
1409:
1410:
1411:
1412:
1413:
1414:
1415:
1416:
1417:
1418:
1419:
1420:
1421:
1422:
1423:
1424:
1425:
1426:
1427:
1428:
1429:
1430:
1431:
1432:
1433:
1434:
1435:
1436:
1437:
1438:
1439:
1440:
1441:
1442:
1443:
1444:
1445:
1446:
1447:
1448:
1449:
1450:
1451:
1452:
1453:
1454:
1455:
1456:
1457:
1458:
1459:
1460:
1461:
1462:
1463:
1464:
1465:
1466:
1467:
1468:
1469:
1470:
1471:
1472:
1473:
1474:
1475:
1476:
1477:
1478:
1479:
1480:
1481:
1482:
1483:
1484:
1485:
1486:
1487:
1488:
1489:
1490:
1491:
1492:
1493:
1494:
1495:
1496:
1497:
1498:
1499:
1500:
1501:
1502:
1503:
1504:
1505:
1506:
1507:
1508:
1509:
1510:
1511:
1512:
1513:
1514:
1515:
1516:
1517:
1518:
1519:
1520:
1521:
1522:
1523:
1524:
1525:
1526:
1527:
1528:
1529:
1530:
1531:
1532:
1533:
1534:
<?php
//error_reporting(E_ALL);
/*~ phpmailer-fe.php
.---------------------------------------------------------------------------.
|  Software: PHPMailer-FE (Form mailer Edition)                             |
|   Version: 3.1                                                            |
|   Contact: codeworxtech@users.sourceforge.net                             |
|      Info: http://phpmailer.codeworxtech.com                              |
| ------------------------------------------------------------------------- |
|    Author: Andy Prevost andy.prevost@worxteam.com (admin)                 |
| Copyright (c) 2002-2008, Andy Prevost. All Rights Reserved.               |
| ------------------------------------------------------------------------- |
|   License: Distributed under the Lesser General Public License (LGPL)     |
|            http://www.gnu.org/copyleft/lesser.html                        |
| This program is distributed in the hope that it will be useful - WITHOUT  |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     |
| FITNESS FOR A PARTICULAR PURPOSE.                                         |
| ------------------------------------------------------------------------- |
| We offer a number of paid services:                                       |
| - Web Hosting on highly optimized fast and secure servers                 |
| - Technology Consulting                                                   |
| - Oursourcing (highly qualified programmers and graphic designers)        |
'---------------------------------------------------------------------------'
Last updated: August 10 2008 21:08 EST
 
/**
 * PHPMailer-FE - PHP Form To Email
 * @package PHPMailer-FE
 * @author Andy Prevost
 * @copyright 2008 Andy Prevost
 *
 * PHPMailer-FE is an HTML form to e-mail gateway that parses the results of
 * any form and sends them to the specified recipient(s). This script has many
 * formatting and operational options, most of which can be specified in each
 * form. You don't need programming knowledge or multiple scripts for
 * multiple forms. PHPMailer-FE also has security features to prevent users
 * from including URLs in fields containing "nourl" or "comments" in the field name.
 * PHPMailer-FE was written to be compatible with Formmail.pl and Formmail.php
 *
 */
 
/* ****************************************************************
 * Setting up PHPMailer-FE - REQUIRED FOR OPTIONAL SETTINGS
 * ***************************************************************/
 
/**
 * Defined Term, PHPMailer-FE Version number (for debugging mostly)
 * @var static string
 *
 * NOTE: Required here, do not change
 *
 */
define("VERSION", "3.1");
 
/**
 * Defined Term, PHPMailer-FE base path (works with Linux and Windows)
 * @var static string
 *
 * NOTE: Required here, do not change
 *
 */
define("FEPATH", getcwd() . substr($_SERVER['PHP_SELF'],0,1) );
 
/**
 * Ban List file name, fully qualified including directory
 * ie. /home/public_html/account/banlog.php
 * - can only be set in the script
 * @var string
 * NOTE: Required here, change only if filename altered
 */
$fileBanlist = FEPATH . 'banlog.php';
 
/**
 * Use Ban List, protect from URLs in fields containing "nourl" or "comments" in name
 * - can only be set in the script
 * @var boolean
 * NOTE: Required here, change as needed
 */
$useBanlist  = true;
if ( is_writable($fileBanlist) ) {
  $useBanlist  = true;
}
 
/**
 * Redirect URL if banned or hacked or failed Worx Turing test
 * - can only be set in the script
 * @var boolean
 */
$redirectOnBan  = "http://" . $_SERVER['HTTP_HOST'];
 
/**
 * REQUIRED: value determines if the javascript window close will be
 * used when the default messages display after processing the form
 * - useful for POPUP style forms
 * default is "false"
 * @var boolean
 * NOTE: Required here, change as needed
 */
$useWindowClose = false;
 
/**
 * 1. Convert all $_POST variables to a regular variable
 * 2. Checks all $_POSTs for URL type input
 *    - will exit and not proceed if URL type input is found
 * NOTE1: REQUIRED, PLEASE DO NOT CHANGE ... NEEDED TO SET VARIABLES PROPERLY
 * NOTE2: Processing here because many of the settings can be altered by the form
 * NOTE3: Processing here because External Config will also alter settings (after the form)
 */
foreach ($_POST as $key => $value) {
 
  $key    = strtolower($key);
  $value  = str_replace("\n","<br />",$value);
  $hacked = false;
  if (!is_array($value)) {
    $$key = '';
    $$key = trim(utf8_urldecode($value));
  }
  if ($useBanlist && is_writable($fileBanlist)) {
    if ( !stristr($key, 'url') ) { // will only search if 'url' not found in $key
      $hacked = FALSE;
      $hacked = checkBannedInput($key,$value,$fileBanlist);
    }
  }
  if ( $hacked === TRUE ) {
    echo "Comments were not sent ...<br />";
    echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"10; URL=" . $redirectOnBan . "\">";
    if ($useWindowClose) {
      echo '<script language="javascript" type="text/javascript">' . "\n";
      echo 'setTimeout("self.close()", 5000 )' . "\n";
      echo '</script>' . "\n";
    }
    exit();
  }
}
 
/**
 * include external configuration files
 */
$loadDefault = FEPATH . 'default.config.php';
if (file_exists($loadDefault)) {
  include_once( $loadDefault );
  foreach ($_POST as $key => $value) {
    $key   = strtolower($key);
    $value = str_replace("\n","<br />",$value);
    $$key  = trim(utf8_urldecode($value));
  }
}
if ( getenv('HTTP_REFERER') != '' || $_POST['referer'] != '' ) {
  if ( getenv('HTTP_REFERER') != '' ) {
    $path_parts = pathinfo(getenv('HTTP_REFERER'));
  } else {
    $path_parts = pathinfo(trim($_POST["referer"]));
  }
  $filearr = split("\.",$path_parts["basename"]);
  if (count($filearr) > 1) {
    $loadFile = '';
    for ($i=0;$i<count($filearr)-1;$i++) {
      $loadFile .= $filearr[$i] . ".";
    }
    $loadFile .= 'config.php';
  }
  $loadFile = FEPATH . $loadFile;
  if ( file_exists($loadFile) ) {
    include_once( $loadFile );
  }
  foreach ($_POST as $key => $value) {
    $key   = strtolower($key);
    $value = str_replace("\n","<br />",$value);
    $$key  = trim(utf8_urldecode($value));
  }
}
$loadDefault = '';
$loadFile    = '';
 
/**
 * Set if you wish the email to be from this email address instead of the
 * email address of the sender
 * - can only be set in the script
 * @var string
 */
$fixedFromEmail = 'welcome@advantagevalues.com'; //'webmaster@thisdomain.com';
$fixedFromName  = 'Tom Piccirillo'; //'Webmaster'
 
/* ****************************************************************
 * Optional Form Configuration that can be set in script or in form
 * Note: can also be set in External Configuration file
 * ***************************************************************/
 
/**
 * 'Swap' out hack attempts
 * - can only be set in the script
 * @var array
 */
if ( !isset($email_bad_array) ) {
  $email_bad_array = "\r|\n|to:|cc:|bcc:";
}
 
/**
 * Email Address to send the form contents "To"
 * - can be set in the script or in the form as a form variable
 * - for security, use this instead of using the form
 * @var string
 */
if ( !isset($recipient) ) {
  $recipient = 'tpiccirillo@earthlink.net';
} else {
  $recipient = eregi_replace($email_bad_array,'',$recipient);
  $recipient = str_replace(" ", "", $recipient);
}
 
/**
 * Email Address to "Cc" the form contents
 * separate multiple email addresses by comma
 * - for security, use this instead of using the form
 * ie: johndoe@yourdomain.com,janedoe@yourdomain.com
 * - can be set in the script or in the form as a form variable
 * @var string
 */
if ( !isset($cc) ) {
  $cc = "mattkramb@gmail.com";
} else {
  $cc = eregi_replace($email_bad_array,'',$cc);
  $cc = str_replace(";", ",", $cc);
  $cc = str_replace(" ", "", $cc);
}
 
/**
 * Email Address to "Bcc" the form contents
 * separate multiple email addresses by comma
 * - for security, use this instead of using the form
 * ie: johndoe@yourdomain.com,janedoe@yourdomain.com
 * - can be set in the script or in the form as a form variable
 * @var string
 */
if ( !isset($bcc) ) {
  $bcc = '';
} else {
  $bcc = eregi_replace($email_bad_array,'',$bcc);
  $bcc = str_replace(";", ",", $bcc);
  $bcc = str_replace(" ", "", $bcc);
}
 
/**
 * Subject for email that is sent to "recipient"
 * - can be set in the script or in the form as a form variable
 * @var string
 */
if ( !isset($subject) ) {
  $subject = 'WELECOME' . ' from: ' . $_SERVER['HTTP_HOST'];
} else {
  $subject = eregi_replace($email_bad_array,'',$subject);
  $subject = stripslashes($subject);
}
 
/**
 * Option to include System Environment Variables with form content
 * - can be set in the script or in the form as a form variable
 * Note: comment out to disable
 * @var array
 */
if ( !isset($env_report) ) {
  $env_report = array ();
  //$env_report = array ('REMOTE_HOST','REMOTE_USER','REMOTE_ADDR','HTTP_USER_AGENT','HTTP_REFERER');
}
 
/**
 * Defines the file extensions of files that can be emailed as attachments to you
 * - can only be set in the script
 * @var array
 */
if ( !isset($allowedFileTypes) ) {
  $allowedFileTypes = "doc|xls|pdf|jpg|jpeg|png|gif|zip|rar|gz";
}
 
/**
 * Redirect URL on any failures
 * does not apply to banned or hacked or failed Worx Turing test
 * @var boolean
 * NOTE: will 'build' a page if this variable is missing
 */
if ( !isset($redirectOnFail) ) {
  $redirectOnFail  = '';
}
 
/**
 * Email template to send to form submitter on successful post
 * @var boolean
 * NOTE: email in html format only in same folder as PHPMailer-FE
 * NOTE: if variable is empty, no reply email will be sent
 */
if ( !isset($replyEmailOnSuccess) ) {
  $replyEmailOnSuccess  = 'emailtemp.html';
}
 
/**
 * Email template to send to form submitter on failed post
 * does not apply to banned or hacked or failed Worx Turing test
 * @var boolean
 * NOTE: email in html format only in same folder as PHPMailer-FE
 * NOTE: if variable is empty, no reply email will be sent
 */
if ( !isset($replyEmailOnFail) ) {
  $replyEmailOnFail  = '';
}
 
/**
 * Use as Auto-Responder and do not send emails to Recipient
 * default is false
 * @var boolean
 * NOTE: if set to false, this will behave normally and send emails
 * to recipient as expected. If set to true, this will only send
 * emails to submitter (none to recipient - unless you add
 * recipient as bcc or cc - a perfect auto-responder strategy).
 */
if ( !isset($useAsAutoResponder) ) {
  $useAsAutoResponder = true;
}
 
/* ****************************************************************
 * Setting up PHPMailer-FE (can only be set in script)
 * ***************************************************************/
 
/**
 * Value determines if the script will use the Worx Turing test
 * default is "false"
 * @var boolean
 */
$useWorxTuring = false;
 
/**
 * User PHPMailer as mail transport class
 * - can only be set in the script
 * change only if not in the same directory as phpmailer-fe.php
 * @var string
 */
$PHPMailerLocation = FEPATH . "class.phpmailer.php";
 
/**
 * REQUIRED: IP or domain name of domains allowed to use your script
 * defaults to $_SERVER['HTTP_HOST']
 * - can only be set in the script
 * @var array
 */
//$referers   = array ($_SERVER['HTTP_HOST']);
$referers   = array ($_SERVER['HTTP_HOST']);
 
/**
 * Use Environment Variables Report, that is email the details of the sender's browser
 * - can only be set in the script
 * @var boolean
 */
$useEnvRpt  = false;
 
/**
 * Email addresses that are banned from using the script
 * - can only be set in the script
 * @var array
 */
$bannedEmails    = ''; //array ('*@anydomain.com', '*@otherdomain.com');
 
/**
 * Defined Term, Separator (field / value separator)
 * @var static string
 */
if ( !isset($separator)  ) {
  $separator = ": ";
}
define("SEPARATOR", $separator);
 
/**
 * Defined Term, Newline (end of line)
 * @var static string
 */
if ( !isset($newline)  ) {
  $newline = "\n";
}
define("NEWLINE", $newline);
 
/**
 * Defined Left Command delimiter
 * @var static string
 */
define("DELIMITERLEFT", "{");
 
/**
 * Defined Left Command delimiter
 * @var static string
 */
define("DELIMITERRIGHT", "}");
 
/* ------------ END SETTINGS - START PROCESSING -------------------- */
 
// do the Worx Turing test
if ( $useWorxTuring && isset($_POST["WorxTuringTest"]) ) {
  session_start();
  if (strtoupper($_POST["WorxTuringTest"]) != $_SESSION['WorxTuringTest']) {
    echo "Security test failed ...<br />";
    echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"4; URL=" . $redirectOnBan . "\">";
    if ($useWindowClose) {
      echo '<script language="javascript" type="text/javascript">' . "\n";
      echo 'setTimeout("self.close()", 5000 )' . "\n";
      echo '</script>' . "\n";
    }
    exit();
  }
  session_destroy();
}
 
//check connect through proxy or not
$proxydescription = "";
$remoteaddr       = $_SERVER['REMOTE_ADDR'];
$http_via         = getenv('HTTP_VIA');
$http_forwarded   = getenv('HTTP_X_FORWARDED_FOR');
$remoteport       = getenv('REMOTE_PORT');
//no proxy case or highly anonymous case
if($http_via == NULL && $http_forwarded == NULL) {
  $remote = $remoteaddr;
  $proxyip = $remoteaddr;
  $hostname = gethostbyaddr($remoteaddr);
  $proxyhostname = gethostbyaddr($remoteaddr);
  $proxydescription = "No Proxy or a High Anonymity Proxy";
} else if(strcmp($remote, $http_via) == 0 && strcmp($http_forwarded, $http_via) != 0) {
  //Transparent Proxy or Anonymous Proxy case
  $remote = $http_forwarded;
  $proxyip = $remoteaddr;
  $hostname = gethostbyaddr($http_forwarded);
  $proxyhostname = gethostbyaddr($remoteaddr);
  $proxydescription = "Transparent Proxy or Anonymous Proxy";
} else {
  //Highly Anonymous Proxy case
  $remote = $remoteaddr;
  $proxyip = $remoteaddr;
  $hostname = gethostbyaddr($remoteaddr);
  $proxyhostname = gethostbyaddr($remoteaddr);
  $proxydescription = "Highly Anonymous Proxy";
}
 
ob_start();
 
$imgProcessing = '';
if ( file_exists('processing.gif') ) {
  $imgProcessing = '<img border="0" src="processing.gif" width="200" height="84"><br />';
}
$_POST['IP']   = $proxyip;
$_POST['HOST'] = $proxyhostname;
if ( $redirect == '' && $redirectOnFail == '' ) {
 echo $imgProcessing . "IP: " . $_POST['IP'] . " at " . $_POST['HOST'] . "<hr /><br />";
}
 
/* uncomment to hard code banned IP addresses
if ($_POST['IP']   == "85.255.120.58" ||
    $_POST['IP']   == "216.255.183.194" ||
    substr_count($_POST['HOST'], "custblock.intercage.com") > 0 ||
    substr_count($_POST['HOST'], "inhoster.com") > 0
   ) {
  echo "Submissions from your IP address are not accepted<br />";
  echo "<meta http-equiv=\"Refresh\" content=\"3; URL=http://www.google.com/\">";
  if ($useWindowClose) {
    echo '<script language="javascript" type="text/javascript">' . "\n";
    echo 'setTimeout("self.close()", 5000 )' . "\n";
    echo '</script>' . "\n";
  }
  exit();
}
*/
 
/**
 * Checks that form is from an approved "referer"
 * - will exit and not proceed if referer is NOT found
 * @var array string
 */
if ($referers) {
  check_referer($referers);
}
 
/**
 * Checks if "email" included in form is on banlist
 * - will exit and not proceed if email is on banlist
 */
if ($bannedEmails) {
  check_banlist($bannedEmails, $email);
}
 
/**
 * Sort the $_POST variables
 */
if ( isset($sort) && $sort == "alphabetic") {
  uksort($_POST, "strnatcasecmp");
} elseif ( (isset($sort) && isset($list)) && (ereg('^order:.*,.*', $sort)) && ($list = explode(',', ereg_replace('^order:', '', $sort)))) {
  $sort = $list;
}
 
/**
 * Checks if the browser's IP address or Remote Host is on ban list
 * - will exit and not proceed if either is found in ban list
 */
if ($useBanlist && is_writable($fileBanlist)) {
  $banned = checkBanlist($fileBanlist);
  if ($banned) {
    echo "Submissions not accepted from  ..." . $_POST['IP']  . " / " . $_POST['HOST'] . "<br />";
    echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"10; URL=" . $redirectOnBan . "\">";
    if ($useWindowClose) {
      echo '<script language="javascript" type="text/javascript">' . "\n";
      echo 'setTimeout("self.close()", 5000 )' . "\n";
      echo '</script>' . "\n";
    }
    exit();
  }
}
 
/**
 * Determines if $_POST fields that are blank are sent in email
 * - Default is false (blanks are not included)
 * - set in he form as a form variable
 * @var boolean
 */
if (!isset($print_blank_fields)) {
  $print_blank_fields = false;
  }
 
/**
 * Checks if "recipient" is valid email address
 * - will generate error if email is not valid
 */
$recipient_in = split(',',$recipient);
for ($i=0;$i<count($recipient_in);$i++) {
  $recipient_to_test = trim($recipient_in[$i]);
  if ( _validateEmail($recipient_to_test) === FALSE ) {
    print_error("<li>your <b>email address</b> is invalid</li>");
  }
}
 
/**
 * Used to maintain compatibility with Formmail.pl and formmail.php
 */
if ( isset($required) ) {
  if ( isset($require) ) {
    $require .= $required;
  } else {
    $require = $required;
  }
}
 
/**
 * Process required fields
 */
if ($require) {
  // split at commas
  $require = ereg_replace( " +", "", $require);
  $required = split(",",$require);
  for ($i=0;$i<count($required);$i++) {
    $string = trim(strtolower($required[$i]));
    // check if exists
    if( !(${$string}) ) {
      // if the missing_fields_redirect option is on: redirect them
      if ($missing_fields_redirect) {
        echo "<meta http-equiv=\"refresh\" content=\"0;url=" . $missing_fields_redirect . '">';
        exit();
      }
      // $require;
      $missing_field_list .= "<li><b>Missing: " . $required[$i] . "</b></li>\n";
    }
  }
  // send error to our error function
  if ( isset($missing_field_list) ) {
    print_error($missing_field_list,"missing");
  }
}
 
/**
 * Validate email fields
 */
if ( isset($EMAIL) || isset($email) ) {
  $email = trim($email);
  if ( isset($EMAIL) ) {
    $email = trim($EMAIL);
  }
  if ( _validateEmail($email) === FALSE ) {
    print_error("<li>your <b>email address</b> is invalid</li>");
  }
}
if (!$email) {
  $email = $recipient;
}
 
/**
 * Validate Zipcode or Postal Code
 */
if ( isset($ZIP_CODE) || isset($zip_code) ) {
  $zip_code = trim($zip_code);
  if ( isset($ZIP_CODE) ) {
    $zip_code = trim($ZIP_CODE);
  }
  if (!ereg("(^[0-9]{5})-([0-9]{4}$)", trim($zip_code)) && (!ereg("^[a-zA-Z][0-9][a-zA-Z][[:space:]][0-9][a-zA-Z][0-9]$", trim($zip_code))) && (!ereg("(^[0-9]{5})", trim($zip_code)))) {
    print_error("<li>your <b>zip/postal code</b> is invalid</li>");
  }
}
 
/**
 * Validate Phone Number
 */
if ( isset($PHONE_NO) || isset($phone_no) ) {
  $phone_no = trim($phone_no);
  if ( isset($PHONE_NO) ) {
    $phone_no = trim($PHONE_NO);
  }
  if (!ereg("(^(.*)[0-9]{3})(.*)([0-9]{3})(.*)([0-9]{4}$)", $phone_no)) {
    print_error("<li>your <b>phone number</b> is invalid</li>");
  }
}
 
/**
 * Validate Fax Number
 */
if ( isset($FAX_NO) || isset($fax_no) ) {
  $fax_no = trim($fax_no);
  if ( isset($FAX_NO) ) {
    $fax_no = trim($FAX_NO);
  }
  if (!ereg("(^(.*)[0-9]{3})(.*)([0-9]{3})(.*)([0-9]{4}$)", $fax_no)) {
    print_error("<li>your <b>fax number</b> is invalid</li>");
  }
}
 
/**
 * Prepare (parse) content
 */
$content      = array();
$contentArray = array();
if ( isset($sort) ) {
  $contentArray = parse_form($_POST, $sort);
} else {
  $contentArray = parse_form($_POST, '');
}
 
/**
 * Upload attachment if there is one (intended for recipient)
 */
if ($_FILES) {
  // code for file uploaded by form
  $attachment_name = $_FILES["attachment"]["name"];
  $attachment_size = $_FILES["attachment"]["size"];
  $attachment_temp = $_FILES["attachment"]["tmp_name"];
  $attachment_type = $_FILES["attachment"]["type"];
  $attachment_ext  = explode('.', $attachment_name);
  $attachment_ext  = $attachment_ext[count($attachment_ext)-1];
  if ( trim($attachment_temp) != '' && stristr($allowedFileTypes, $attachment_ext) === true ) {
    if ($attachment_name) {
      if ($attachment_size > 0) {
        if (!$attachment_type) {
          $attachment_type =  "application/unknown";
        }
        $content    .= "Attached File: ".$attachment_name."\n";
        $fp = fopen($attachment_temp,  "r");
        $attachment_chunk = fread($fp, filesize($attachment_temp));
        $attachment_chunk = base64_encode($attachment_chunk);
        $attachment_chunk = chunk_split($attachment_chunk);
      }
    }
  }
}
 
/**
 * Local attachment if there is one (intended for submitter)
 */
if ( $_POST['attach_local_name'] && $_POST['attach_local_type'] ) {
  // code for file on local server (and passed by config file)
  $local_name = basename($_POST['attach_local_name']);
  $local_type = $_POST['attach_local_type']; // The mime type of the file. An example would be "image/gif".
  $local_size = @filesize($_POST['attach_local_name']);
  $local_temp = $_POST['attach_local_name'];
  $local_ext  = explode('.', $local_name);
  $local_ext  = $local_ext[count($local_ext)-1];
  $content    .= "Attached File: ".$local_name."\n";
  $fp = fopen($local_temp,  "r");
  $local_chunk = fread($fp, filesize($local_temp));
  $local_chunk = base64_encode($local_chunk);
  $local_chunk = chunk_split($local_chunk);
  $local_local = true;
}
 
/**
 * If the "env_report" option is true, get environment variables
 */
if ($env_report && $useEnvRpt) {
  $env_reports = $env_report;
  $content .= "\n------ environmental variables ------\n";
 
  $proxy="";
  $envIP = "";
  if (isSet($_SERVER["HTTP_X_FORWARDED_FOR"])) {
    $envIP = $_SERVER["HTTP_X_FORWARDED_FOR"];
    $proxy  = $_SERVER["REMOTE_ADDR"];
  } elseif (isSet($_SERVER["HTTP_CLIENT_IP"])) {
    $envIP = $_SERVER["HTTP_CLIENT_IP"];
  } else {
    $envIP = $_SERVER["REMOTE_ADDR"];
  }
  if (strstr($envIP, ',')) {
    $ips = explode(',', $envIP);
    $envIP = $ips[0];
  }
  $RemoteInfo["ip"]    = $envIP;
  $RemoteInfo["host"]  = @GetHostByAddr($envIP);
  $RemoteInfo["proxy"] = $proxy;
 
  for ($i=0;$i<count($env_reports);$i++) {
    $string = trim($env_reports[$i]);
    if ($env_reports[$i] == "REMOTE_HOST") {
      $content .= str_pad("REMOTE HOST", 15, " ", STR_PAD_LEFT) . ": " . $RemoteInfo["host"] ."\n";
    }
    if ($env_reports[$i] == "REMOTE_ADDR") {
      $content .= str_pad("REMOTE ADDR", 15, " ", STR_PAD_LEFT) . ": " .  $RemoteInfo["ip"] . "\n";
      $content .= str_pad("PROXY HOST", 15, " ", STR_PAD_LEFT) . ": " .  $RemoteInfo["proxy"] . "\n";
    }
    if ($env_reports[$i] == "REMOTE_USER") {
      $content .= str_pad("REMOTE USER", 15, " ", STR_PAD_LEFT) . ": " . $_SERVER['REMOTE_USER'] ."\n";
    }
    if ($env_reports[$i] == "HTTP_USER_AGENT") {
      $content .= str_pad("BROWSER", 15, " ", STR_PAD_LEFT) . ": " . $_SERVER['HTTP_USER_AGENT'] . "\n";
    }
    if ($env_reports[$i] == "HTTP_REFERER") {
      $content .= str_pad("REFERER", 15, " ", STR_PAD_LEFT) . ": " . $_SERVER['HTTP_REFERER'] . "\n";
    }
  }
}
 
/**
 * Send the $_POST variables
 */
if ( !isset($realname) && isset($name) ) {
  $realname = $name;
}
if ( isset($realname) && isset($email_bad_array) ) {
  $realname = eregi_replace($email_bad_array,'',$realname);
}
 
$content         = array();
$content["text"] = stripslashes($contentArray["text"]);
$content["html"] = stripslashes($contentArray["html"]);
 
// send email to the recipient
if ( !isset($realname) ) {
  $realname = '';
}
if ( $useAsAutoResponder === false ) { // if $useAsAutoResponder is true, an email to $recipient is not needed
  mail_it($content, $subject, $email, $realname, $recipient, true);
}
 
// if you are using the "copy me" feature, a duplicate of the email will be send to the sender
if ( isset($send_email_copy) && isset($email) ) {
  mail_it($content, 'Copy: ' . $subject, $email, $realname, $email, true);
}
 
// code to send reply to sender on success of form submission
/* note your email HTML form has to include the variables
 * $recipient (this will be used as the TO: address) (or put in external config file)
 * $fromemail (this will be used as the FROM: address - should be your email address)
 * $fromname  (this will be used as the FROM: name    - should be your name)
 * all other aspects of the reply email have to be set by you ... you can use
 * variables from your form in the format $field.
 * in your form, use the code format
 * <php echo $recipient; ?>
 */
$replyEmailOnSuccess = $_POST['replyEmailOnSuccess'];
if ( $replyEmailOnSuccess != '' ) {
  $_POST['thanksMessage'] = "We will be in touch with you shortly!";
  $msgSend = getTplFile($replyEmailOnSuccess);
  $replyEmail = array();
  $replyEmail["text"] = stripslashes(html_entity_decode(strip_tags($msgSend)));
  $replyEmail["html"] = stripslashes($msgSend);
  $ccOrg  = $cc; $cc = NULL;
  $bccOrg = $bcc; $bcc = NULL;
  mail_it($replyEmail, $subject, $recipient, '', $email, false);
  $cc  = $ccOrg;
  $bcc = $bccOrg;
}
// END code to send reply to sender on success of form submission
 
/**
 * Process Plugin
 */
$loadDefault = FEPATH . 'default.plugin.php';
if (file_exists($loadDefault)) {
  include_once( $loadDefault );
}
$loadFile = '';
if ( getenv('HTTP_REFERER') != '' || $_POST['referer'] != '' ) {
  if ( getenv('HTTP_REFERER') != '' ) {
    $path_parts = pathinfo(getenv('HTTP_REFERER'));
  } else {
    $path_parts = pathinfo(trim($_POST["referer"]));
  }
  $filearr = split("\.",$path_parts["basename"]);
  if (count($filearr) > 1) {
    $loadFile = '';
    for ($i=0;$i<count($filearr)-1;$i++) {
      $loadFile .= $filearr[$i] . ".";
    }
    $loadFile .= 'plugin.php';
  }
  $loadFile = FEPATH . $loadFile;
  if ( file_exists($loadFile) ) {
    include_once( $loadFile );
  }
}
$loadDefault = '';
$loadFile    = '';
 
/**
 * Redirect (after sent) if redirect variable is set
 */
if ($redirect) {
  $msgDisplay = getTplFile($redirect);
  echo $msgDisplay;
  exit();
} else {
  echo "Thank you for your submission\n";
  echo "<br /><br />\n";
  if ($return_link_url) {
    echo "<a href=\"" . $return_link_url . "\">";
    if ($return_link_title) {
      echo $return_link_title;
    } else {
      echo $return_link_url;
    }
    echo "</a>";
    echo "<br /><br />\n";
  }
  echo "<small>Powered by <a href=\"http://phpmailer.codeworxtech.com/\">PHPMailer-FE.php " . VERSION . "!</a></small>\n\n";
  echo '<script language="javascript" type="text/javascript">' . "\n";
  if ($useWindowClose) {
    echo 'setTimeout("self.close()", 5000 )' . "\n";
  }
  echo '</script>' . "\n";
  exit();
}
 
/* ****************** FUNCTIONS ******************** */
 
/**
 * Error processing function
 * @param string $reason
 * @param int $type
 * @return void
 */
function print_error($reason,$type = 0) {
 
  $redirectOnFail   = $_POST['redirectOnFail'];
  $replyEmailOnFail = $_POST['replyEmailOnFail'];
 
  if ($redirectOnFail == '') {
    build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet);
    // for missing required data
    if ($type == "missing") {
      if ($missing_field_redirect) {
        header("Location: $missing_field_redirect?error=$reason");
        exit();
      } else {
        $failMessage  = 'The form was not submitted for the following reasons:<p>';
        $failMessage .= '<ul>' . $reason . "\n" . '</ul>';
        echo $failMessage;
        echo 'Please use your browser&#39;s back button to return to the form and try again.';
      }
    } else { // every other error
      $failMessage = 'The form was not submitted because of the following reasons:<p>';
      echo $failMessage;
    }
    echo "<br /><br />\n";
    echo "<small>This form is powered by <a href=\"http://phpmailer.codeworxtech.com/\">PHPMailer-FE.php " . VERSION . "</a></small>\n\n";
    exit();
  } else {
    $reason = str_replace('<li>','',$reason);
    $reason = str_replace('</li>','<br />',$reason);
    $failMessage = '';
    if ($type == "missing") {
      if ($missing_field_redirect) {
        $failMessage .= $reason;
      } else {
        $failMessage .= 'The form was not submitted for the following reasons:<br /><br />';
        $failMessage .= $reason;
      }
    } else { // every other error
      $failMessage .= ' The form was not submitted because of the following reasons:<br /><br />';
      $failMessage .= $reason;
    }
    $failMessage .= "<br />";
    $_POST['failMessage'] = $failMessage;
    $msgDisplay = getTplFile($redirectOnFail);
    echo $msgDisplay;
    exit();
  }
  // code to send reply to sender on failure of form submission
  /* note your email HTML form has to include the variables
   * $recipient (this will be used as the TO: address)
   * $fromemail (this will be used as the FROM: address - should be your email address)
   * $fromname  (this will be used as the FROM: name    - should be your name)
   * all other aspects of the reply email have to be set by you ... you can use
   * variables from your form in the format $field.
   * in your form, use the code format
   * <php echo $recipient; ?>
   */
  if ( $replyEmailOnFail != '' ) {
    $msgSend = getTplFile($replyEmailOnFail);
    $replyEmail = array();
    $replyEmail["text"] = stripslashes(html_entity_decode(strip_tags($msgSend)));
    $replyEmail["html"] = stripslashes($msgSend);
    $ccOrg  = $cc; $cc = NULL;
    $bccOrg = $bcc; $bcc = NULL;
    mail_it($replyEmail, $subject, $recipient, '', $email, false);
    $cc  = $ccOrg;
    $bcc = $bccOrg;
  }
  // END code to send reply to sender on failure of form submission
}
 
/**
 * Function to check the banlist
 * calls error function if banned email is found
 * @param array $bannedEmails
 * @param string $email
 * @return void
 */
function check_banlist($bannedEmails, $email) {
  if (count($bannedEmails)) {
    $allow = true;
    foreach($bannedEmails as $banned) {
      $temp = explode("@", $banned);
      if ($temp[0] == "*") {
        $temp2 = explode("@", $email);
        if (trim(strtolower($temp2[1])) == trim(strtolower($temp[1]))) {
          $allow = false;
        }
      } else {
        if (trim(strtolower($email)) == trim(strtolower($banned))) {
          $allow = false;
        }
      }
    }
  }
  if (!$allow) {
    print_error("You are using a <b>banned email address.</b>");
  }
}
 
/**
 * Function to check referer (IP or Domain of submitted $_POST)
 * calls error function if referer is NOT found
 * @param array $referers
 * @return boolean
 */
function check_referer($referers) {
  if (count($referers)) {
    $found = false;
 
    $temp = explode("/",getenv("HTTP_REFERER"));
    $referer = $temp[2];
 
    if ($referer=="") {
      $referer = $_SERVER['HTTP_REFERER'];
      list($remove,$stuff)=split('//',$referer,2);
      list($home,$stuff)=split('/',$stuff,2);
      $referer = $home;
    }
 
    for ($x=0; $x < count($referers); $x++) {
       if (eregi ($referers[$x], $referer)) {
         $found = true;
       }
    }
    if ($referer == "") {
      $found = false;
    }
    if (!$found) {
      print_error("You are coming from an <b>unauthorized domain. ($referer)</b>");
      error_log("[PHPMailer-FE.php] Illegal Referer. (".getenv("HTTP_REFERER").")", 0);
    }
    return $found;
  } else {
    return true;
  }
}
 
/**
 * Function to: sort, exclude keys, and format content string
 * @param array $array
 * @param array $sort
 * @return string
 */
function parse_form($array, $sort = "") {
  // reserved keyword array
  $reserved_keys[] = "alink_color";
  $reserved_keys[] = "allowedFileTypes";
  $reserved_keys[] = "cc";
  $reserved_keys[] = "cs_config_country_field";
  $reserved_keys[] = "cs_config_state_field";
  $reserved_keys[] = "cs_config_country_default";
  $reserved_keys[] = "cs_config_state_default";
  $reserved_keys[] = "countryDefault";
  $reserved_keys[] = "stateDefault";
  $reserved_keys[] = "bcc";
  $reserved_keys[] = "bgcolor";
  $reserved_keys[] = "form_notice";
  $reserved_keys[] = "Helo";
  $reserved_keys[] = "Host";
  $reserved_keys[] = "HOST";
  $reserved_keys[] = "IP";
  $reserved_keys[] = "link_color";
  $reserved_keys[] = "Mailer";
  $reserved_keys[] = "MAX_FILE_SIZE";
  $reserved_keys[] = "missing_fields_redirect";
  $reserved_keys[] = "path_to_file";
  $reserved_keys[] = "Port";
  $reserved_keys[] = "print_blank_fields";
  $reserved_keys[] = "recipient";
  $reserved_keys[] = "redirect";
  $reserved_keys[] = "redirectOnBan";
  $reserved_keys[] = "redirectOnFail";
  $reserved_keys[] = "referer";
  $reserved_keys[] = "replyEmailOnFail";
  $reserved_keys[] = "replyEmailOnSuccess";
  $reserved_keys[] = "require";
  $reserved_keys[] = "required";
  $reserved_keys[] = "reserved_key_words";
  $reserved_keys[] = "reset";
  $reserved_keys[] = "reset_x";
  $reserved_keys[] = "reset_y";
  $reserved_keys[] = "return_link_url";
  $reserved_keys[] = "return_link_title";
  $reserved_keys[] = "send";
  $reserved_keys[] = "SMTPKeepAlive";
  $reserved_keys[] = "sort";
  $reserved_keys[] = "style_sheet";
  $reserved_keys[] = "subject";
  $reserved_keys[] = "submit";
  $reserved_keys[] = "submit_x";
  $reserved_keys[] = "submit_y";
  $reserved_keys[] = "text_color";
  $reserved_keys[] = "Timeout";
  $reserved_keys[] = "title";
  $reserved_keys[] = "useAsAutoResponder";
  $reserved_keys[] = "vlink_color";
  $reserved_keys[] = "WorxTuringTest";
  if ( isset($_POST['reserved_key_words']) ) {
    $reserved_key_words = $_POST['reserved_key_words'];
    $resarray = split(',',$reserved_key_words);
    if ( count($resarray) == 1 ) {
      $reserved_keys[] = $reserved_key_words;
    } else {
      for ($ra=0;$ra < count($resarray);$ra++) {
        $reserved_keys[] = $resarray[$ra];
      }
    }
  }
  $content         = array();
  $content["text"] = '';
  $content["html"] = '';
  if (count($array)) {
    if (is_array($sort)) {
      foreach ($sort as $field) {
        $reserved_violation = 0;
        for ($ri=0; $ri<count($reserved_keys); $ri++) {
          if ($array[$field] == $reserved_keys[$ri]) { $reserved_violation = 1; }
        }
        if ($reserved_violation != 1) {
          if (is_array($array[$field])) {
            for ($z=0;$zcount($array[$field]);$z++) {
              $content["text"] .= $field.SEPARATOR.str_replace("br />","\n",$array[$field][$z]).NEWLINE;
              $content["html"] .= '<tr><td align="right" valign="top" style="border: 1px #E0E0E0 solid;">' . $field . '</td><td valign="top" style="border: 1px #E0E0E0 solid;">' . str_replace("\n","<br>",$array[$field][$z]) . '</td></tr>';
            }
          } else {
            $content["text"] .= $field.SEPARATOR.str_replace("<br />","\n",$array[$field]).NEWLINE;
            $content["html"] .= '<tr><td align="right" valign="top" style="border: 1px #E0E0E0 solid;">' . $field . '</td><td valign="top" style="border: 1px #E0E0E0 solid;">' . str_replace("\n","<br>",$array[$field]) . '</td></tr>';
          }
        }
      }
    }
    foreach ($array as $key => $val) {
      $reserved_violation = 0;
      for ($ri=0; $ri<count($reserved_keys); $ri++) {
        if ($key == $reserved_keys[$ri]) {
          $reserved_violation = 1;
        }
      }
      if ( is_array($sort) ) {
        for ($ri=0; $ricount($sort); $ri++) {
          if ($key == $sort[$ri]) {
            $reserved_violation = 1;
          }
        }
      }
      // prepare content
      if ($reserved_violation != 1) {
        if (is_array($val)) {
          for ($z=0;$zcount($val);$z++) {
            if ( (strlen($val[$z]) > 0) || $print_blank_fields ) {
              $content["text"] .= $key.SEPARATOR.str_replace("<br />","\n",$val[$z]).NEWLINE;
              $content["html"] .= '<tr><td align="right" valign="top" bgcolor="#ffffff" style="border: 1px #E0E0E0 solid;">' . $key . '</td><td valign="top" bgcolor="#ffffff" style="border: 1px #E0E0E0 solid;">' . str_replace("\n","<br>",$val[$z]) . '</td></tr>';
            }
          }
        } else {
          if ( strlen($val) > 0 ) {
            $content["text"] .= $key.SEPARATOR.str_replace("<br />","\n",$val).NEWLINE;
            $content["html"] .= '<tr><td valign="top" align="right" bgcolor="#ffffff" style="border: 1px #E0E0E0 solid;">' . $key . '</td><td valign="top" bgcolor="#ffffff" style="border: 1px #E0E0E0 solid;">' . str_replace("\n","<br>",$val) . '</td></tr>';
          }
        }
      }
    }
  }
 
  /* code to send customized email - note, the customized email file name must be
   * identical to the first part of the form filename, with the extension .tpl
   * example: form is named "form.php"
   * custom email is named "form.tpl"
   */
  $adminEmailTpl = '';
  if ( getenv('HTTP_REFERER') != '' || $_POST['referer'] != '' ) {
    if ( getenv('HTTP_REFERER') != '' ) {
      $path_parts = pathinfo(getenv('HTTP_REFERER'));
    } else {
      $path_parts = pathinfo(trim($_POST["referer"]));
    }
    if ( isset($_POST["admin_tpl"]) ) {
      $adminEmailTpl = $_POST["admin_tpl"];
    } else {
      $filearr = split("\.",$path_parts["basename"]);
      if (count($filearr) > 1) {
        $adminEmailTpl = '';
        for ($i=0;$i<count($filearr)-1;$i++) {
          $adminEmailTpl .= $filearr[$i] . ".";
        }
        $adminEmailTpl .= 'tpl';
      }
      $adminEmailTpl = FEPATH . $adminEmailTpl;
    }
  }
  if (file_exists($adminEmailTpl)) {
    $adminEmailHTML = getContents('', $adminEmailTpl);
    $content["text"]    = stripslashes(html_entity_decode(strip_tags($adminEmailHTML)));
    $content["html"]    = stripslashes($adminEmailHTML);
  } else {
    $content["html"]  = '<table border="0" cellpadding="2" cellspacing="0" style="border: 1px #E0E0E0 solid;"><tr><th bgcolor="#ffffd2" style="border: 1px #E0E0E0 solid;">Form Field</td><th bgcolor="#ffffd2" style="border: 1px #E0E0E0 solid;">User Input</td></tr>'.$content["html"].'/table>';
  }
  // END code to send customized email
  return $content;
}
 
/**
 * Function to mail the content
 * @param string $content
 * @param string $subject
 * @param string $email           (from email)
 * @param string $realname        (from name)
 * @param string/array $recipient (to)
 * @return void
 */
function mail_it($content, $subject, $email, $realname, $recipient, $inbound=true) {
  global $attachment_chunk, $attachment_name, $attachment_type, $attachment_temp;
  global $local_chunk, $local_name, $local_type, $local_temp;
  global $bcc, $cc;
  global $PHPMailerLocation, $fixedFromEmail, $fixedFromName;
 
  if ($realname) {
    $sendTo = $realname . "<" . $email . ">";
  } else {
    $sendTo = $email;
  }
  $ob = "----=_OuterBoundary_000";
  $ib = "----=_InnerBoundery_001";
 
  $headers  = "MIME-Version: 1.0\r\n";
  if ($fixedFromEmail != '') {
    $headers .= "From: " . $fixedFromEmail . "\n";
  } else {
    $headers .= "From: " . $sendTo . "\n";
  }
  $headers .= "To: " . $recipient . "\n";
  $headers .= "Reply-To: " . $sendTo . "\n";
  if ($cc)  { $headers .= "Cc: ".$cc."\n"; }
  if ($bcc) { $headers .= "Bcc: ".$bcc."\n"; }
  $headers .= "X-Priority: 1\n";
  $headers .= "X-Mailer: PHPMailer-FE v" . VERSION . " (software by codeworxtech.com)\n";
  $headers .= "Content-Type: multipart/mixed;\n\tboundary=\"" . $ob . "\"\n";
  $message  = "This is a multi-part message in MIME format.\n";
  $message .= "\n--".$ob."\n";
  $message .= "Content-Type: multipart/alternative;\n\tboundary=\"" . $ib . "\"\n\n";
  $message .= "\n--" . $ib . "\n";
  $message .= "Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
  $message .= "Content-Transfer-Encoding: quoted-printable\n\n";
  $message .= $content["text"] . "\n\n";
  $message .= "\n--" . $ib . "--\n";
  if ($attachment_name && $inbound) {
    $message .= "\n--" . $ob . "\n";
    $message .= "Content-Type: $attachment_type;\n\tname=\"" . $attachment_name . "\"\n";
    $message .= "Content-Transfer-Encoding: base64\n";
    $message .= "Content-Disposition: attachment;\n\tfilename=\"" . $attachment_name . "\"\n\n";
    $message .= $attachment_chunk;
    $message .= "\n\n";
  } else if ($local_name && $inbound === false) {
    $message .= "\n--" . $ob . "\n";
    $message .= "Content-Type: $local_type;\n\tname=\"" . $local_name . "\"\n";
    $message .= "Content-Transfer-Encoding: base64\n";
    $message .= "Content-Disposition: attachment;\n\tfilename=\"" . $local_name . "\"\n\n";
    $message .= $local_chunk;
    $message .= "\n\n";
  }
  $message .= "\n--" . $ob . "--\n";
  if (file_exists($PHPMailerLocation)) {
    include_once($PHPMailerLocation);
    $mail           = new PHPMailer();
    if ( isset($_POST['Mailer']) && trim($_POST['Mailer']) == "smtp" ) {
      // get path of class.phpmailer.php
      $path_parts = pathinfo($PHPMailerLocation);
      $mail->PluginDir  = $path_parts['dirname']; // set if class is not in PHP Path or not in same directory as calling script
      $mail->IsSMTP();
      if ( isset($_POST['Host']) && trim($_POST['Host']) != "" ) {
        $mail->Host = trim($_POST['Host']);
      }
      if ( isset($_POST['Port']) && trim($_POST['Port']) != "" ) {
        $mail->Port = trim($_POST['Port']);
      }
      if ( isset($_POST['SMTPAuth']) && ( $_POST['SMTPAuth'] === true || $_POST['SMTPAuth'] === false) ) {
        $mail->SMTPAuth = $_POST['SMTPAuth'];
      }
      if ( isset($_POST['Username']) && trim($_POST['Username']) != "" ) {
        $mail->Username = trim($_POST['Username']);
      }
      if ( isset($_POST['Username']) && trim($_POST['Username']) != "" ) {
        $mail->Password = trim($_POST['Password']);
      }
      if ( isset($_POST['Timeout']) && trim($_POST['Timeout']) != "" ) {
        $mail->Timeout = trim($_POST['Timeout']);
      }
    } elseif ( isset($_POST['Mailer']) && trim($_POST['Mailer']) == "sendmail" ) {
      $mail->IsSendmail();
      $mail->Sendmail = trim($_POST['Sendmail']);
    } elseif ( isset($_POST['Mailer']) && trim($_POST['Mailer']) == "qmail" ) {
      $mail->IsQmail();
    }
    if ($fixedFromEmail != '') {
      $mail->From     = $fixedFromEmail;
      $mail->FromName = $fixedFromName;
    } else {
      $mail->From     = $email;
      $mail->FromName = $realname;
    }
    $mail->Subject  = $subject;
    $mail->AltBody  = $content["text"];
    $mail->MsgHTML($content["html"]);
    $mail->AddAddress($recipient);
    if ($bcc) {
      if (count($bcc) > 1) {
        $bcc_in = split(',',$bcc);
        foreach ($bcc_in as $key => $value) {
          $mail->AddBcc($value);
        }
      } else {
        $mail->AddBcc($bcc);
      }
    }
    if ($cc) {
      if (count($cc) > 1) {
        $cc_in = split(',',$cc);
        foreach ($cc_in as $key => $value) {
          $mail->AddCc($value);
        }
      } else {
        $mail->AddCc($cc);
      }
    }
 
    if ($attachment_name && $inbound) {
      $mail->AddAttachment($attachment_temp, $attachment_name);
    } else if ($local_name && $inbound === false) {
      $mail->AddAttachment($local_temp, $local_name);
    }
 
    $mail->Send();
  } else {
    @mail($recipient, $subject, $message, $headers);
  }
 
}
 
/**
 * Function to build the redirect HTML page for redirect (if no redirect specified)
 * @param string $title
 * @param string $bgcolor
 * @param string $text_color
 * @param string $link_color
 * @param string $vlink_color
 * @param string $alink_color
 * @param string $style_sheet
 * @return void
 */
function build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet) {
  if ($style_sheet) {
    echo "<link rel=\"stylesheet\" href=file:///Macintosh%20HD/Users/tompiccirillo/Desktop/PHPMailer-FE_v3/sample_form/_lib/%5C%22$style_sheet%5C%22 Type=\"text/css\">\n";
  }
  if ($title) {
    echo "<title>$title</title>\n";
  }
  if (!$bgcolor) {
    $bgcolor = "#FFFFFF";
  }
  if (!$text_color) {
    $text_color = "#000000";
  }
  if (!$link_color) {
    $link_color = "#0000FF";
  }
  if (!$vlink_color) {
    $vlink_color = "#FF0000";
  }
  if (!$alink_color) {
    $alink_color = "#000088";
  }
  if ($background) {
    $background = "background=\"$background\"";
  }
  echo "<body bgcolor=\"$bgcolor\" text=\"$text_color\" link=\"$link_color\" vlink=\"$vlink_color\" alink=\"$alink_color\" $background>\n\n";
}
 
/**
 * Function to decode URL including UTF8 elements
 * @param string $str
 * @return void
 */
function utf8_urldecode($str) {
  if ( !is_array($str) ) {
    $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));
    return html_entity_decode($str);
  } else {
    return $str;
  }
}
 
/**
 * Function to check the user's IP address or Remote Host is on the banlist
 * @param string $fileBanlist
 * @return boolean
 */
function checkBanlist($fileBanlist) {
  // if the option is set, read the ban list and refuse to process further if IP is found
  $file      = fopen($fileBanlist, 'r');
  $matchIP   = false;
  $matchHOST = false;
  $banned    = false;
  while (!feof($file)) {
    $line    = fgets($file);
    $lbits   = split(',', $line);
    $banIP   = trim($lbits[0]);
    $banHOST = trim($lbits[1]);
    if ($_SERVER['REMOTE_ADDR'] == $banIP) {
      $matchIP = true;
      $banned  = true;
    }
    if (gethostbyaddr($_SERVER['REMOTE_ADDR']) == $banHOST) {
      $matchHOST = true;
      $banned    = true;
    }
  }
  fclose($file);
  if ($banned === true) {
    return true;
  } else {
    return false;
  }
}
 
/**
 * Function to check for banned input on fields that contain "nourl" or "comments" in field name
 * - will add IP / Remote Host to the ban list log if found and stop processing
 * @param string $key
 * @param string $value
 * @param string $fileBanlist
 * @return boolean
 */
function checkBannedInput($key,$value,$fileBanlist) {
  $hack = false;
  if ( stristr($key, 'nourl') || stristr($key, 'comments') ) {
    if ( stristr($value, '<a href') ||         stristr($value, '/a>') ||
         stristr($value, 'http:') ||
         stristr($value, 'www') ) {
      $hack = true;
      echo $value . " - " . $key . ": hyperlink not allowed<br />";
    }
  }
  if ($hack === true) {
    // ADD TO BAN LIST
    if (is_writable($fileBanlist)) {
      $handle = fopen($fileBanlist, 'a');
      fwrite($handle, $_SERVER['REMOTE_ADDR'] . "," . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\n");
      fclose($handle);
    }
  }
  return $hack;
}
 
/**
 * Function to do the DNS MX record check for Windows based servers
 * @param string $hostname
 * @param string $recType
 * @return boolean
 * (returns true if hostname MX record exists
 */
function checkworxdnsrr($hostName, $recType = 'MX') {
  exec("nslookup -type=$recType $hostName", $result);
  // if line starts with the hostname then function succeeded.
  foreach ($result as $line) {
    if( eregi("^$hostName",$line) ) {
      return true;
    }
  }
  // otherwise there was no mail handler for the domain
  return false;
}
 
/**
 * Function to validate an email address (format and MX record)
 * @param string $email
 * @return boolean
 * (returns true if email address is properly formatted and MX record exists
 */
function _validateEmail($emailAddy) {
  $pattern = "/^[\w-]+(\.[\w-]+)*@";
  $pattern .= "([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i";
  if (preg_match($pattern, $emailAddy)) { // valid email address
    $parts = explode("@", $emailAddy);
    if ( function_exists('checkdnsrr') ) {
      if (!checkdnsrr($parts[1], 'MX')) { // fails MX record check
        return false;
      }
    }
  } else { // fails pre_match test
    return false;
  }
  return true;
}
 
  /* Process file or contents to strip out the <body tag (inclusive)   * and the </body tag to the end
   *
   * Usage Example:
   * $page->getContents( '', '/contents.htm' );
   * or
   * $page->getContents( 'start of data .... end of data' );
   *
   * @access public
   * @param string $contents Parameter contents
   * @param string $filename Parameter filename (fully qualified)
   * @desc strip out body tags and return only page data
   */
  function getContents($contents, $filename="") {
    //if ( $contents == '' && $filename != '' && file_exists($filename) ) {
    if ( $contents == '' && $filename != '' ) {
      $handle = fopen($filename, "r");
      $contents = '';
      while (!feof($handle)) {
        $contents .= fread($handle, 8192);
      }
      fclose($handle);
      //$contents = file_get_contents($filename);
    }
    if (preg_match_all('/'.DELIMITERLEFT.'([a-zA-Z0-9_. >]+)'.DELIMITERRIGHT.'/', $contents, $var)) {
      foreach ($var[1] as $fulltag) {
        $code = $_POST[$fulltag];
        $code = str_replace("\n","<br />",$code);
        $contents  =  str_replace(DELIMITERLEFT.$fulltag.DELIMITERRIGHT, $code, $contents);
      }
      $contents = stripslashes($contents);
    }
    // START process any PHP code
    ob_start();
    eval("?>".$contents."<?php ");
    $contents = ob_get_contents();
    ob_end_clean();
    // END process any PHP code
    $lower_contents = strtolower($contents);
    // determine if a <body tag exists and process if necessary
    $bodytag_start = strpos($lower_contents, "<body");
    if ( $bodytag_start !== false ) {
      $bodytag_end    = strpos($lower_contents, ">", $bodytag_start) + 1;
      // get contents with <body tag removed
      $contents       = substr($contents, $bodytag_end);
      $lower_contents = strtolower($contents);
      // work on </body closing tag
      $end_start      = strpos($lower_contents, "</body");
      $end_end        = strpos($lower_contents, ">", $bodytag_start) + 1;
      // return stripped out <body and </body tags
      return substr($contents, 0, $end_start);
    } else {
      // body tags not found, so return data
      return $contents;
    }
  }
 
  /* Get template file ( primarily for internal script use )
   * and process for any variable substitution
   *
   * Usage Example:
   * $page->getContents( '', '/contents.htm' );
   * or
   * $var = getTplFile( 'path/to/filename' );
   *
   * @access public
   * @param string $filename Parameter filename (fully qualified)
   * @desc return file contents
   */
  function getTplFile($filename) {
    $handle = fopen($filename, "r");
    $msgTPL = '';
    while (!feof($handle)) {
      $msgTPL .= fread($handle, 8192);
    }
    fclose($handle);
    if (preg_match_all('/'.DELIMITERLEFT.'([a-zA-Z0-9_. >]+)'.DELIMITERRIGHT.'/', $msgTPL, $var)) {
      foreach ($var[1] as $fulltag) {
        $code = $_POST[$fulltag];
        $code = str_replace("\n","<br />",$code);
        $msgTPL  =  str_replace(DELIMITERLEFT.$fulltag.DELIMITERRIGHT, $code, $msgTPL);
      }
      $msgTPL = stripslashes($msgTPL);
    }
    // START process any PHP code
    ob_start();
    eval("?>".$msgTPL."<?php ");
    $msgDisplay = ob_get_contents();
    ob_end_clean();
    return $msgDisplay;
  }
 
 
 
?>
Attachments:
 
 
[+][-]11/05/08 04:49 AM, ID: 22885076Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: PHP and Databases, MySQL Server
Tags: Codeworx Technologies, phpmailer-fe, 3.1, php
Sign Up Now!
Solution Provided By: Ray_Paseur
Participating Experts: 1
Solution Grade: A
 
[+][-]12/13/08 05:13 AM, ID: 23163792Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]12/18/08 03:30 PM, ID: 23208886Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 / EE_QW_2_20070628