Advertisement
Guest User

Untitled

a guest
Aug 18th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.02 KB | None | 0 0
  1. <?php
  2. header('Content-Type: text/html; charset=iso-8859-2');
  3.  
  4. global $post;
  5.  
  6. if($_POST)
  7. {
  8.     $to_email = "pablobbbb@wp.pl"; //Recipient email, Replace with own email here
  9.    
  10.     //check if its an ajax request, exit if not
  11.     if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
  12.        
  13.         $output = json_encode(array( //create JSON data
  14.             'type'=>'error',
  15.             'text' => 'Sorry Request must be Ajax POST'
  16.         ));
  17.         die($output); //exit script outputting json data
  18.     }
  19.    
  20.     //Sanitize input data using PHP filter_var().
  21.     $user_name      = filter_var($_POST["user_name"], FILTER_SANITIZE_STRING);
  22.     $user_surname       = filter_var($_POST["user_surname"], FILTER_SANITIZE_STRING);
  23.     $user_email     = filter_var($_POST["user_email"], FILTER_SANITIZE_EMAIL);
  24.     $phone_number   = filter_var($_POST["phone_number"], FILTER_SANITIZE_NUMBER_INT);
  25.     $street     = filter_var($_POST["street"], FILTER_SANITIZE_STRING);
  26.     $streetnr       = filter_var($_POST["streetnr"], FILTER_SANITIZE_STRING);
  27.     $city       = filter_var($_POST["city"], FILTER_SANITIZE_STRING);
  28.     $zipcode        = filter_var($_POST["zipcode"], FILTER_SANITIZE_STRING);
  29.     $rightnr        = filter_var($_POST["rightnr"], FILTER_SANITIZE_STRING);
  30.     $nip        = filter_var($_POST["nip"], FILTER_SANITIZE_NUMBER_INT);
  31.     $company        = filter_var($_POST["company"], FILTER_SANITIZE_STRING);
  32.     $message = $_POST["message"];
  33.     $subject        = "Nowe zgłoszenie na szkolenia od " . $user_name . " " . $user_surname;
  34.     $sender_subject     = "Potwierdzenie zgłoszenia na szkolenia Poldent.pl";
  35.     $test = mb_convert_encoding('łęśćłżą', 'HTML-ENTITIES', 'UTF-8');
  36.     //$message      = filter_var($_POST["msg"], FILTER_SANITIZE_STRING);
  37.  
  38. $checkbox = $_POST['checkbox'];
  39. $checkbox2 = $_POST['checkbox2'];
  40. $checkbox3 = $_POST['checkbox3'];
  41.  
  42. $school = $_POST['school'];
  43.  
  44. $schoolbody = '';
  45. foreach ($school as $s)
  46. {
  47.     $data = @json_decode($s['value']);
  48.  
  49.     $schoolbody .= "Nazwa szkolenia: ".$data->item_name."\r\nData szkolenia: ".$data->item_number."\r\nGodzina szkolenia: ".$data->item_hour."\r\nKoszt szkolenia: ".$data->amount." zł‚\r\nProwadzący szkolenie: ".$data->item_lect."\r\nLiczba punktów edukacyjnych: ".$data->item_point." \r\n\r\n";
  50.     $schoolbname .= " ".$data->item_name." - ".$data->item_number." ";
  51. }
  52.  
  53. $person = $_POST['person'];
  54.  
  55. $personbody = '';
  56. foreach ($person as $p)
  57. {
  58.     $data = @json_decode($p['value']);
  59.  
  60.     $personbody .= $data->item_person.',';
  61. }
  62.  
  63.  
  64.  
  65.    
  66.     //$title = get_the_title();
  67.    
  68.     //additional php validation
  69.   //additional php validation
  70.  
  71. $rule = '';
  72.  
  73. if(($checkbox3 =="false")){
  74. $rule = 'Nie';
  75.  } else if(($checkbox3 =="true")){
  76. $rule = 'Tak';
  77. }
  78.  
  79.  
  80.         if(strlen($user_name)<2){ // If length is less than 4 it will output JSON error.
  81.                 $output = json_encode(array('type'=>'error', 'text' => 'Wpisane pole "Imię" jest za krótkie lub puste.'));
  82.                 die($output);
  83.         }
  84.         if(strlen($user_surname)<2){ // If length is less than 4 it will output JSON error.
  85.                 $output = json_encode(array('type'=>'error', 'text' => 'Wpisane pole "Nazwisko" jest za krótkie lub puste.'));
  86.                 die($output);
  87.         }
  88.         if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)){ //email validation
  89.                 $output = json_encode(array('type'=>'error', 'text' => 'Proszę wprowadzić poprawny adres e-mail.'));
  90.                 die($output);
  91.         }
  92.    
  93.         if(strlen($phone_number)<7){ // If length is less than 4 it will output JSON error.
  94.                 $output = json_encode(array('type'=>'error', 'text' => 'Podany numer jest błądy lub za krótki.'));
  95.                 die($output);
  96.         }
  97.        
  98.         if($_POST["choice"] == 1) {
  99.         if(strlen($company)<2){
  100.  
  101.         // If length is less than 4 it will output JSON error.
  102.                 $output = json_encode(array('type'=>'error', 'text' => 'Nazwa firmy jest za krótka.'));
  103.                 die($output);
  104.         }
  105.    
  106.         if(strlen($nip)<8){ // If length is less than 4 it will output JSON error.
  107.                 $output = json_encode(array('type'=>'error', 'text' => 'Numer NIP jest błędny.'));
  108.                 die($output);
  109.         }
  110.         }
  111.        
  112.         if(strlen($street)<3){ // If length is less than 4 it will output JSON error.
  113.                 $output = json_encode(array('type'=>'error', 'text' => 'Nazwa ulicy jest za krótka.'));
  114.                 die($output);
  115.         }
  116.    
  117.         if(strlen($streetnr)<1){ // If length is less than 4 it will output JSON error.
  118.                 $output = json_encode(array('type'=>'error', 'text' => 'Numer budynku/lokalu jest za krotki.'));
  119.                 die($output);
  120.         }
  121.    
  122.         if(strlen($city)<3){ // If length is less than 4 it will output JSON error.
  123.                 $output = json_encode(array('type'=>'error', 'text' => 'Nazwa miasta jest za krótka'));
  124.                 die($output);
  125.         }
  126.    
  127.         if(strlen($zipcode)<5){ // If length is less than 4 it will output JSON error.
  128.                 $output = json_encode(array('type'=>'error', 'text' => 'Błędny kod pocztowy.'));
  129.                 die($output);
  130.         }
  131.  
  132.    
  133.         if(strlen($rightnr)<2){ // If length is less than 4 it will output JSON error.
  134.                 $output = json_encode(array('type'=>'error', 'text' => 'Numer do wykonywania zawodu jest za krótki.'));
  135.                 die($output);
  136.         }
  137.        
  138.         if(($checkbox =="false")){
  139.             $output = json_encode(array('type'=>'error', 'text' => 'Brak akceptacji regulaminów szkoleń'));
  140.             die($output);
  141.         }
  142.        
  143.         if(($checkbox2 =="false")){
  144.             $output = json_encode(array('type'=>'error', 'text' => 'Brak akceptacji na przetwarzanie danych osobowych w celu realizacji umowy na uczestnictwo w kursie.'));
  145.             die($output);
  146.         }
  147.  
  148.    
  149.  
  150.  
  151.     //if(strlen($message)<3){ //check emtpy message
  152.     //  $output = json_encode(array('type'=>'error', 'text' => 'Zbyt krĂłtka wiadomość. Wpisz wiÄ™cej!'));
  153.     //  die($output);
  154.     //}
  155.    
  156.     //email body
  157.     $message_body = "
  158.    <html>
  159. <head>
  160.  <title>Test</title>
  161. </head>
  162. <body>
  163.  <p>śłężę</p>
  164.  <table>
  165.    <tr>
  166.      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
  167.    </tr>
  168.    <tr>
  169.      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
  170.    </tr>
  171.    <tr>
  172.      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
  173.    </tr>
  174.  </table>
  175. </body>
  176. </html>
  177.  
  178.    \r\nImię i nazwisko : ".$user_name." ".$user_surname.",
  179.    \r\nEmail : ".$user_email."
  180.    \r\nNumer telefonu : ". $phone_number ."
  181.    \r\nNazwa firmy : ".$company."
  182.    \r\nNIP firmy : ".$nip."
  183.    \r\nUlica : ".$street." ".$streetnr."
  184.    \r\nMiasto : ".$zipcode." ".$city."
  185.    \r\nNumer prawa do wykonywania zawodu : ".$rightnr."
  186.    \r\nTreść Wiadomości : ".$message."
  187.    \r\nPotwierdzenie zgody na przetwarzanie informacji: ".$rule."
  188.    \r\nSzkolenia:\r\n".$schoolbody."
  189.    \r\nTest: ".$test;
  190.    
  191.    
  192.     $sender_message_body = "
  193.    \r\n Uwaga! Po zapisie na szkolenie powinni Państwo otrzymać telefon lub e-mail potwierdzający zapis na dane szkolenie. W przypadku braku kontaktu z naszej strony – prosimy o kontakt telefoniczny pod nr 22 3517668.
  194.    \r\n ".$choice."
  195.    \r\nWitaj ".$user_name." ".$user_surname."
  196.    \r\nDziękujemy za zapisanie się na szkolenie.
  197.    \r\nPoniżej znajduje się lista szkoleń, na które zostałeś zapisany.
  198.    \r\n
  199.    \r\nSzkolenia:
  200.    \r\n".$schoolbody. "
  201.    \r\nWpłatę za szkolenia (jeśli nie jest zaznaczone inaczej w opisie szkolenia) prosimy uiścić na poniższe konto bankowe:
  202.    \r\nPEKAO 64 1240 6175 1111 0010 3915 9844
  203.    \r\nW tytule przelewu prosimy wpisać: imię, nazwisko, datę szkolenia, miejsce szkolenia.
  204.    \r\nWpłat na szkolenia prosimy dokonywać maksymalnie na 2 tygodnie przed datą szkolenia.
  205.    \r\nW razie jakichkolwiek pytań dotyczących szkoleń prosimy o kontakt pod adresem:
  206.    \r\nszkolenia@poldent.pl lub pod tel. 22 351 76 68
  207.    \r\nDziękujemy i do zobaczenia na szkoleniu,
  208.    \r\nZespół Poldent.pl
  209. ";
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  function utf8mail($to,$subject,$message_body,$from_name="x",$from_a = "info@x.com", $reply="info@x.com")
  216. {
  217.     $subject= "=?utf-8?b?".base64_encode($subject)."?=";
  218.     $headers = "MIME-Version: 1.0\r\n";
  219.     $headers.= "From: =?utf-8?b?".base64_encode($from_name)."?= <".$from_a.">\r\n";
  220.     $headers.= "Content-Type: text/plain;charset=utf-8\r\n";
  221.     $headers.= "Reply-To: $reply\r\n";  
  222.     $headers.= "X-Mailer: PHP/" . phpversion();
  223.     $BodyReceiver = mail($to, $subject, $message_body, $headers);
  224. }
  225.  
  226.     if(!$BodyReceiver)
  227.     {
  228.         //If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens)
  229.         $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
  230.         die($output);
  231.     }else{
  232.         $output = json_encode(array('type'=>'message', 'text' => 'Witaj '.$user_name .' '.$user_surname.'. Dziękujemy za wypełnienie formularza.'));
  233.         die($output);
  234.     }
  235.  
  236.     /*
  237.     //proceed with PHP email.
  238.     $headers  = 'MIME-Version: 1.0' . "\r\n";
  239.     $headers .= 'Content-type: text/html; charset=iso-8859-2' . "\r\n";
  240.     $headers = 'From: '.$user_email.'' . "\r\n" .
  241.     'Reply-To: '.$user_email.'' . "\r\n" .
  242.     'X-Mailer: PHP/' . phpversion();
  243.    
  244.     $sender_headers = 'From: '.$to_email.'' . "\r\n" .
  245.     'Reply-To: '.$to_email.'' . "\r\n" .
  246.     'X-Mailer: PHP/' . phpversion();
  247.     $BodyReceiver  = mail('pablobbbb@wp.pl', $subject, $message_body, $headers);
  248.    
  249.     $BodySender = mail($user_email, $sender_subject, $sender_message_body, $sender_headers);
  250.    
  251.     if(!$BodyReceiver)
  252.     {
  253.         //If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens)
  254.         $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
  255.         die($output);
  256.     }else{
  257.         $output = json_encode(array('type'=>'message', 'text' => 'Witaj '.$user_name .' '.$user_surname.'. Dziękujemy za wypełnienie formularza.'));
  258.         die($output);
  259.     }*/
  260. }
  261. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement