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 |
| LinkedIn: | linkedin.com/fredrik-leemann |
| GitHub: | github.com/freddan88 |
In order to send emails php.ini needs to be configured to use a mail-server or sendmail-program
- How to Sendmail in PHP - Dibya Sahoo
- PHP.NET: .INI Configuration for emails
- Send email from Localhost - phpBasics
- Download sendmail for Windows
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
git clone https://github.com/freddan88/simple-php-oop-email-api.git- 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
| Endpoint | Request Method | Description |
|---|---|---|
| POST | Send email |
| 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 |
Post formData using javascript from bootstrap-form