Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- abstract class MailTtt {
- protected $config = array();
- protected $body;
- protected $subject;
- protected $email;
- protected $title;
- function __construct($email, $title, $subject, $body) {
- if (self::emailVaidator($email))
- $this->email = $email;
- else
- throw new Exception("неверный адрес ящика");
- $this->body = $body;
- $this->title = $title;
- $this->subject = $subject;
- $this->setMailData();
- }
- private function setMailData() {
- $mailData= getMailConfig();
- foreach ($mailData as $key => $value)
- $this->config[$key] = $value;
- }
- public function sendConfirmationMail() {
- require_once('phpmailer/class.phpmailer.php');
- define('ROOT_PATH2', dirname(dirname(__FILE__)) . "/");
- $mail = new PHPMailer(); // create a new object
- $mail->IsSMTP(); // enable SMTP
- $mail->CharSet = 'cp-1251';
- $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
- $mail->SMTPAuth = $this->config['auth']; // authentication enabled
- $mail->SMTPSecure = $this->config['secure']; // secure transfer enabled REQUIRED for Gmail
- $mail->Host = $this->config['host'];
- $mail->Port = $this->config['port'];
- $mail->Username = $this->config['companyEmail'];
- $mail->Password = $this->config['companyPassword'];
- $mail->setFrom($this->config['companyEmail'], $this->title);
- $mail->Subject = $this->subject;
- $mail->Body = $this->body;
- //$mail->AddAttachment(ROOT_PATH."/xml/torrents.xml"); // attachment
- $mail->addAddress($this->email);
- $mail->Send();
- unset($mail);
- return true;
- }
- static function emailVaidator($email, $check = 0) {
- if (function_exists("filter_var")) {
- $s = filter_var($email, FILTER_VALIDATE_EMAIL);
- if (mb_strlen($s) > 0)
- $check = 1;
- } else {
- $p = '/^[a-z0-9!#$%&*+-=?^_`{|}~]+(\.[a-z0-9!#$%&*+-=?^_`{|}~]+)*';
- $p.= '@([-a-z0-9]+\.)+([a-z]{2,3}';
- $p.= '|info|arpa|aero|coop|name|museum|mobi)$/ix';
- $s = (preg_match($p, $email));
- if (mb_strlen($s) > 0)
- $check = 1;
- }
- if ($check == 1)
- return true;
- else
- return false;
- /* * ******************* */
- /* $check=0;
- if ($check == 1) {
- list($prefix, $domain) = split("@", $s);
- if (function_exists("getmxrr") && getmxrr($domain, $mxhosts)) {
- return true;
- } elseif (@fsockopen($domain, 25, $errno, $errstr, 5)) {
- return true;
- } else {
- return false;
- }
- }
- else
- return false; */
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement