freddan88 / simple-php-email-api

Simple PHP API to send emails

Home Page:http://www.leemann.se/fredrik

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple PHP Email API

Post formdata and send emails by using the built in mail function in PHP

Code License: MIT

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

Example code client (axios)


Version using csrf

Functionalities:

  1. Security checks of api key and origin
  2. Will generate and send CSRF-token to client
  3. Validation and sanitization of data from user
  4. Error messages are sent back to client as json

API endpoints

Endpoint Request Method Description
/token POST Generate and send csrf-token
/mail 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

  1. Rename index.csrv.php to index.php
  2. Rename config.example.php to config.php
  3. Configure allowed domains in config.php
  4. Configure valid api key in config.php
  5. Upload all files to your webserver

Generate keys here

Version not using csrf

Functionalities:

  1. Security checks of api key and origin
  2. Validation and sanitization of data from user
  3. Error messages are sent back to client as json

API endpoints

Endpoint Request Method Description
/mail POST Send email and validate token

Installation

Code located in the "server_code" directory

  1. Rename index.key.php to index.php
  2. Rename config.example.php to config.php
  3. Configure allowed domains in config.php
  4. Configure valid api key in config.php
  5. Upload all files to your webserver

Generate keys here

About

Simple PHP API to send emails

http://www.leemann.se/fredrik

License:MIT License


Languages

Language:PHP 46.7%Language:HTML 29.4%Language:JavaScript 23.9%