Skip to content

Verify Email when registering #12

@tutester166

Description

@tutester166

Registering without verification is not safe.
We can try this:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';

$mail = new PHPMailer(true);
try {
    // 服务器配置
    $mail->isSMTP();
    $mail->Host       = 'smtp.qq.com';              // QQ邮箱 SMTP 服务器
    $mail->SMTPAuth   = true;
    $mail->Username   = '你的QQ号@qq.com';           // 发件邮箱
    $mail->Password   = '你的16位授权码';             // ⚠️ 不是登录密码,是授权码
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // 启用 SSL
    $mail->Port       = 465;

    // 收件人
    $mail->setFrom('你的QQ号@qq.com', '社区管理员');
    $mail->addAddress($userEmail);                   // 用户注册的邮箱

    // 内容
    $mail->isHTML(true);
    $mail->Subject = '请验证您的邮箱';
    $mail->Body    = "您的验证码是:<b>$code</b>,10分钟内有效。";

    $mail->send();
    echo '发送成功';
} catch (Exception $e) {
    echo "发送失败: {$mail->ErrorInfo}";
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions