Automated Email
1.0.0
This project is a simple Email Scheduling and Notification System built using PHP, MySQL, and PHPMailer. Users can schedule emails to be sent at a future date and time. The system checks for pending emails periodically using a cron job and sends them automatically.
Before running the project, make sure you have the following installed:
git clone https://github.com/yourusername/email-scheduling-app.git
cd email-scheduling-app
composer install
DB_HOST=your_db_host
DB_NAME=your_db_name
DB_USER=your_db_user
DB_PASSWORD=your_db_password
SMTP_HOST=smtp.yourmailprovider.com
SMTP_PORT=587
[email protected]
SMTP_PASS=your_email_password
CREATE DATABASE email_scheduler;
USE email_scheduler;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL
);
CREATE TABLE scheduled_emails (
email_id INT AUTO_INCREMENT PRIMARY KEY,
recipient_email VARCHAR(255) NOT NULL,
subject VARCHAR(255) NOT NULL,
body TEXT NOT NULL,
scheduled_time DATETIME NOT NULL,
status ENUM('pending', 'sent', 'failed') DEFAULT 'pending',
attempts INT DEFAULT 0
);
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use DotenvDotenv;
$dotenv = Dotenv::createImmutable(__DIR__ . '/../');
$dotenv->load();
class Dbh {
protected function connect() {
$dsn = 'mysql:host=' . $_ENV['DB_HOST'] . ';dbname=' . $_ENV['DB_NAME'];
try {
$pdo = new PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASSWORD']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
} catch (PDOException $e) {
die('Connection failed: ' . $e->getMessage());
}
}
}
php -S localhost:8000
crontab -e
* * * * * /usr/bin/php /path/to/project/includes/send_email.inc.php
project-root/
│
├── .env
├── .gitignore
├── composer.json
├── composer.lock
├── config.php
├── index.php
├── project.sql
├── README.md
│
├── config/
│ └── db.php
│
├── controllers/
│ ├── login-contr.php
│ ├── schedule_email-contr.php
│ └── signup-contr.php
│
├── includes/
│ ├── login.inc.php
│ ├── logout.inc.php
│ ├── schedule_email.inc.php
│ ├── send_email.inc.php
│ └── signup.inc.php
│
├── models/
│ ├── login-model.php
│ ├── schedule_email-model.php
│ └── signup-model.php
│
├── cron/
│ └── send_email.php
│
└── views/
├── dashboard.php
├── login.php
├── schedule_email.php
└── signup.php
Contributions are welcome! Feel free to submit a pull request or open an issue.