MySQL Configuration
Database Creation
1- Log in to MySQL:
- Access your MySQL server using a client like MySQL Workbench, phpMyAdmin, or the command line.
mysql -u your_username -p
2- Create the Database:
- Run the following SQL command to create the newsletter database.
CREATE DATABASE newsletter;
Table Creation
1- Select the Database:
- Switch to the newsletter database.
USE newsletter;
2- Create subscribers Table:
- Execute the following SQL command to create the subscribers table
CREATE TABLE `subscribers` (
`id` int NOT NULL AUTO_INCREMENT,
`email` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`token` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
`is_confirmed` tinyint(1) DEFAULT '0',
`confirmed_at` timestamp NULL DEFAULT NULL,
`status` enum('pending','confirmed') COLLATE utf8mb4_general_ci DEFAULT 'pending',
`mailchimp_sync` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=78 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
PHP Configuration
Customizing the .env File
1- Mailchimp Configuration:
- Replace the placeholders with your Mailchimp API key and list ID.
# Mailchimp Configuration (replace with your own configuration without quotes)
MAILCHIMP_API_KEY=your_mailchimp_api_key
MAILCHIMP_LIST_ID=your_mailchimp_list_id
2- Database Configuration:
- Replace the placeholders with your database credentials.
# Database Configuration (replace with your own configuration without quotes)
DB_HOST=your_database_host
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password
DB_NAME=your_database_name
3- Email Configuration:
- Replace the placeholders with your SMTP server details and email credentials.
# Email Configuration (replace with your own configuration without quotes)
SMTP_HOST=your_smtp_host
SMTP_PORT=your_smtp_port
SMTP_USERNAME=your_smtp_username
SMTP_PASSWORD=your_smtp_password
FROM_EMAIL=your_from_email
FROM_NAME=your_from_name
RECIPIENTS_PRIMARY=your_primary_recipient_email
Customizing the config.php File
1- Enable or Disable Features:
- Set the following options to true or false based on your needs.
<?php
require_once 'load_env.php';
return [
// Enable or disable saving subscriptions to the local database
'save_to_database' => true,
// Enable or disable saving subscriptions to Mailchimp
'save_to_mailchimp' => true,
// Enable or disable welcome email
'send_welcome_email' => true,
],
];
?>
2- Mailchimp Configuration:
- Ensure the Mailchimp API key and list ID are correctly set in the .env file. The config.php file will automatically use these values.
<?php
require_once 'load_env.php';
return [
// Mailchimp API key (replace with your own key in .env file)
'mailchimp_api_key' => getenv('MAILCHIMP_API_KEY'),
// Mailchimp list ID (replace with your own list ID in .env file)
'mailchimp_list_id' => getenv('MAILCHIMP_LIST_ID'),
],
];
?>
3- Database Configuration:
- Ensure the database credentials are correctly set in the .env file. The config.php file will automatically use these values.
<?php
require_once 'load_env.php';
return [
// Database configuration (replace with your own configuration in .env file)
'database' => [
'host' => getenv('DB_HOST'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'dbname' => getenv('DB_NAME'),
],
];
?>
4- Email Configuration:
- Ensure the SMTP and email details are correctly set in the .env file. The config.php file will automatically use these values.
<?php
require_once 'load_env.php';
return [
// Email configuration (replace with your own configuration in .env file)
'email' => [
'smtp_host' => getenv('SMTP_HOST'),
'smtp_port' => getenv('SMTP_PORT'),
'smtp_username' => getenv('SMTP_USERNAME'),
'smtp_password' => getenv('SMTP_PASSWORD'),
'from_email' => getenv('FROM_EMAIL'),
'from_name' => getenv('FROM_NAME'),
],
'recipients' => [
'primary' => getenv('RECIPIENTS_PRIMARY'),
],
];
?>
Testing Configuration with env-test.php
1- Purpose:
- This script tests and displays the values of the Mailchimp API key, database host, SMTP host, SMTP username, SMTP password, and primary recipient email.
2- How It Works:
- It loads the config.php file and outputs the values using echo.
3- Customization:
- No customization is needed for this file. It automatically reads the configuration from config.php.
4- Usage:
- Run this script in your browser or command line to verify the configuration values.
