Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TerrePorter's avatar

unable to sent mail using 127.0.0.1

Hello, I have a odd problem. I have my vps server and I’m trying to configure mail to send through my Laravel site. I’ve verified the username and password are correct, I can connect to the IMAP server at least. The problem is no matter what port I use I get a timeout error. 127.0.0.1 works for the database but it seems not to work for the smtp setup. I’ve checked the firewall and the services are set in there to be allowed. I’ve tried to use telnet to connect to the ports but it just says connected then nothing else. Anyone have any ideas on what I might try?

0 likes
4 replies
LaryAI's avatar
Level 58

It sounds like you're trying to send mail from your Laravel application using SMTP settings that point to 127.0.0.1, which is the loopback address for the local machine. If your mail server is not running on the same VPS as your Laravel application, 127.0.0.1 will not work for SMTP. You need to use the actual IP address or hostname of your mail server.

Here are a few steps you can take to troubleshoot and resolve the issue:

  1. Verify Mail Server Configuration: Ensure that your mail server is correctly configured to accept SMTP connections. If you're using a third-party mail service, make sure you have the correct server address.

  2. Check Ports: Common SMTP ports are 25, 465 (for SSL), and 587 (for TLS). Make sure that the port you are trying to use is open and listening on your mail server.

  3. Firewall Settings: Double-check your firewall settings to ensure that the port you're trying to use for SMTP is not being blocked.

  4. Laravel .env Settings: Make sure your .env file in Laravel has the correct settings for mail. Here's an example configuration:

MAIL_MAILER=smtp
MAIL_HOST=your.mailserver.com
MAIL_PORT=587
MAIL_USERNAME=yourusername
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"

Replace your.mailserver.com, yourusername, yourpassword, and [email protected] with your actual mail server details.

  1. Test Connection with Telnet: You mentioned that you tried using telnet. When you connect with telnet, you should be able to issue SMTP commands to test the connection. Here's an example of how to test port 587:
telnet your.mailserver.com 587

After connecting, you should see a greeting message from the SMTP server. If you don't, there may be an issue with the SMTP service or your connection to it.

  1. Check Mail Server Logs: If you have access to the mail server, check the logs to see if there are any error messages that can give you a clue as to what's going wrong.

  2. Use Laravel's Log Driver for Mail: As a temporary measure, you can set the mail driver to log in your .env file to see if Laravel is handling the mail correctly:

MAIL_MAILER=log

This will write all email output to your Laravel log files instead of sending them, which can help you debug the application side of things.

  1. Laravel Mail Configuration: Ensure that your config/mail.php file is set up to use the environment variables from your .env file.

If you've gone through all these steps and are still facing issues, you may want to reach out to your VPS provider or the support for your mail server to see if they can assist you further.

Snapey's avatar

You need to send via SMTP, so anything imap related is not relevant.

So, you have a mail server that is setup for use by your application? Any you have created SPF record to say that this server can send on your behalf?

TerrePorter's avatar

yes, postfix i beleive. I've got the DNS all set up and it resovles. But event it it didnt work the localhost can't connect for some reason.

TerrePorter's avatar

@snapey I got it working. The problem was i had a invalid map file or something that caused the smtpd to fail to launch.

Please or to participate in this conversation.