A comprehensive PHP implementation for testing Mailchimp's Mandrill Transactional API with both command-line scripts and a web-based UI.
- PHP 7.4+ (8.0+ recommended)
- Composer
- A Mandrill API key from Mailchimp
# Clone or navigate to the project
cd Transactional-PHP-Samples
# Install dependencies
cd scripts
composer install
# Configure environment variables
cp env.example .env
# Edit .env with your Mandrill API key and email settingsStart the web server:
cd scripts
php -S localhost:8000Then open your browser to:
http://localhost:8000
The web UI provides:
- ✨ Beautiful, modern interface
- 📋 Dropdown menu to select email operations
- 🎨 Dynamic forms and previews
- ✅ Instant feedback on email sending
Run individual PHP scripts directly:
cd scripts
# Send a basic email
php email_with_single_recipient.php
# Send with merge tags
php email_with_merge_tags.php
# Send with attachments
php email_with_attachments.php
# Send using a template
php email_with_template.php
# Kitchen sink - all features
php kitchen_sink_email.phpSend a basic email with subject, body, and recipient.
Personalize emails with dynamic content using merge variables.
Attach files (PDF, CSV, images, etc.) to your emails.
Use pre-created Mandrill templates for consistent branding.
Comprehensive example using all features combined.
Transactional-PHP-Samples/
├── public/
│ ├── index.php # Web UI entry point
│ └── styles.css # Web UI styles
├── scripts/
│ ├── app.php # Web UI application router
│ ├── composer.json # PHP dependencies
│ ├── config.php # Configuration loader
│ ├── .env # Your configuration (create from env.example)
│ ├── email_with_single_recipient.php
│ ├── email_with_merge_tags.php
│ ├── email_with_attachments.php
│ ├── email_with_template.php
│ ├── kitchen_sink_email.php
│ └── create_template.php
├── views/
│ └── index.php # Web UI template
├── use-cases/ # Detailed documentation for each use case
├── WEB_UI_GUIDE.md # Web UI documentation
└── README.md # This file
Create a .env file in the scripts directory:
MANDRILL_API_KEY=your_mandrill_api_key_here
DEFAULT_FROM_EMAIL=sender@yourdomain.com
DEFAULT_FROM_NAME="Your Name"
DEFAULT_TO_EMAIL=recipient@example.com
DEFAULT_TO_NAME="Recipient Name"Important: Always quote values that contain spaces or special characters. The PHP dotenv library strictly enforces this requirement.
Each script demonstrates a specific use case:
| Script | Description | Documentation |
|---|---|---|
email_with_single_recipient.php |
Basic email sending | Docs |
email_with_merge_tags.php |
Personalized emails | Docs |
email_with_attachments.php |
Emails with files | Docs |
email_with_template.php |
Template-based emails | Docs |
kitchen_sink_email.php |
All features combined | Docs |
# If you see: "Could not find package mailchimp/transactional"
composer install
# If composer version mismatch:
rm composer.lock
composer installThe SDK requires PHP 7.2+. Check your version:
php -v# Port already in use:
lsof -ti:8000 | xargs kill -9
# Then restart:
php -S localhost:8000.env file or API keys to version control!
The .env file is in .gitignore by default. Keep your API keys secure.
See the LICENSE file in the root directory.
cd scripts
composer install
php -S localhost:8000
# Open http://localhost:8000cd scripts
composer install
php email_with_single_recipient.phpReady to send your first email? 🚀
Choose your preferred method above and get started!
Happy emailing! 📧✨