Skip to content

Instantly share code, notes, and snippets.

@tranchausky
Last active June 3, 2025 04:14
Show Gist options
  • Save tranchausky/555917560bb4e0c377a067b44b872f25 to your computer and use it in GitHub Desktop.
Save tranchausky/555917560bb4e0c377a067b44b872f25 to your computer and use it in GitHub Desktop.
Document build mailhog for docker and test

1. Install docker 1

docker-compose.yml

services:
  mailhog:
    image: mailhog/mailhog
    container_name: mailhog
    ports:
      - "8025:8025"
      - "1025:1025"

Run and remove

docker-compose down
docker-compose up -d

Access web, Open MailHog at
http://127.0.0.1:8025/
http://localhost:8025
http://192.168.1.157:8025/

2. Run in xampp

create file mail-test.php

<?php
$to = "[email protected]";
$subject = "Test Email from PHP";
$message = "This is a test email sent using PHP and MailHog.";
$headers = "From: [email protected]";

if (mail($to, $subject, $message, $headers)) {
    echo "Email sent successfully!";
} else {
    echo "Failed to send email.";
}
?>

xampp/php/php.ini

[mail function]
SMTP=127.0.0.1
smtp_port=1025

After restart Apache XAMPP Control Panel

Access web http://localhost/mail-test.php

3. For LARAVEL

.env config

MAIL_MAILER=smtp
MAIL_HOST=192.168.1.157 #ip PC of docker
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

At a controller HomeController

use Illuminate\Support\Facades\Mail;
class HomeController extends BaseController{
	public function index(Request $request)
	{
		Mail::raw('This is a test email from Laravel to MailHog.', function ($message) {
		$message->to('[email protected]')
			->subject('Test Laravel Email');
	});

	//return 'Email sent!';
	die;
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment