Simple PHP Email API
Post formdata and send emails by using the built in mail function in PHP
There are two versions in this repository
My Links: | |
---|---|
WebPage: | leemann.se/fredrik |
YouTube: | youtube.com/FreLee54 |
GitHub: | github.com/freddan88 |
Tested with
OBS! Only tested with web servers like Apache and PHP:s built in
In order to send emails php.ini needs to be configured to use a mail-server or sendmail-program
Links
- How to Sendmail in PHP - Dibya Sahoo
- PHP.NET: .INI Configuration for emails
- Send email from Localhost - phpBasics
- Download sendmail for Windows
Example code client (axios)
Version using csrf
Functionalities:
- Security checks of api key and origin
- Will generate and send CSRF-token to client
- Validation and sanitization of data from user
- Error messages are sent back to client as json
API endpoints
Endpoint | Request Method | Description |
---|---|---|
/token | POST | Generate and send csrf-token |
POST | Send email and validate token | |
/end | POST | End current php session |
Don't know if /end is needed but added it anyway
Installation
Code located in the "server_code" directory
- Rename index.csrv.php to index.php
- Rename config.example.php to config.php
- Configure allowed domains in config.php
- Configure valid api key in config.php
- Upload all files to your webserver
Generate keys here
Version not using csrf
Functionalities:
- Security checks of api key and origin
- Validation and sanitization of data from user
- Error messages are sent back to client as json
API endpoints
Endpoint | Request Method | Description |
---|---|---|
POST | Send email and validate token |
Installation
Code located in the "server_code" directory
- Rename index.key.php to index.php
- Rename config.example.php to config.php
- Configure allowed domains in config.php
- Configure valid api key in config.php
- Upload all files to your webserver