Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.88 KB | None | 0 0
  1. <?php
  2.  
  3. abstract class MailTtt {
  4.  
  5.     protected $config = array();
  6.     protected $body;
  7.     protected $subject;
  8.     protected $email;
  9.     protected $title;
  10.  
  11.     function __construct($email, $title, $subject, $body) {
  12.         if (self::emailVaidator($email))
  13.             $this->email = $email;
  14.         else
  15.             throw new Exception("неверный адрес ящика");
  16.         $this->body = $body;
  17.         $this->title = $title;
  18.         $this->subject = $subject;
  19.         $this->setMailData();
  20.     }
  21.  
  22.     private function setMailData() {
  23.         $mailData=  getMailConfig();
  24.         foreach ($mailData as $key => $value)
  25.             $this->config[$key] = $value;
  26.     }
  27.  
  28.     public function sendConfirmationMail() {
  29.         require_once('phpmailer/class.phpmailer.php');
  30.         define('ROOT_PATH2', dirname(dirname(__FILE__)) . "/");
  31.         $mail = new PHPMailer();  // create a new object
  32.         $mail->IsSMTP(); // enable SMTP
  33.         $mail->CharSet = 'cp-1251';
  34.         $mail->SMTPDebug = 1;  // debugging: 1 = errors and messages, 2 = messages only
  35.         $mail->SMTPAuth = $this->config['auth'];  // authentication enabled
  36.         $mail->SMTPSecure = $this->config['secure']; // secure transfer enabled REQUIRED for Gmail
  37.         $mail->Host = $this->config['host'];
  38.         $mail->Port = $this->config['port'];
  39.         $mail->Username = $this->config['companyEmail'];
  40.         $mail->Password = $this->config['companyPassword'];
  41.         $mail->setFrom($this->config['companyEmail'], $this->title);
  42.         $mail->Subject = $this->subject;
  43.         $mail->Body = $this->body;
  44. //$mail->AddAttachment(ROOT_PATH."/xml/torrents.xml"); // attachment
  45.         $mail->addAddress($this->email);
  46.         $mail->Send();
  47.         unset($mail);
  48.         return true;
  49.     }
  50.  
  51.     static function emailVaidator($email, $check = 0) {
  52.  
  53.         if (function_exists("filter_var")) {
  54.             $s = filter_var($email, FILTER_VALIDATE_EMAIL);
  55.             if (mb_strlen($s) > 0)
  56.                 $check = 1;
  57.         } else {
  58.             $p = '/^[a-z0-9!#$%&*+-=?^_`{|}~]+(\.[a-z0-9!#$%&*+-=?^_`{|}~]+)*';
  59.             $p.= '@([-a-z0-9]+\.)+([a-z]{2,3}';
  60.             $p.= '|info|arpa|aero|coop|name|museum|mobi)$/ix';
  61.             $s = (preg_match($p, $email));
  62.             if (mb_strlen($s) > 0)
  63.                 $check = 1;
  64.         }
  65.         if ($check == 1)
  66.             return true;
  67.         else
  68.             return false;
  69.         /*         * ******************* */
  70.         /*  $check=0;
  71.           if ($check == 1) {
  72.           list($prefix, $domain) = split("@", $s);
  73.           if (function_exists("getmxrr") && getmxrr($domain, $mxhosts)) {
  74.           return true;
  75.           } elseif (@fsockopen($domain, 25, $errno, $errstr, 5)) {
  76.           return true;
  77.           } else {
  78.           return false;
  79.           }
  80.           }
  81.           else
  82.           return false; */
  83.     }
  84.  
  85. }
  86.  
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement