This project is a simple PHP application that allows users to register their information, store it in an SQLite database, and send a confirmation email using PHPMailer. Before running the main application, you need to create the database by running a separate script.
- Stores user registration information in an SQLite database
- Sends a confirmation email with the registered details
- Securely uses Gmail SMTP for sending emails
- PHP 7.4 or higher
- Composer
- SQLite
- A Gmail account
git clone https://github.com/amircliper/mail-sender-php.git
cd your-repo-name
Use Composer to install the necessary dependencies:
composer install
Before running the main API script, you need to create the SQLite database by running the create-database.php
script.
php create-database.php
You need to generate an application-specific password for your Gmail account to securely send emails. Follow these steps:
- Go to Google App Passwords
- Generate a new app password and save it.
Open the api.php
file and replace the $GLOBALS['mail_address']
and $GLOBALS['mail_password']
with your Gmail address and the generated app password.
$GLOBALS['mail_address'] = '[email protected]';
$GLOBALS['mail_password'] = 'your-app-password';
Once you have set up everything, you can start using the API.
You can use PHP's built-in server to run the application locally.
php -S localhost:8000
Send a POST request to the API endpoint with the user's details:
name
: User's namephone
: User's phone numberemail
: User's email addressdescription
: Additional information
Example using curl
:
curl -X POST http://localhost:8000/api.php \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"phone": "123-456-7890",
"email": "[email protected]",
"description": "New user registration"
}'
The API will respond with a JSON object indicating the status of the operation.
- Success with email sent:
{
"status": "success",
"message": "User registered and email sent"
}
- Success without email sent:
{
"status": "success",
"message": "User registered but email not sent",
"error": "Detailed error message"
}
- Error:
{
"status": "error",
"message": "Error message"
}
api.php
: Main API file to handle user registration and sending confirmation emails.create-database.php
: Script to create the SQLite database.composer.json
: Composer configuration file.
If you encounter issues with sending emails, ensure that:
- You have enabled "Less secure app access" in your Gmail account settings.
- You are using the correct app password generated from the Google App Passwords page.
For any issues related to the database, ensure that the create-database.php
script was executed successfully and that the database file users.db
is in the correct location.
If you would like to contribute to this project, please fork the repository and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.