/simple-php-oop-email-api

Enhancements of previous php email-api - fredrik.leemann.se

Primary LanguagePHPMIT LicenseMIT

simple-php-oop-email-api

Enhancements of previous PHP email-api

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

Code License: MIT

My Links:
WebPage: leemann.se/fredrik
YouTube: youtube.com/FreLee54
LinkedIn: linkedin.com/fredrik-leemann
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

Installation

Code located in the "api" directory

  1. Clone or download this repository
  2. Rename config_example.ini to ./api/config.ini
  3. Configure "allowed_origins" in ./api/config.ini
  4. Configure valid "api_key" in ./api/config.ini
  5. Upload the api-folder to your webserver
Command to clone this repository:
git clone https://github.com/freddan88/simple-php-oop-email-api.git

Generate keys here

Functionalities:

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

API endpoints

Endpoint Request Method Description
/email POST Send email

Multipart form-fields (Post)

Field Name Field Value Required
apikey Random string Yes
emailTo Email to send to Yes
senderEmail Email to send from Yes
senderName Name of the sender No
emailSubject Subject of the email Yes
emailMessage Message of the email Yes

Example frontend-code

Post formData using javascript from bootstrap-form