Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. <?php
  2.  
  3. namespace A3plus;
  4.  
  5. class Email
  6. {
  7.  
  8.  
  9. // **************************************************** //
  10. // *************** Dokumentation **************** //
  11. // **************************************************** //
  12.  
  13. // Include Email Class :
  14. //require_once ("your/path/email.php");
  15.  
  16. // Work with Namespaces:
  17. //use A3plus\Email as Email;
  18.  
  19. // Initialize new Email:
  20. //$mail = new Email( "Sender E-Mail Address", "Sender Name", "Sender Message", "$_POST["a3SpamProtection"]");
  21.  
  22. // To show Errors use
  23. // $mail->getError
  24.  
  25. // Integrating the following field for spam hedging
  26. // <input type="hidden" name="a3SpamProtection" >
  27.  
  28.  
  29. // **************************************************** //
  30. // *********** Variables / Settings ************* //
  31. // **************************************************** //
  32.  
  33.  
  34. // E-Mail Address of Recipient
  35. private $senderMail;
  36.  
  37. // Name Address of Recipient
  38. private $senderName;
  39.  
  40. // Message Address of Recipient
  41. private $senderMessage;
  42.  
  43. // Field to check out Bots
  44. private $spamField;
  45.  
  46. //Mail of E-Mail Sender
  47. private $recipientMail = "f.breuer@a3plus.de";
  48.  
  49. //Short Mail Subject
  50. private $mailSubject = "Kontaktformular Website";
  51.  
  52. //Spamtimeout in Seconds
  53. private $Spamtimeout = 60;
  54.  
  55. //Error Handling
  56. private $error;
  57.  
  58. //Error Message for Spamfilter
  59. private $errorSpamFilterMessage = "Spamfilter !!!";
  60.  
  61. //Error Message for non Validate Sender Email
  62. private $errorSenderMailMessage = "Sender E-Mail Adresse ist nicht valide";
  63.  
  64. //Error Message for non Validate Sender Recipient
  65. private $errorRecipientMailMessage = "Empfänger E-Mail Adresse ist nicht valide";
  66.  
  67. // Other Settings
  68.  
  69. //Wordwrap after number of Characters
  70. private $characterPerLine = 70;
  71.  
  72.  
  73.  
  74. // **************************************************** //
  75. // ***************** Functions ****************** //
  76. // **************************************************** //
  77.  
  78.  
  79. public function __construct($email, $name, $message, $spamField)
  80. {
  81. $this->senderMail = htmlspecialchars($email);
  82. $this->senderName = htmlspecialchars($name);
  83. $this->senderMessage = wordwrap(htmlspecialchars($message), $this->characterPerLine, "<br />\n");
  84. $this->spamField = htmlspecialchars($spamField);
  85. $this->mailBuilder();
  86. }
  87.  
  88. public function validateEmail($email)
  89. {
  90. if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
  91. return true;
  92. }else{
  93. return false;
  94. }
  95. }
  96.  
  97.  
  98. public function spamFilter()
  99. {
  100. if($this->spamField == "") {
  101. if (!isset($_SESSION['lastSendMail']) || $_SESSION['lastSendMail'] + $this->Spamtimeout <= time()) {
  102. $_SESSION['lastSendMail'] = time();
  103. return true;
  104. } else {
  105. return false;
  106. }
  107. }else{
  108. return false;
  109. }
  110. }
  111.  
  112. public function mailBuilder()
  113. {
  114. if($this->validateEmail($this->senderMail)){
  115.  
  116. if($this->validateEmail($this->recipientMail)){
  117.  
  118. if($this->spamFilter()){
  119. // Vaild Email, Ready to Send
  120. $this->sendMail();
  121. }else{
  122. //Error Spamfilter
  123. $this->setError($this->errorSpamFilterMessage);
  124. }
  125.  
  126. }else{
  127. //Error Recipient Mail is no valid Email
  128. $this->setError($this->errorRecipientMailMessage);
  129. }
  130.  
  131. }else {
  132. //Error Sender Mail is no valid Email
  133. $this->setError($this->errorSenderMailMessage);
  134. }
  135. }
  136.  
  137.  
  138. // Error Handling
  139. public function getError()
  140. {
  141. echo $this->error;
  142. }
  143.  
  144. public function setError($errorMessage)
  145. {
  146. $this->error = $errorMessage;
  147. }
  148.  
  149.  
  150. public function sendMail ()
  151. {
  152.  
  153. $header = 'MIME-Version: 1.0' . "\r\n";
  154. $header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  155. $header .= 'From:' . $this->senderMail . "\r\n";
  156. $header .= 'Reply-To:' . $this->recipientMail . "\r\n";
  157.  
  158. // Add Sender Name to Message
  159. $this->senderMessage = $this->senderName .":" . "<br />\n <br />\n" . $this->senderMessage;
  160.  
  161. mail($this->recipientMail, $this->mailSubject, $this->senderMessage, $header);
  162.  
  163. }
  164. }
  165. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement