Guest User

Untitled

a guest
Feb 14th, 2019
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. <?php
  2.  
  3. class IwMail {
  4. protected $subject;
  5. protected $headers;
  6. protected $content;
  7. protected $to;
  8. protected $from;
  9. public $mail;
  10.  
  11. public function __construct($subject, $to, $content="", $from="Admin <admin@gmail.com>") {
  12. $this->subject = $subject;
  13. $this->to = $to;
  14. $this->content = $content;
  15. $this->from = $from;
  16. $this->headers = "MIME-Version: 1.0\n"
  17. . "Content-type:text/html;charset=iso-8859-1\n"
  18. . "From: Admin <" . $this->from . ">\n";
  19.  
  20. $mail = new PHPMailer(); // create a new object
  21. $mail->IsHTML(true);
  22. $this->mail = $mail;
  23. }
  24.  
  25. public function mail() {
  26. $ret = mail($this->to, $this->subject, $this->content, $this->headers);
  27. echo "status($ret): email sent to " . $this->to;
  28. }
  29.  
  30. public function gmail_setup($username="", $password="") {
  31. $mail = $this->mail;
  32. // TODO: if username and password is empty, read from config file
  33. $mail->Username = $username;
  34. $mail->Password = $password;
  35.  
  36. $mail->IsSMTP(); // enable SMTP
  37. $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
  38. $mail->SMTPAuth = true; // authentication enabled
  39. $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
  40. $mail->Host = "smtp.gmail.com";
  41. $mail->Port = 465; // or 587
  42. }
  43.  
  44. public function mail_google($attachment=null, $username="", $password="") {
  45. $mail = $this->mail;
  46. $this->gmail_setup($username, $password);
  47. $mail->SetFrom($this->from);
  48. $mail->Subject = $this->subject;
  49. $mail->Body = $this->content;
  50. $mail->AddAddress($this->to);
  51.  
  52. if(!$mail->Send()) {
  53. echo "Mailer Error: " . $mail->ErrorInfo;
  54. } else {
  55. if(!is_null($attachment)) {
  56. unlink($attachment);
  57. }
  58. echo "Message has been sent";
  59. }
  60. }
  61. }
Add Comment
Please, Sign In to add comment