JezK
Edit File: share_email.php
<?php require 'config.php'; require 'auth.php'; require 'mailer.php'; requireLogin(); if ($_SERVER["REQUEST_METHOD"] == "POST") { $note_id = $_POST['note_id']; $email = $_POST['email']; $user_id = $_SESSION['user_id']; // Verify ownership or access? For now, sharing via email implies you have access. // Let's ensure note exists and user has view access at least. $stmt = $pdo->prepare("SELECT title, content FROM notes WHERE id = ?"); $stmt->execute([$note_id]); $note = $stmt->fetch(); if ($note) { // Create a share token if not exists? // Actually, sharing via email usually sends a link or the content. // Let's Check if we should generate a view-only token if none exists, or just send content. // The prompt said "sharing notes... through email (along with shared through link)". // Let's send a nice HTML email with content and link. // Get or create a token for this specific share? // Simplest: Use the public link if public_access is on, OR just send content. // Better: Invite them properly? But this is "Share via Email" separate from "Collaborators". // Let's stick to the prompt's simplicity -> Share content + Link. $// We need the token. $stmtToken = $pdo->prepare("SELECT share_token FROM notes WHERE id = ?"); $stmtToken->execute([$note_id]); $res = $stmtToken->fetch(); $token = $res ? $res['share_token'] : null; $linkHtml = ""; if ($token) { $link = "http://" . $_SERVER['HTTP_HOST'] . "/humara-notes/view_shared.php?token=" . $token; $linkHtml = "<p>View online: <a href='$link'>$link</a></p>"; } $subject = "Note Shared: " . $note['title']; $body = " <h2>" . htmlspecialchars($note['title']) . "</h2> <div style='background:#f9f9f9; padding:10px; border:1px solid #ddd; margin-bottom:10px;'> " . nl2br(htmlspecialchars($note['content'])) . " </div> $linkHtml <p>Shared via Humare Notes</p> "; $result = send_smtp_email($email, $subject, $body); if ($result === true) { header("Location: dashboard.php?msg=Email+sent+successfully"); } else { // Encode error message for display header("Location: dashboard.php?msg=" . urlencode("Email failed: " . $result)); } } else { header("Location: dashboard.php?msg=Error+sending+email"); } } else { header("Location: dashboard.php"); } ?>