What is the purpose of using an opt-in script without a database in PHP?
When using an opt-in script without a database in PHP, the purpose is to collect user email addresses for a mailing list without the need for a database to store the information. This can be useful for smaller websites or projects that do not require a full database setup.
<?php
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["email"])) {
$email = $_POST["email"];
// Save the email address to a text file
$file = "emails.txt";
file_put_contents($file, $email . PHP_EOL, FILE_APPEND);
echo "Thank you for subscribing!";
}
?>
<form method="post">
<input type="email" name="email" placeholder="Enter your email" required>
<button type="submit">Subscribe</button>
</form>