Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class IwMail {
- protected $subject;
- protected $headers;
- protected $content;
- protected $to;
- protected $from;
- public $mail;
- public function __construct($subject, $to, $content="", $from="Admin <admin@gmail.com>") {
- $this->subject = $subject;
- $this->to = $to;
- $this->content = $content;
- $this->from = $from;
- $this->headers = "MIME-Version: 1.0\n"
- . "Content-type:text/html;charset=iso-8859-1\n"
- . "From: Admin <" . $this->from . ">\n";
- $mail = new PHPMailer(); // create a new object
- $mail->IsHTML(true);
- $this->mail = $mail;
- }
- public function mail() {
- $ret = mail($this->to, $this->subject, $this->content, $this->headers);
- echo "status($ret): email sent to " . $this->to;
- }
- public function gmail_setup($username="", $password="") {
- $mail = $this->mail;
- // TODO: if username and password is empty, read from config file
- $mail->Username = $username;
- $mail->Password = $password;
- $mail->IsSMTP(); // enable SMTP
- $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
- $mail->SMTPAuth = true; // authentication enabled
- $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
- $mail->Host = "smtp.gmail.com";
- $mail->Port = 465; // or 587
- }
- public function mail_google($attachment=null, $username="", $password="") {
- $mail = $this->mail;
- $this->gmail_setup($username, $password);
- $mail->SetFrom($this->from);
- $mail->Subject = $this->subject;
- $mail->Body = $this->content;
- $mail->AddAddress($this->to);
- if(!$mail->Send()) {
- echo "Mailer Error: " . $mail->ErrorInfo;
- } else {
- if(!is_null($attachment)) {
- unlink($attachment);
- }
- echo "Message has been sent";
- }
- }
- }
Add Comment
Please, Sign In to add comment