Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gabrielagodek/easymail
PHP mail sender with MySQL database
https://github.com/gabrielagodek/easymail
crud email-sender mysql php
Last synced: about 2 hours ago
JSON representation
PHP mail sender with MySQL database
- Host: GitHub
- URL: https://github.com/gabrielagodek/easymail
- Owner: GabrielaGodek
- Created: 2024-01-02T15:19:31.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-01-16T20:08:37.000Z (10 months ago)
- Last Synced: 2024-01-17T04:27:28.515Z (10 months ago)
- Topics: crud, email-sender, mysql, php
- Language: PHP
- Homepage:
- Size: 342 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# EasyMail
The application allows selecting customer groups from the database and sending emails with dynamic values. Secured against XSS, SQL Injection, and Path Traversal through input validation and routing. This documentation outlines the functionality and implementation details of a PHP program designed to send emails with MySQL integration. The program involves three tables in the database: `users`, `categories`, and `users_categories`.## Installation
1. Clone this repo: `https://github.com/GabrielaGodek/EasyMail.git`.
2. Open XAMPP and run `Apache Web Server` and `MySQL Database`.
3. Open an type in the browser `localhost/phpmyadmin`.
4. Upload `easymail.sql` from src/db folder.
5. In the EasyMail folder install dependencies `composer install`.
6. Open `http://localhost/path_to/EasyMail/index` at your browser.## Routing
The application uses a simple routing system. The main entry point is `http://localhost/path_to/EasyMail/index`, and the different actions can be accessed by appending appropriate routes. For example:
- `http://localhost/path_to/EasyMail/form` for the "Send message" action.
- `http://localhost/path_to/EasyMail/users` for viewing all users.
- `http://localhost/path_to/EasyMail/categories` for viewing all categories.## Usage
1. Choose the action:
1. Send message.
2. View all users
3. View all categories### Send message action
1. Select category from dropdown menu.
2. Input the subject, alt message and message.
3. Click "Send" to dispatch the message to users associated with the selected category.### Additional information
1. For `cat_1` there are two suitable users.
2. For `cat_2` and `cat_3` there is only one.## SQL Operations
All functions can be found in `/src/db/db_conn.php`### Get users by category
```phpfunction getUsersByCategory($conn, $cat)
{
$cat = intval($cat);$categoryQuery = "SELECT user_id FROM `user_categories` WHERE category_id=?";
$categoryStmt = $conn->prepare($categoryQuery);
$categoryStmt->bind_param("i", $cat);
$categoryStmt->execute();
$categoryResult = $categoryStmt->get_result();if (!$categoryResult) {
die("Error fetching users by category: " . $conn->error);
}$userIDs = $categoryResult->fetch_all(MYSQLI_ASSOC);
if (empty($userIDs)) {
return [];
}$userIDs = array_column($userIDs, 'user_id');
$placeholders = implode(',', array_fill(0, count($userIDs), '?'));$userQuery = empty($placeholders) ? "SELECT * FROM `users`" : "SELECT * FROM `users` WHERE user_id IN ($placeholders)";
$userStmt = $conn->prepare($userQuery);if (!empty($placeholders)) {
$userStmt->bind_param(str_repeat("i", count($userIDs)), ...$userIDs);
}$userStmt->execute();
$userResult = $userStmt->get_result();if (!$userResult) {
die("Error fetching users: " . $conn->error);
}return $userResult->fetch_all(MYSQLI_ASSOC);
}
```### Get all data
```php
function getAllData($conn, $tableName)
{
$sql = "SELECT * FROM `$tableName`";
$result = $conn->query($sql);if ($result) {
return $result->fetch_all(MYSQLI_ASSOC);
} else {
die("Error fetching $tableName: " . $conn->error);
}
}
```## Preview
![Preview](public/app_preview.png)