Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <?php
  2. /*
  3. Class name : Mailer
  4. Description : Class for handling sending an email
  5. Author : Achmad Solichin (http://achmatim.net)
  6. */
  7.  
  8. class Mailer {
  9. // declare private attributes
  10. private $to = array();
  11. // Class constructor
  12. public function __construct($to) {
  13. $this->to = $to;
  14. }
  15. // accessor functions
  16. public function __set($name, $value) {
  17. $this->$name = $value;
  18. }
  19. public function __get($name) {
  20. return $this->$name;
  21. }
  22.  
  23. public function send_mail() {
  24. if (!empty($this->to) && count($this->to) > 0) {
  25. $destination = implode (',',$this->to);
  26. }
  27. require 'PHPMailerAutoload.php';
  28.  
  29. $mail = new PHPMailer;
  30. $mail->isSMTP();
  31. $mail->SMTPAuth = true;
  32. $mail->Host = 'smtp.gmail.com';
  33. $mail->Username = 'user@example.com'; // SMTP username
  34. $mail->Password = 'secret'; // SMTP password
  35. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  36. $mail->setFrom('marketing@tegar27.com');
  37. $mail->addAddress('$destination'); // Add a recipient
  38. $mail->Port = 587; // TCP port to connect to
  39. $mail->isHTML(true); // Set email format to HTML
  40. $mail->Subject = 'Here is the subject';
  41. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  42. $mail = 'MIME-Version: 1.0' . "\r\n";
  43. $mail = 'Content-type: text/ html; charset=iso-8859-1' . "\r\n";
  44.  
  45. if (!empty($this->to)) {
  46. $headers .= 'From: '. $this->from . "\r\n";
  47. }
  48. if(!$mail->send()) {
  49. if(mail($destination, $mail->Subject, $this->message, $headers)) {
  50. return true;
  51. } else {
  52. $mail->ErrorInfo = 'Server cannot sending mail.';
  53. return false;
  54. }
  55. }
  56. }
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement