I have a subscribe option on my page. All I want is for users to be able to subscribe via email and have their emails save to a .txt
file.
Here is my HTML form code:
<form action="contacts.php" method="post">
E-mail: <input type="text" name="email" placeholder="Subscribe to our page for the latest News & Updates">
<input type="submit" value="Subscribe">
</form>
I just need to know the script to write in the contacts.php
file to save the emails.
I'm using XAMPP as a local server.
Your Form
<form action="contacts.php" method="post">
<input type="text" name="email" placeholder="Subscribe to our page for the latest News & Updates" />
<input type="submit" value="Subscribe" />
</form>
Use this code in your contacts.php
$email = $_POST['email'];
file_put_contents('emails.txt', $email . PHP_EOL , FILE_APPEND | LOCK_EX);