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

Laravel本地Homestead用Mailtrap发件时SMTP连接超时#110问题求助

Fixing Laravel SMTP Connection Timout (#110) with Mailtrap on Homestead

Hey there, let's work through this frustrating connection timeout issue you're hitting when trying to send emails via Mailtrap on your Homestead server. I've dealt with similar headaches before, so here's a step-by-step breakdown of what to check and fix:

  • Double-check your Mailtrap SMTP configuration in .env
    It's easy to mistype credentials or settings. Make sure your .env has the exact values from your Mailtrap inbox page:

    MAIL_MAILER=smtp
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=your_mailtrap_inbox_username
    MAIL_PASSWORD=your_mailtrap_inbox_password
    MAIL_ENCRYPTION=null
    MAIL_FROM_ADDRESS=your-test-email@example.com
    MAIL_FROM_NAME="${APP_NAME}"
    

    Note: For port 2525, MAIL_ENCRYPTION should be set to null (not an empty string or "tls"). If you switch to port 587 or 465 later, update encryption to tls or ssl respectively.

  • Test connectivity from Homestead to Mailtrap
    SSH into your Homestead server and run these commands to verify the server can reach Mailtrap's SMTP endpoint:

    1. Ping to check DNS resolution:
      ping smtp.mailtrap.io
      If this fails, your Homestead instance has DNS issues. Update your server's DNS to use Google (8.8.8.8) or Cloudflare (1.1.1.1) in /etc/resolv.conf.
    2. Telnet to test port access:
      telnet smtp.mailtrap.io 2525
      If you get a timeout here, the problem is network-level—even if your local firewall allows 2525, Homestead might be blocked or lack outbound access.
  • Verify Homestead's internal firewall rules
    Even if your local firewall is clear, check if Homestead's internal firewall (ufw/iptables) is blocking outbound traffic on 2525:

    • Check ufw status: sudo ufw status
    • If port 2525 isn't allowed, add the rule: sudo ufw allow out 2525/tcp
    • For iptables, list rules with sudo iptables -L and add an allow rule if needed.
  • Clear Laravel's configuration cache
    Sometimes Laravel caches old config values even after you update .env. Run these commands to reset the cache:

    php artisan config:clear
    php artisan cache:clear
    

    Then try sending the test email again.

  • Try alternative Mailtrap ports
    Some server environments restrict port 2525. Switch to Mailtrap's encrypted ports and update your .env:

    • For TLS (port 587):
      MAIL_PORT=587
      MAIL_ENCRYPTION=tls
      
    • For SSL (port 465):
      MAIL_PORT=465
      MAIL_ENCRYPTION=ssl
      
  • Confirm Homestead has outbound internet access
    If none of the above works, check if your Homestead instance can reach external websites at all:
    curl https://google.com
    If this fails, your Homestead network setup (like NAT mode, port forwarding, or host machine network) has an issue. Verify your Homestead.yaml network settings and restart the instance with homestead reload --provision.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 09:21:13