PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/classes/email.php

https://github.com/MilkZoft/zan
PHP | 90 lines | 81 code | 9 blank | 0 comment | 9 complexity | b344ceb94c26d44fdefd6a2229dba734 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. if (!defined("ACCESS")) {
  3. die("Error: You don't have permission to access here...");
  4. }
  5. class ZP_Email extends ZP_Load
  6. {
  7. public $email;
  8. public $fromEmail;
  9. public $fromName;
  10. public $message;
  11. public $messageText;
  12. public $subject;
  13. public $library = "PHPMailer";
  14. public function send()
  15. {
  16. if (strtolower($this->library) === "elastic") {
  17. $response = "";
  18. $data = "username=". urlencode(ELASTIC_USERNAME);
  19. $data .= "&api_key=". urlencode(ELASTIC_API_KEY);
  20. $data .= "&from=". urlencode($this->fromEmail);
  21. $data .= "&from_name=". urlencode($this->fromName);
  22. $data .= "&to=". urlencode($this->email);
  23. $data .= "&subject=". urlencode($this->subject);
  24. if ($this->message) {
  25. $data .= "&body_html=". urlencode($this->message);
  26. }
  27. $header = "POST /mailer/send HTTP/1.0\r\n";
  28. $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  29. $header .= "Content-Length: " . strlen($data) . "\r\n\r\n";
  30. $fp = fsockopen('ssl://api.elasticemail.com', 443, $errno, $errstr, 30);
  31. if(!$fp) {
  32. return "ERROR. Could not open connection";
  33. } else {
  34. fputs ($fp, $header . $data);
  35. while (!feof($fp)) {
  36. $response .= fread ($fp, 1024);
  37. }
  38. fclose($fp);
  39. }
  40. return true;
  41. } elseif (strtolower($this->library) === "phpmailer") {
  42. $this->config("email");
  43. $this->PHPMailer = $this->library("phpmailer", "PHPMailer");
  44. $this->PHPMailer->isHTML(true);
  45. $this->PHPMailer->isSMTP();
  46. $this->PHPMailer->addAddress($this->email);
  47. $this->PHPMailer->FromName = $this->fromName;
  48. $this->PHPMailer->Subject = $this->subject;
  49. $this->PHPMailer->Body = $this->message;
  50. $this->PHPMailer->Host = GMAIL_SSL;
  51. $this->PHPMailer->Port = GMAIL_PORT;
  52. $this->PHPMailer->Username = GMAIL_USER;
  53. $this->PHPMailer->Password = GMAIL_PWD;
  54. $this->PHPMailer->SMTPAuth = true;
  55. if (!$this->PHPMailer->Send()) {
  56. return false;
  57. } else {
  58. return true;
  59. }
  60. } else {
  61. $headers = "MIME-Version: 1.0\r\n";
  62. $headers .= "Content-type: text/html; charset=utf-8\r\n";
  63. $headers .= "From: ". $this->fromName ." <". $this->fromEmail .">\r\n";
  64. if (!@mail($this->email, $this->subject, $this->message, $headers)) {
  65. return false;
  66. } else {
  67. return true;
  68. }
  69. }
  70. }
  71. public function setLibrary($library = "native")
  72. {
  73. $this->library = $library;
  74. }
  75. }