Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. <?php
  2. include('SMTPClass.php');
  3.  
  4. $use_smtp = '0';
  5. $emailto = 'csillig.beatrice@gmail.com';
  6.  
  7. // retrieve from parameters
  8. $emailfrom = isset($_POST["email"]) ? $_POST["email"] : "";
  9. $nocomment = isset($_POST["nocomment"]) ? $_POST["nocomment"] : "";
  10. $subject = 'Email from Kubb';
  11. $message = '';
  12. $response = '';
  13. $response_fail = 'There was an error verifying your details.';
  14.  
  15. // Honeypot captcha
  16. if($nocomment == '') {
  17.  
  18. $params = $_POST;
  19. foreach ( $params as $key=>$value ){
  20.  
  21. if(!($key == 'ip' || $key == 'emailsubject' || $key == 'url' || $key == 'emailto' || $key == 'nocomment' || $key == 'v_error' || $key == 'v_email')){
  22.  
  23. $key = ucwords(str_replace("-", " ", $key));
  24.  
  25. if ( gettype( $value ) == "array" ){
  26. $message .= "$key: \n";
  27. foreach ( $value as $two_dim_value )
  28. $message .= "...$two_dim_value<br>";
  29. }else {
  30. $message .= $value != '' ? "$key: $value\n" : '';
  31. }
  32. }
  33. }
  34.  
  35. $response = sendEmail($subject, $message, $emailto, $emailfrom);
  36.  
  37. } else {
  38.  
  39. $response = $response_fail;
  40.  
  41. }
  42.  
  43. echo $response;
  44.  
  45. // Run server-side validation
  46. function sendEmail($subject, $content, $emailto, $emailfrom) {
  47.  
  48. $from = $emailfrom;
  49. $response_sent = 'Thank you. Your messsage has been received.';
  50. $response_error = 'Error. Please try again.';
  51. $subject = filter($subject);
  52. $url = "Origin Page: ".$_SERVER['HTTP_REFERER'];
  53. $ip = "IP Address: ".$_SERVER["REMOTE_ADDR"];
  54.  
  55. $message = $content."\n$ip\r\n$url";
  56.  
  57. // Validate return email & inform admin
  58. $emailto = filter($emailto);
  59.  
  60. // Setup final message
  61. $body = wordwrap($message);
  62.  
  63.  
  64. if($use_smtp == '1'){
  65.  
  66. $SmtpServer = 'SMTP SERVER';
  67. $SmtpPort = 'SMTP PORT';
  68. $SmtpUser = 'SMTP USER';
  69. $SmtpPass = 'SMTP PASSWORD';
  70.  
  71.  
  72. $to = $emailto;
  73. $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
  74. $SMTPChat = $SMTPMail->SendMail();
  75. $response = $SMTPChat ? $response_sent : $response_error;
  76.  
  77. } else {
  78.  
  79. // Create header
  80. $headers = "From: $from\r\n";
  81. $headers .= "MIME-Version: 1.0\r\n";
  82. $headers .= "Content-type: text/plain; charset=utf-8\r\n";
  83. $headers .= "Content-Transfer-Encoding: quoted-printable\r\n";
  84.  
  85. // Send email
  86. $mail_sent = @mail($emailto, $subject, $body, $headers);
  87. $response = $mail_sent ? $response_sent : $response_error;
  88.  
  89. }
  90. return $response;
  91. }
  92.  
  93. // Remove any un-safe values to prevent email injection
  94. function filter($value) {
  95. $pattern = array("/\n/", "/\r/", "/content-type:/i", "/to:/i", "/from:/i", "/cc:/i");
  96. $value = preg_replace($pattern, "", $value);
  97. return $value;
  98. }
  99.  
  100. exit;
  101.  
  102. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement