Automated Email
1.0.0
該專案是使用PHP 、 MySQL和PHPMailer建立的簡單電子郵件排程和通知系統。使用者可以安排在未來的日期和時間發送電子郵件。系統使用 cron 作業定期檢查待處理的電子郵件並自動傳送它們。
在運行專案之前,請確保您已安裝以下軟體:
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 Dotenv Dotenv ;
$ 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
歡迎貢獻!請隨意提交拉取請求或提出問題。