You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel注册页面触发Connection to tcp://smtp.mailtrap.io:587 Timed Out错误如何解决?

Fixing "Connection to tcp://smtp.mailtrap.io:587 Timed Out" in Laravel Registration

Hey there, let's work through this SMTP timeout issue you're hitting when trying to register users in your Laravel app. This is a common snag, so here are the step-by-step fixes to get your email flow back on track:

1. First, Test Network Connectivity

Before diving into configs, confirm your server/local machine can actually reach Mailtrap's SMTP server. Run one of these commands in your terminal:

  • telnet smtp.mailtrap.io 587
  • nc -zv smtp.mailtrap.io 587

If either command times out, the problem is network-level:

  • Try switching to a different network (like a mobile hotspot if you're on local dev) to rule out your ISP/office network blocking port 587.
  • Check if your firewall (local or server-side, e.g., UFW, iptables) is blocking outbound traffic to port 587.

2. Double-Check Your Laravel Mail Configs

It's easy to mistype a credential—head to your .env file and verify these settings match exactly what's in your Mailtrap dashboard:

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=587 # Or try 2525 if 587 fails (Mailtrap supports both)
MAIL_USERNAME=your_mailtrap_inbox_username
MAIL_PASSWORD=your_mailtrap_inbox_password
MAIL_ENCRYPTION=tls # Important: Use TLS for port 587, not SSL
MAIL_FROM_ADDRESS=test@example.com # Any valid-looking email works for testing

After updating, clear Laravel's config cache to apply changes:

php artisan config:clear

3. Verify Your Mailtrap Account Status

Log into your Mailtrap dashboard to check:

  • Your inbox is active and hasn't been suspended.
  • You haven't exceeded your monthly email limit (free plans have caps).
  • There are no ongoing service maintenance notices affecting SMTP access.

4. Increase Timeout Limits

Laravel's default SMTP timeout might be too short for slow network connections. Open config/mail.php, find the smtp array, and add these lines:

'smtp' => [
    'transport' => 'smtp',
    'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
    'port' => env('MAIL_PORT', 587),
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'timeout' => 60, // Extend timeout to 60 seconds
    'connection_timeout' => 60, // Extend connection timeout
    'auth_mode' => null,
],

Again, clear the config cache after making this change:

php artisan config:clear

5. Rule Out Proxy or Firewall Restrictions

  • If you're behind a corporate proxy, ensure your Laravel app is configured to use it for outbound SMTP requests. Alternatively, test without the proxy to see if that resolves the timeout.
  • For server setups, check if your hosting provider blocks outbound SMTP traffic (some shared hosts restrict port 587). If so, use Mailtrap's 2525 port instead, or reach out to your host to unblock the port.

6. Fallback to Log Driver for Testing

If you just need to confirm your registration logic works (without sending actual emails temporarily), switch your mail driver to log:

MAIL_MAILER=log

This will write all outgoing emails to storage/logs/laravel.log so you can verify the registration flow isn't broken, while you troubleshoot the SMTP issue separately.


内容的提问来源于stack exchange,提问作者Okoye Kenneth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:39:23