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/
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
.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;
}
}