This project runs a vanilla version of Bootstrap by way of CDN.
MyPHPMailer is used to send the e-mails.
Basic Structure
This project has three main forms:
Subscribe Form: The click event of the submit button is overridden in Subscribe.js which gets
the form data and executes a fetch to Subscribe.php. The php returns an error if the e-mail is invalid.
Else it tries to read subscribers.txt by way of AccessSubscribers.php, which may throw a variety of exceptions. subscribers.txt is an
associative array with the e-mails as indices. If already subscribed it throws an exception,
else it adds the e-mail and associated name (which can be empty) and gives a confirmation.
UnSubscribe Form: The click event of the submit button is overridden in UnSubscribe.js which gets
the form data and executes a fetch to UnSubscribe.php. Exceptions and confirmations are generated.
Send Mail Form: The click event of the submit button is overridden in SendTheMail.js which gets
the form data and executes a fetch to SendTheMail.php. The sending of any individual e-mail is done
by way of MyPHPMailer.php and can take several seconds. A fetch is used to start the processing of the e-mails.
Each e-mail will return a response. Another fetch needs to be done until the response contains ERROR or ALLDONE.
Notes
This project initiates the debugging by calling index.php which invokes ContactForm.html
so that both JS and PHP can be debugged. See the URL of the debug configuration for details.
All of the forms use the results-field to display any messages, by way of SetResultsAndSpinner.js.
Only the Send Mail button supports the spinner, which only shows up while the e-mails are being sent.
MyPHPMailer gets its credentials from .env by way of MyDotEnv.php.
It is insecure to store .env in a non-local repository.
The e-mail that is sent has an unsubscribe button that will invoke the website with the e-mail
already in the unsubscribe field. This is handled by CheckForQueryString.js
The body of the e-mail was taken from an example downloaded from BeeFree. It is a complicated
structure of nested tables to do just a simple e-mail. This is because all e-mail tools support
tables, but not all support divs. The HTML is in heredoc format in EmailBody.php
Variables can be inserted.