matthiasmullie / post-to-email
Post to email
Fund package maintenance!
matthiasmullie
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 3
Forks: 1
Open Issues: 0
Type:project
Requires
- php: ^8.0
- symfony/mailer: ^6.0
README
Contact forms for static websites
Here's a solution for those with static websites wanting a contact form, but find themselves in a situation where they can't provide a script to support it (e.g. your platform doesn't allow you to host such script, or you simply don't know how)
This project provides a simple endpoint to submit your forms to, turning those form fields into an email to you.
All you need is:
- An SMTP server, for outgoing mails (e.g. Gmail or Outlook)
- A platform that supports deploying Docker containers (e.g. render)
- Your static website with a form, hosted anywhere
For your convenience, this project is wrapped into a Docker container that can easily be deployed on any Paas - some of which will allow you to deploy this for free. Read on!
Instructions
1. Deploy the container
Run the matthiasmullie/post-to-email
Docker container in whatever configuration makes sense.
Below are detailed instructions to run this in a couple of different ways - pick whichever makes most sense for your use-case:
- Deploy it on a PaaS
- Run it with Docker
- Run it with Docker Compose
- Clone the repo and build it yourself
2. Build a simple form & submit it
Submit a POST request (with remaining variables - see configuration)
Check out this simple example to build a form that submits forms to the service we deployed in the first step.
And here's information about mitigating spam in case you were worried about that!
3. Receive email
You've got this! We're done here.
Configuration
Email configuration can be set globally on the server hosting this script (via environment variables), or per request on the client calling this (via POST or GET params)
If set, environment variables always get precedence over POST, which gets precedence over GET params.
This can be useful to lock down certain settings (e.g. RECIPIENT
or DSN
) within your hosting environment to prevent abuse.
Available params:
ALLOW_ORIGIN
[ENV only]: allowed CORS domainDSN
[ENV only]: DSN string for a transport (e.g. SMTP) to send emails withSENDER
: sender email addressRECIPIENT
: recipient email addressREPLY_TO
(optional, defaults toSENDER
): reply-to email addressSUBJECT
(optional, defaults to "Form to email"): email subjectREDIRECT
(optional, defaults to referrer): location to redirect back to after handing submission, or explicitly blank for no redirectHONEYPOT
(optional, defaults to none): Name of a form field to use as honeypot to filter out unwanted (spam) submissions