|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Uses the PHPmailer library to send emails through SMTP more efficiently. |
| 5 | + * v6.13 is using. |
| 6 | + * |
| 7 | + * @url https://github.com/PHPMailer/PHPMailer/ |
| 8 | + */ |
| 9 | + |
| 10 | +use PHPMailer\PHPMailer\PHPMailer; |
| 11 | +use PHPMailer\PHPMailer\Exception; |
| 12 | + |
| 13 | +require_once 'libs/vendor/phpmailer/phpmailer/src/Exception.php'; |
| 14 | +require_once 'libs/vendor/phpmailer/phpmailer/src/PHPMailer.php'; |
| 15 | +require_once 'libs/vendor/phpmailer/phpmailer/src/SMTP.php'; |
| 16 | +require_once 'includes/requires.php'; |
| 17 | + |
| 18 | + |
| 19 | +abstract class SMTP |
| 20 | +{ |
| 21 | + /** |
| 22 | + * The Srevant class. |
| 23 | + * Tester.su SMTP server settings. |
| 24 | + * |
| 25 | + * @url https://ru.wikipedia.org/wiki/%D0%A8%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD_%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F |
| 26 | + */ |
| 27 | + |
| 28 | + /** |
| 29 | + * @var object |
| 30 | + */ |
| 31 | + private static $mail; |
| 32 | + |
| 33 | + /** |
| 34 | + * Setting to send mails. |
| 35 | + * |
| 36 | + * @return void |
| 37 | + */ |
| 38 | + private static function getSMTP() |
| 39 | + { |
| 40 | + static::$mail = new PHPMailer; |
| 41 | + static::$mail->CharSet = 'UTF-8'; |
| 42 | + |
| 43 | + static::$mail->isSMTP(); |
| 44 | + static::$mail->SMTPAuth = true; |
| 45 | + static::$mail->SMTPDebug = 0; |
| 46 | + |
| 47 | + static::$mail->Host = 'ssl://smtp.mail.ru'; |
| 48 | + static::$mail->Port = 465; |
| 49 | + static:: $mail-> Username = '[email protected]'; |
| 50 | + static::$mail->Password = 'ka8Jq1_$as'; |
| 51 | + |
| 52 | + static:: $mail-> setFrom( '[email protected]', 'tester.su' ); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Sends mail with activation code to complete the sign up process. |
| 57 | + * |
| 58 | + * @return void |
| 59 | + */ |
| 60 | + public static function sendActivation() |
| 61 | + { |
| 62 | + self::getSMTP(); |
| 63 | + |
| 64 | + $body = '<p><b>Welcome to us!<br>This your activation code: '.$_SESSION['activation'].'</b></p>'; |
| 65 | + |
| 66 | + static::$mail->addAddress( $_SESSION['email'], 'Dear Customer' ); |
| 67 | + static::$mail->Subject = 'Sign up Completion'; |
| 68 | + static::$mail->msgHTML( $body ); |
| 69 | + |
| 70 | + static::$mail->send(); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Sends mail with users login and a new password for account recovery procedure. |
| 75 | + * |
| 76 | + * @param string $login |
| 77 | + * |
| 78 | + * @param string $password |
| 79 | + * |
| 80 | + * @return void |
| 81 | + */ |
| 82 | + public static function sendRecovery( $login, $password ) |
| 83 | + { |
| 84 | + self::getSMTP(); |
| 85 | + |
| 86 | + $body = "<p><b>We received information that you lost your account<br>This your login: ".$login. |
| 87 | + ";<br>And your new password: ".$password.".<br>If you have not left an application for |
| 88 | + account recovery just ignore this message.<br>But if you are the owner of the account, the attacker may have left this request. |
| 89 | + Then we recommend that you change the email address in your account settings</b></p>"; |
| 90 | + |
| 91 | + static::$mail->addAddress( $_SESSION['email'], 'Dear Customer' ); |
| 92 | + static::$mail->Subject = 'Account recovery'; |
| 93 | + static::$mail->msgHTML( $body ); |
| 94 | + |
| 95 | + static::$mail->send(); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Sends mail with users login and a new password for account recovery procedure. |
| 100 | + * |
| 101 | + * @param string $login |
| 102 | + * |
| 103 | + * @param string $password |
| 104 | + * |
| 105 | + * @return void |
| 106 | + */ |
| 107 | + public static function sendActivationLink( $link ) |
| 108 | + { |
| 109 | + self::getSMTP(); |
| 110 | + |
| 111 | + $body = "<p><b>We received information that you want to change your email address.<br>If you have not left an application for |
| 112 | + change email address just ignore this message.<br>Follow this link to confirm you are owner of this account:<br>" . $link . "</b></p>"; |
| 113 | + |
| 114 | + static::$mail->addAddress( $_SESSION['email'], 'Dear Customer' ); |
| 115 | + static::$mail->Subject = 'Email change procedure'; |
| 116 | + static::$mail->msgHTML( $body ); |
| 117 | + |
| 118 | + static::$mail->send(); |
| 119 | + } |
| 120 | +} |
0 commit comments