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
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
- How to Sendmail in PHP - Dibya Sahoo
- PHP.NET: .INI Configuration for emails
- Send email from Localhost - phpBasics
- Download sendmail for Windows
Installation
Code located in the "api" directory
- Clone or download this repository
- Rename config_example.ini to ./api/config.ini
- Configure "allowed_origins" in ./api/config.ini
- Configure valid "api_key" in ./api/config.ini
- 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:
- Security checks with api key and remote origin
- Validation and sanitization of data sent from user
- Error and success messages are sent back to client as json
API endpoints
Endpoint | Request Method | Description |
---|---|---|
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