-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
executable file
·1194 lines (1107 loc) · 47.2 KB
/
contact.php
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
<?php
/**
* Class file to handle user requests for contact form
*
* LICENSE:
*
* This source file is subject to the licensing terms that
* is available through the world-wide-web at the following URI:
* http://codecanyon.net/wiki/support/legal-terms/licensing-terms/.
* The buyers have extended license are hence certified to use or
* extend the functionality of this file or re-sell after modification.
*
* This file is licensed to be used with Eventify theme and the
* same can be resold/redistributed with the terms subject to those
* are specified for extended license at Envato marketplace in the above link
*
* PHP version >= 5.3
*
* @category ContactForm
* @package ContactForm
* @author Kirti Kumar Nayak, India <[email protected]>
* @copyright 2013 TheBestFreelancer,
* @license http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ CodeCanyon
* @version Release 1.9
* @link http://demos.thebestfreelancer.in/phpcontact/
* @tutorial http://demos.thebestfreelancer.in/phpcontact/documentation/
*/
/**
* Check if Contact class exists or not and define if not
*/
if (!class_exists('Contact')) {
/**
* Class to handle contact form requests handled via url
*
* This is a singleton pattern class and can be called via static methods
*
* @category ContactForm
* @package ContactForm
* @author Kirti Kumar Nayak, India <[email protected]>
* @copyright 2013 TheBestFreelancer,
* @license http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ CodeCanyon
* @version Release 1.9
* @link http://demos.thebestfreelancer.in/phpcontact/
* @tutorial http://demos.thebestfreelancer.in/phpcontact/documentation/
*/
class Contact
{
// {{{ properties
/**
* private variable to store any string
* mainly used to store user submitted data
*
* @access private
* @var string The string submitted by user/visitor
*/
private $_str;
/**
* private variable to store a string of allowable HTML tags
* to be used against code / CSFR / XSS attacks by visitors/hackers
*
* @access private
* @var string The allowable html tags for user
*/
private $_allowedHTML;
/**
* private variable to store
* an array of restricted HTML/special characters
* to be used against code / CSFR / XSS attacks by visitors/hackers
*
* @access private
* @var string The restricted special characters/strings for user
*/
private $_restrictedChars;
/**
* private property to store mail receivers/admin
*
* @access private
* @var string The e-mail id(s) who will receive the mail
*/
private $_receiver;
/**
* private property to hold the lowercase letter set
* to be used to generate random string
*
* @access private
* @var string The lowercase character set string
*/
private $_lowerCaseChars;
/**
* private property to hold the uppercase letter set
* to be used to generate random string
*
* @access private
* @var string The uppercase character set string
*/
private $_upperCaseChars;
/**
* private property to hold the numeric character set
* to be used to generate random string
*
* @access private
* @var string The numeric character set string
*/
private $_numericChars;
/**
* private property to hold the special character set
* to be used to generate random string
*
* @access private
* @var string The special character set string
*/
private $_specialChars;
/**
* private variable for random characters used by captcha method
*
* @access private
* @var string The character set from which captcha should be generated
*/
private $_charSet;
/**
* Private variable to store captcha type
* if you have no GD library installed you may switch over to
* Javascript captcha
*
* @access private
* @var string The type of the captcha wanted
*/
private $_captchaType;
/**
* Private variable to store captcha width
*
* @access private
* @var int The height of the captcha image
*/
private $_captchaWidth;
/**
* Private variable to store the captcha height
*
* @access private
* @var int The height of the captcha image
*/
private $_captchaHeight;
/**
* Private variable to store the location of the font to be used in captcha image
*
* @access private
* @var string The path string of the ttf font file
*/
private $_captchaFontLocation;
/**
* Private variable to store the captcha image font size
*
* @access private
* @var float The font size for the captcha image
*/
private $_captchaFontSize;
/**
* Private variable to store the captcha string angle
*
* @access private
* @var float The angle of the captcha string
*/
private $_captchaCharAngle;
/**
* private variable to hold mail type
* expected values 'plain' / 'html'
*
* @access private
* @var string The string describing mail type
*/
private $_mailType;
/**
* private variable to store plain template
*
* @access private
* @var string The plain mail template string
*/
private $_plainMailTemplate;
/**
* private variable to store html template
*
* @access private
* @var string The html mail template string
*/
private $_htmlMailTemplate;
/**
* private variable to store html reply template
*
* @access private
* @var string The html reply mail template string
*/
private $_replyHtmlMailTemplate;
/**
* private variable to contain response and to be converted into json
*
* @access private
* @var mixed Json data object for page responses
*/
private $_response;
/**
* private variable to store system auto response mail id
*
* @access private
* @var string The name and e-mail string of the system
*/
private $_autoResponder;
/**
* private static variable to hold class object
*
* @access private
* @staticvar
* @var object The current class object
*/
private static $_classObject;
// }}}
// {{{ __construct()
/**
* Default constructor class to initialize variables and page data.
* Accoring to singleton class costructor must be private
*
* @return void
* @access private
*/
private function __construct()
{
/*
* set Error Reporting to all
*/
error_reporting(E_ALL | E_STRICT);
/*
* Initialize a session if not started yet
* YOU MUST ENABLE THIS IF WANT TO USE CAPTCHA !!!!!!!!!!!!
*/
/*if (session_id() === '') {
session_start();
}
/*
* Set the receiver e-mail of the mail
* CHANGE IT ACCORDING TO NEEDS
*/
$this->_receiver = '[email protected]';
/*
* initialize the allowed html tags which user/visitor can
* use to send a html formatted message
* define more if you want
*/
$this->_allowedHTML = '<a><br><div><p><span><strong>';
$this->_allowedHTML .= '<h1><h2><h3><h4><h5><h6><hr>';
$this->_allowedHTML .= '<table><tr><td><th><thead><tfoot>';
/*
* initialize the allowed html tags which user/visitor can
* use to send a html formatted message
* define more if you want
*/
$this->_restrictedChars = array('"', 'javascript', '()', '\\');
/*
* Main user configurations start
* You may edit as per your need from here
* Please refer to documentation if you face problems
* Or you may ask me in the support section
*/
// captcha configurations
/*
* define captcha type as php
* you may use javascript captcha too
* possible values: php, js
*/
$this->_captchaType = 'php';
/*
* initialize captcha image width
* it is defined as per the html design
*/
$this->_captchaWidth = 70;
/*
* initialize the captcha image height
* defined optimum for the design
*/
$this->_captchaHeight = 30;
/*
* initialize the font file location to be used for captcha characters
* it must be a valid ttf font file at the specified location
*/
$this->_captchaFontLocation = './MONOFONT.TTF';
/*
* initialize the font size of the captcha string
* by default the maximum defined i.e. 80% of the image height
*/
$this->_captchaFontSize = $this->_captchaHeight * 0.8;
/*
* initialize the characters angle for the captcha
* it is randomly set between -2 and 2
* as the image height and font size are set
*/
$this->_captchaCharAngle = rand(-2, 2);
/*
* initialize the lowercase character set from a-z
*/
$this->_lowerCaseChars = 'abcdefghijklmopqrstuvwxyz';
/*
* initialize the uppercase character set from A-Z
*/
$this->_upperCaseChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
/*
* initalize the numeric character set from 0-9
*/
$this->_numericChars = '0123456789';
/*
* initialize the special character set (add more or delete if you like)
*/
$this->_specialChars = '!$%^&*+#~/|';
/*
* initialize the captcha characters as null
*/
$this->_charSet = '';
// mail configurations
/*
* Initialize mail type to catch user preferences
* change it if you want plain mail witout any formatting
*/
$this->_mailType = 'html';
/*
* initiate auto reply system name and e-mail
* Change it accodting to your needs
*/
$this->_autoResponder = '[email protected]';
/*
* Initialize plain mail content template
*/
$this->_plainMailTemplate = '{userMessage}';
$this->_plainMailTemplate .= "\r\n\r\n\r\n" . 'From';
$this->_plainMailTemplate .= "\r\n" . 'Name : {userFullName}';
$this->_plainMailTemplate .= "\r\n" . 'E-Mail : {userEmail}';
// check for optional fields and add them if they are set
/*if (isset($_POST['phone']) and (trim($_POST['phone']) !== '')) {
$this->_plainMailTemplate .= "\r\n" . 'Phone : {userPhone}';
}
if (isset($_POST['url']) and (trim($_POST['url']) !== '')) {
$this->_plainMailTemplate .= "\r\n" . 'URL : {userUrl}';
}
/*
* define html mail content template
*/
$this->_htmlMailTemplate = '<html><body>';
$this->_htmlMailTemplate .= '<table style="margin:0 auto;padding:20px;width:90%;display:block;color:#000;background-color:#dddfea;font-family:Tahoma;border-radius:10px"><tr>';
$this->_htmlMailTemplate .= '<td style="padding:5px;width:100%;display:block">';
$this->_htmlMailTemplate .= '<p>{userMessage}</p>';
$this->_htmlMailTemplate .= '</td></tr>';
$this->_htmlMailTemplate .= '<tr><td style="margin-top:10px;padding-left:10px;font-weight:700;font-family:seriff;font-style:italic">';
$this->_htmlMailTemplate .= '<h4>From</h4></td></tr>';
$this->_htmlMailTemplate .= '<tr><td><hr />Name : {userFullName}</td></tr>';
$this->_htmlMailTemplate .= '<tr><td>E-Mail : {userEmail}</td></tr>';
// check for optional fields and add them if they are set
/*if (isset($_POST['phone']) and (trim($_POST['phone']) !== '')) {
$this->_htmlMailTemplate .= '<tr><td>Phone : {userPhone}</td></tr>';
}
if (isset($_POST['url']) and (trim($_POST['url']) !== '')) {
$this->_htmlMailTemplate .= '<tr><td>URL : {userUrl}</td></tr>';
}*/
$this->_htmlMailTemplate .= '</table></body></html>';
/*
* define reply html mail content template
*/
$this->_replyHtmlMailTemplate = '<html><body>';
$this->_replyHtmlMailTemplate .= '<table style="margin:0 auto;padding:20px;width:100%;display:block;color:#000;font-family:Tahoma">';
$this->_replyHtmlMailTemplate .= '<tr><td style="padding:10px;width:90%;display:block">';
$this->_replyHtmlMailTemplate .= 'Dear {userName}</td></tr>';
$this->_replyHtmlMailTemplate .= '<tr><td><p>We just received your following mail.<br />We\'ll reach you as soon as possible.</p><br /></td></tr>';
$this->_replyHtmlMailTemplate .= '<tr><td><i style="font-size:10px">This is an auto generated reply. Please <strong>do not reply to this e-mail</strong></i></td></tr>';
$this->_replyHtmlMailTemplate .= '<tr><td style="padding:15px;font-weight:normal;font-size:11px;border:#ccc 1px solid;border-radius:8px">';
$this->_replyHtmlMailTemplate .= '<p>{userMessage}</p></td></tr>';
$this->_replyHtmlMailTemplate .= '<tr><td style="margin-top:10px;padding-left:10px;font-weight:700;font-family:seriff;font-style:italic">';
$this->_replyHtmlMailTemplate .= '<h4>From</h4></td></tr><tr><td>';
$this->_replyHtmlMailTemplate .= $this->_autoResponder;
$this->_replyHtmlMailTemplate .= '</td></tr>';
$this->_replyHtmlMailTemplate .= '</body></html>';
// output configurations
/*
* initialize page contents as null
*/
$this->_pageContents = '';
/*
* set page compression to true
* you may set this false
* if you don't like to compress the page contents
*/
$this->_pageCompression = true;
/*
* Initialize the response variable as null
*/
$this->_response = array(
'status' => '',
'message' => '',
'control' => ''
);
}
// }}}
// {{{ getObject()
/**
* Method to return singleton class object.
* returns current class object if already present
* else creates one
*
* @return object The current class object
* @access public
* @static
*
*/
public static function getObject()
{
/*
* check if class not instantiated
*/
if (self::$_classObject === null) {
/*
* then create a new instance
*/
self::$_classObject = new self();
}
/*
* return the class object to be used
*/
return self::$_classObject;
}
// }}}
// {{{ _getRandomChars
/**
* Generate string of random characters
*
* @param int $length Length of the string to generate
* @param bool $lowerCaseChars Include lower case characters
* @param bool $upperCaseChars Include uppercase characters
* @param bool $numericChars Include numbers
* @param bool $specialChars Include special characters
*
* @access private
* @return string The random character string
*/
private function _getRandomChars (
$length = 5,
$lowerCaseChars = true,
$upperCaseChars = true,
$numericChars = true,
$specialChars = false
) {
/**
* variable to store a random character index every time
* @access private
* @var int The random character index out of character set
*/
$charIndex = '';
/**
* variable to store a random character every time
* @access private
* @var char The random character out of character set
*/
$char = '';
/**
* variable to store a random character set every time
* @access private
* @var int The random character setof length 5 out of character set
*/
$resultChars = '';
/*
* check if user has opted for lowercase characters
* if true, then add it to the character set
*/
if ($lowerCaseChars === true) {
$this->_charSet .= $this->_lowerCaseChars;
}
/*
* Check if user has opted for uppercase characters
* If true, add it to the character set
*/
if ($upperCaseChars === true) {
$this->_charSet .= $this->_upperCaseChars;
}
/*
* Check if user has opted for numeric characters
* If true, add it to the character set
*/
if ($numericChars === true) {
$this->_charSet .= $this->_numericChars;
}
/*
* Check if user has opted for uppercase characters
* If true, add it to the character set
*/
if ($specialChars === true) {
$this->_charSet .= $this->_specialChars;
}
/*
* Check if length has given greater than 0 else return null
*/
if (($length < 0) || ($length == 0)) {
return $resultChars;
}
/*
* create a loop to get random 5 characters from the character set
*
*/
for ($i = 0; $i < $length; $i++) {
/*
* get the character randomly
* by selecting between 0 to length of the charSet
*/
$charIndex = rand(0, strlen($this->_charSet));
$char = substr($this->_charSet, $charIndex, 1);
$resultChars .= $char;
}
return $resultChars;
}
// }}}
// {{{ respondRequest()
/**
* Method to respond to the requests via url
*
* @param bool $pageCompression Option for the output data to be compressed or not
* @param mixed $mapOptions The option to show/hide, logitude, latitude for Google Map
* @param string $companyName The name of your company
* @param string $address The address of your company
* @param string $captchaType The type of captcha wanted, possible values: php, js
* @param string $mailType The type of mail to be sent, possible values: html, text
* @param string $emails The address of mail to send, possible values: as specified
* @param string $autoResponder The address of reply mail to be sent back to the visitor
*
* @return mixed May output page HTML string or JSON validation data
* @access public
*/
public function respondRequest(
$captchaType,
$mailType,
$emails,
$autoResponder
) {
/*
* assign captcha type as user has defined
* you may use javascript captcha too
* possible values: php, js
*/
$this->_captchaType = $captchaType;
/*
* assign mail type to catch user preferences
* change it if you want plain mail witout any formatting
*/
$this->_mailType = $mailType;
/*
* set page compression to user defined
* you may set this false
* if you don't like to compress the page contents
*/
$this->_receiver = $emails;
/*
* set page compression to user defined
* you may set this false
* if you don't like to compress the page contents
*/
$this->_autoResponder = $autoResponder;
/*
* catch the get variable
* if set then act accordingly
*/
if (isset($_GET['req'])) {
/*
* switch over the request and respond accordingly
*/
switch ($_GET['req']) {
case 'captcha':
/*
* call the method to create the captcha image
*/
$this->createCaptcha();
break;
case 'captchaimg':
/*
* check if user has opted php captcha and GD library present
* if user has them both then
* call the method to create the captcha image
* else just return the captcha characters
*/
if (extension_loaded('gd') and ($this->_captchaType==='php')) {
/*
* return an image tag
*/
echo '<img src="' . $_SERVER['PHP_SELF'] . '?req=captcha&tm='.time().'" alt="Captcha Image" title="Click to get new challenge" />';
} else {
/*
* take two variables with random integer values,
* then add them and save in session to verify
* @var int Integers to work as captcha
*/
$a = rand(1, 9);
$b = rand(1, 9);
/*
* Assign the characters to a session variable
*/
$_SESSION['CaptchaChars'] = $a+$b;
/*
* Close the session write buffer to avoid overwriting
*/
session_write_close();
/*
* simply output the characters only
*/
echo '<h5>'.$a.' + '.$b.' =</h5>';
}
break;
default:
/*
* call the method to validate and send the message
*/
$this->sendMail();
break;
}
/*
* validate the name must not be empty
* and send json data
*/
} else {
/*
* call the method to validate and send the message
*/
$this->sendMail();
}
}
// }}}
// {{{ createCaptcha()
/**
* Method to create captcha image for bot verification
*
* @return mixed Image for captcha
* @throws Exception GD or general exceptions
* @access public
*/
public function createCaptcha()
{
try {
/*
* Assign the characters to a session variable
*/
$_SESSION['CaptchaChars'] = $this->_getRandomChars(5, false, true, true, false);
/*
* Close the session write buffer to avoid overwriting
*/
session_write_close();
/*
* Create a 100 X 30 image and assign it to a var
*/
$img = imagecreatetruecolor($this->_captchaWidth, $this->_captchaHeight);
/*
* create a white color
*/
$white = imagecolorallocate($img, 255, 255, 255);
/*
* Create a black color to write the characters prominently
*/
$black = imagecolorallocate($img, 0, 0, 0);
/*
* fill the rectangular image with white background
*/
imagefilledrectangle($img, 0, 0, 399, 30, $white);
/*
* Write the string inside the image
* with black color
*/
imagettftext(
$img,
$this->_captchaFontSize,
$this->_captchaCharAngle,
2,
25,
$black,
$this->_captchaFontLocation,
$_SESSION['CaptchaChars']
);
/*
* generating dots randomly in background
* to make an image noise
* if you want more noise replace the argument 5
* as per your requirement
*/
for ( $i=0; $i<5; $i++ ) {
imagefilledellipse(
$img,
mt_rand(0, $this->_captchaWidth),
mt_rand(0, $this->_captchaHeight),
2,
3,
0
);
}
/*
* generating lines randomly in background of image
* for more noise
* if you want more noise replace the argument 10
* as per your requirement
*/
for ( $i=0; $i<10; $i++ ) {
imageline(
$img,
mt_rand(0, $this->_captchaWidth),
mt_rand(0, $this->_captchaHeight),
mt_rand(0, $this->_captchaWidth),
mt_rand(0, $this->_captchaHeight),
0
);
}
/*
* Output the image
*/
header('Content-Type: image/gif');
/*
* output a gif image
*/
imagegif($img);
/*
* destroy the image to save server space
*/
imagedestroy($img);
}
catch(Exception $ex) {
die('Oh no.. Something gone wrong... Details: ' . $ex->getMessage());
}
}
// }}}
// {{{ _cleanSubmittedData()
/**
* The following method makes a variable safe
* as that may contain unacceptable formats or data
* to prevent security holes those may be a threat
*
* @param mixed $submittedData The data submitted by the user to be filtered
*
* @return mixed Cleaned data submitted by the user
* @access protected
*/
protected function _cleanSubmittedData($submittedData)
{
try {
/*
* check if the data is an array or not
*/
if (!is_array($submittedData)) {
/*
* if that is not an array, treat that as a string
*/
$this->_str = $submittedData;
/*
* trim the spaces if any
*/
$this->_str = trim($this->_str);
/*
* check if magic quotes are on or not
* if on then it must have inserted slashes before quotes and slashes
*/
if (get_magic_quotes_gpc()) {
/*
* if magic quotes are on, it inserts a slash before any quotes, hence remove them
*/
$this->_str = stripslashes($this->_str);
}
/*
* escape the data and insert null where restricted characters found
*/
$this->_str = str_ireplace($this->_restrictedChars, "", $this->_str);
/*
* allow the tags for user and strip off rest of them
*/
$this->_str = strip_tags($this->_str, $this->_allowedHTML);
/*
* now return the cleaned data
*/
return $this->_str;
} else {
/**
* var to keep cleaned data array for a temporary period
* so that they can be returned in cleaned state
* and acceptable format
*
* @var mixed The injection cleaned data array
* @access private
*/
$cleanArr = array();
/*
* if the data is an array
* fetch the array values one by one by the loop
*/
foreach ($submittedData as $pointer=>$str) {
/*
* Recursively call clean function if the data is array
*/
$cleanArr[$pointer]=$this->_cleanSubmittedData($str);
}
/*
* return the cleaned data array
*/
return $cleanArr;
}
}
catch(Exception $ex) {
/*
* Catch any Exceptions occured
*/
die('There seems an error while cleaning user submitted data. Description: '. $ex->getMessage());
}
}
// }}}
// {{{ sendMail()
/**
* Method to send normal mail
*
* @return string JSON data object for success or failure
* @access public
*/
public function sendMail()
{
/*
* clean up the user submitted data with the defined method
*/
$submittedData = $this->_cleanSubmittedData($_POST);
/*
* validate the form data
*/
if (!isset($submittedData['contact_name']) or ($submittedData['contact_name'] === '')) {
/*
* fill out the response array variable
* with alert/error message having bootstrap styles
*/
$this->_response['status'] = 'error';
$this->_response['message'] = '<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
$this->_response['message'] .= 'Please Enter your Name'.$submittedData['contact_name'];
$this->_response['message'] .= '</div>';
/*
* output the json data by converting the response array into a json format
*/
echo json_encode($this->_response);
/*
* exit the script
*/
exit(0);
}
/*
* validate email via php predefined (inbuilt) function
*/
if (!isset($submittedData['contact_email']) or (strlen(filter_var($submittedData['contact_email'], FILTER_VALIDATE_EMAIL)) < 1)) {
$this->_response['status'] = 'error';
$this->_response['message'] = '<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
$this->_response['message'] .= 'Please Enter your Valid E-Mail';
$this->_response['message'] .= '</div>';
echo json_encode($this->_response);
exit(0);
}
/*
* validate the phone number correct or not if entered
* enable if you want to validate phone number
*/
/*if (isset($submittedData['phone']) and !empty($submittedData['phone']) and (!preg_match('/^(\+[1-9][0-9]*(\([0-9]*\)|-[0-9]*-))?[0]?[1-9][0-9\- ]*$/', $submittedData['phone']))) {
$this->_response['status'] = 'error';
$this->_response['message'] = '<div class="alert alert-danger alert-dismissable">';
$this->_response['message'] .= 'Please Enter a correct phone number';
$this->_response['message'] .= '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>';
$this->_response['control'] = 'phone';
echo json_encode($this->_response);
exit(0);
}
/*
* validate the url correct or not if entered
* enable this if you want to validate url
*/
/*if (isset($submittedData['url']) and !empty($submittedData['url']) and (!preg_match('/(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/', $submittedData['url']))) {
$this->_response['status'] = 'error';
$this->_response['message'] = '<div class="alert alert-danger alert-dismissable">';
$this->_response['message'] .= 'Please Enter a correct URL';
$this->_response['message'] .= '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>';
$this->_response['control'] = 'url';
header("Content-Type: application/json");
echo json_encode($this->_response);
exit(0);
}
/*
* validate subject for empty value
*/
if (!isset($submittedData['contact_subject']) or ($submittedData['contact_subject']==='')) {
$this->_response['status'] = 'error';
$this->_response['message'] = '<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
$this->_response['message'] .= 'Please Enter a Subject';
$this->_response['message'] .= '</div>';
echo json_encode($this->_response);
exit(0);
}
/*
* validate the message empty or blank
*/
if (!isset($submittedData['contact_message']) or ($submittedData['contact_message'] === '')) {
$this->_response['status'] = 'error';
$this->_response['message'] = '<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
$this->_response['message'] .= 'Please Enter your Message';
$this->_response['message'] .= '</div>';
echo json_encode($this->_response);
exit(0);
}
/*
* Enable this if you want to validate captcha
*/
/*if (!isset($submittedData['captcha']) or !isset($_SESSION['CaptchaChars']) or ($submittedData['captcha'] !== (string)$_SESSION['CaptchaChars'])) {
$this->_response['status'] = 'error';
$this->_response['message'] = '<div class="alert alert-danger alert-dismissable">';
$this->_response['message'] .= 'Please Enter The Captcha Correctly';
$this->_response['message'] .= '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>';
$this->_response['control'] = 'captcha';
echo json_encode($this->_response);
exit(0);
}
/*
* Build up the mail and
* Set headers first, else the mail may be caught as spam
*/
$headers = array();
$headers[] = "MIME-Version: 1.0";
// set content type according to the option supplied
if ($this->_mailType === 'html') {
$headers[] = "Content-type: text/html; charset=iso-8859-1";
} else {
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
}