Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Class name : Mailer
- Description : Class for handling sending an email
- Author : Achmad Solichin (http://achmatim.net)
- */
- class Mailer {
- // declare private attributes
- private $to = array();
- // Class constructor
- public function __construct($to) {
- $this->to = $to;
- }
- // accessor functions
- public function __set($name, $value) {
- $this->$name = $value;
- }
- public function __get($name) {
- return $this->$name;
- }
- public function send_mail() {
- if (!empty($this->to) && count($this->to) > 0) {
- $destination = implode (',',$this->to);
- }
- require 'PHPMailerAutoload.php';
- $mail = new PHPMailer;
- $mail->isSMTP();
- $mail->SMTPAuth = true;
- $mail->Host = 'smtp.gmail.com';
- $mail->Username = 'user@example.com'; // SMTP username
- $mail->Password = 'secret'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
- $mail->setFrom('marketing@tegar27.com');
- $mail->addAddress('$destination'); // Add a recipient
- $mail->Port = 587; // TCP port to connect to
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = 'Here is the subject';
- $mail->Body = 'This is the HTML message body <b>in bold!</b>';
- $mail = 'MIME-Version: 1.0' . "\r\n";
- $mail = 'Content-type: text/ html; charset=iso-8859-1' . "\r\n";
- if (!empty($this->to)) {
- $headers .= 'From: '. $this->from . "\r\n";
- }
- if(!$mail->send()) {
- if(mail($destination, $mail->Subject, $this->message, $headers)) {
- return true;
- } else {
- $mail->ErrorInfo = 'Server cannot sending mail.';
- return false;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement