/userfiles/templates/yomex/mail_sender.php

https://github.com/geekbuntu/Microweber · PHP · 137 lines · 81 code · 39 blank · 17 comment · 6 complexity · 34b6b872f2ac62bfe4c30c0786b981cf MD5 · raw file

  1. <?php /**
  2. * Multibyte safe version of trim()
  3. * Always strips whitespace characters (those equal to \s)
  4. *
  5. * @author Peter Johnson
  6. * @email phpnet@rcpt.at
  7. * @param $string The string to trim
  8. * @param $chars Optional list of chars to remove from the string ( as per trim() )
  9. * @param $chars_array Optional array of preg_quote'd chars to be removed
  10. * @return string
  11. */
  12. function mb_trim( $string, $chars = "", $chars_array = array() )
  13. {
  14. for( $x=0; $x<iconv_strlen( $chars ); $x++ ) $chars_array[] = preg_quote( iconv_substr( $chars, $x, 1 ) );
  15. $encoded_char_list = implode( "|", array_merge( array( "\s","\t","\n","\r", "\0", "\x0B" ), $chars_array ) );
  16. $string = mb_ereg_replace( "^($encoded_char_list)*", "", $string );
  17. $string = mb_ereg_replace( "($encoded_char_list)*$", "", $string );
  18. return $string;
  19. }
  20. //var_dump($_POST) ;
  21. $mails = array();
  22. foreach($_POST as $k => $v){
  23. if(stristr($v, 'mailform_subject')){
  24. $subj = $v ;
  25. $subj = str_ireplace('-', '', $subj ); ;
  26. $subj = str_ireplace('mailform_subject', '', $subj );
  27. $subj = ($subj);
  28. }
  29. if(stristr($v, 'page_id')){
  30. $page_id = $v ;
  31. $page_id = str_ireplace('-', '', $page_id ); ;
  32. $page_id = str_ireplace('page_id', '', $page_id );
  33. $page_id = intval($page_id);
  34. }
  35. $v = mb_trim($v);
  36. $string =$v;
  37. $pattern = '/([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])' .
  38. '(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)/i';
  39. print $subj;
  40. preg_match ($pattern, $string, $matches);
  41. //echo "We extracted " . $matches[0] . " from $string";
  42. //var_dump($matches[0]);
  43. if($matches[0] != false){
  44. $mails[] = $matches[0];
  45. }
  46. $message.=$v . "\r\n";
  47. }
  48. $file123 = 'counters/count_file'.'.txt';
  49. if (file_exists($file123))
  50. {
  51. $fil = fopen($file123, r);
  52. $dat = fread($fil, filesize($file123));
  53. $count = $dat+1;
  54. fclose($fil);
  55. $fil = fopen($file123, w);
  56. fwrite($fil, $dat+1);
  57. }
  58. else
  59. {
  60. $fil = fopen($file123, w);
  61. fwrite($fil, 1);
  62. $count = '1';
  63. fclose($fil);
  64. }
  65. $mails = array_unique($mails);
  66. $subject='[Yomex] ' . $count .' ' . $subj .' ' ;
  67. // var_dump($subject);
  68. $headers.='From: ' . $mails[0] . ' <' . $mails[0] . '>';
  69. $headers .= "\r\n";
  70. $headers .= "MIME-Version: 1.0\r\n";
  71. $headers .= "Content-type: text/plain; charset=utf-8\r\n";
  72. $headers .= "Content-Transfer-Encoding: quoted-printable\r\n";
  73. $sendto = 'yomex@yomexbg.com, boksiora@gmail.com';
  74. $message = str_replace("<br>", "\r\n",$message);
  75. $message = str_replace("<br />", "\r\n",$message);
  76. $sendto = explode(',',$sendto);
  77. foreach($sendto as $to){
  78. $to = trim($to);
  79. mail($to, $subject, $message, $headers);
  80. //UTF8_mail($_REQUEST['email'],$to,$subject,$message,$cc="",$bcc="");
  81. }
  82. //$message.="\r\nMessage:" . $_REQUEST['message'];
  83. $subject='[YomexBG.com] Потвърждение ';
  84. $headers = '';
  85. $headers.='From: ' . 'yomex@yomexbg.com' . ' <' . 'yomex@yomexbg.com' . '>';
  86. $headers .= "\r\n";
  87. $headers .= "MIME-Version: 1.0\r\n";
  88. $headers .= "Content-type: text/html; charset=utf-8\r\n";
  89. $headers .= "Content-Transfer-Encoding: quoted-printable\r\n";
  90. $sendto = 'yomex@yomexbg.com';
  91. $message = file_get_contents('auto_responders/offer.html');
  92. $sendto = explode(',',$sendto);
  93. foreach($sendto as $to){
  94. $to = trim($to);
  95. mail($mails[0], $subject, $message, $headers);
  96. //UTF8_mail($_REQUEST['email'],$to,$subject,$message,$cc="",$bcc="");
  97. }
  98. ?>