/// real_escape_string(trim($_POST['name'])); $email = $conn->real_escape_string(trim($_POST['email'])); $message_content = $conn->real_escape_string(trim($_POST['message'])); // Validation $isValid = true; if (empty($name)) { $nameErr = "Name is required"; $isValid = false; } elseif (!preg_match("/^[a-zA-Z-' ]*$/", $name)) { $nameErr = "Only letters and white space allowed"; $isValid = false; } if (empty($email)) { $emailErr = "Email is required"; $isValid = false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; $isValid = false; } if (empty($message_content)) { $messageErr = "Message is required"; $isValid = false; } // If valid, insert into database if ($isValid) { // Generate a unique verification token $verification_token = bin2hex(random_bytes(16)); $sql = "INSERT INTO contacts (name, email, message, verification_token) VALUES ('$name', '$email', '$message_content', '$verification_token')"; if ($conn->query($sql) === TRUE) { // Send verification email $verification_url = $baseUrl . "verify.php?token=" . $verification_token; $mail = new PHPMailer(true); try { // SMTP Configuration $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'linhtut123451@gmail.com'; // Replace with your email $mail->Password = 'mrzq opxl vfcj njkn'; // Replace with your email password $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // $mail->SMTPSecure = PHPMailer::PHPMailer::ENCRYPTION_SMTPS; $mail->Port = 587; // $mail->Port = 465; // Recipients $mail->setFrom('linhtut123451@gmail.com', 'Myanmar.ca'); $mail->addAddress($email); // Content $mail->isHTML(true); $mail->Subject = 'Account Verification'; $mail->Body = "Please verify your account by clicking the following link: Verify Account"; $mail->send(); $message = "Account created successfully! A verification link has been sent to your Email."; } catch (Exception $e) { $message = "Error sending email: " . $mail->ErrorInfo; } } else { $message = "Error: " . $conn->error; } } } ?>

Create Account

Go Back