Change smtp port from 25 to 587?

My ISP blocked port 25 for sending emails with PHP and instead allowed using port 587 or 465. how to force the php mail function to use port 587 instead of the standard 25? BTW: I'm on OSX 10.6.6 using MAMP PRO

UPDATE: I tried changing the settings in php.ini to

[mail function] ; For Win32 only. SMTP = localhost smtp_port = 587 

As I am on a Mac, I don’t think this might be the solution for me, and it doesn’t work after I tried. this gives me the following error message.

 May 6 20:32:25 Ibrahim-Armars-MacBook-Pro postfix/smtp[2822]: connect to alt2.aspmx.l.google.com[74.125.159.27]:25: Operation timed out May 6 20:32:25 Ibrahim-Armars-MacBook-Pro postfix/smtp[2823]: connect to alt2.aspmx.l.google.com[74.125.159.27]:25: Operation timed out May 6 20:32:25 Ibrahim-Armars-MacBook-Pro postfix/smtp[2827]: connect to alt2.aspmx.l.google.com[74.125.159.27]:25: Operation timed out May 6 20:32:25 Ibrahim-Armars-MacBook-Pro postfix/smtp[2825]: connect to alt2.aspmx.l.google.com[74.125.159.27]:25: Operation timed out May 6 20:32:25 Ibrahim-Armars-MacBook-Pro postfix/smtp[2828]: connect to alt2.aspmx.l.google.com[74.125.159.27]:25: Operation timed out 

Do you see that it is still trying to connect through port 25? how to change it in mac?

+7
source share
5 answers

Changing smtp_port only affects how mail() interacts with the server specified in the SMTP configuration. It's not a problem. The problem is that:

  • You are using your local computer as an SMTP server - AND
  • Your ISP blocks the local SMTP server (postfix) from sending messages to Gmail

Read this topic first . It discusses the exact same issue. As a result, you must use a different mail server, preferably your ISP mail server. Which server and port does your ISP tell you to use for outgoing mail if you want to use your email services? You should be able to use this from your local PHP, just like an email client like Thundebird, and you will be able to send to Gmail.

+5
source

Set smtp_port = 587 to your php.ini. See http://php.net/manual/en/mail.configuration.php

EDIT

As AJ noted, this will not solve the problem if you use a local postfix or sendmail, which you do by specifying smtp = localhost . Instead, try setting it to the SMTP server address.

This can lead to the next problem if they also require authentication before allowing you to send mail, which many Internet service providers do. In this case, the Pear Mail package would be the best option. This, by the way, also allows you to specify the mail server and port in the script. From the documentation:

 $params["host"] - The server to connect. Default is localhost. $params["port"] - The port to connect. Default is 25. $params["auth"] - Whether or not to use SMTP authentication. Default is FALSE. $params["username"] - The username to use for SMTP authentication. $params["password"] - The password to use for SMTP authentication. 
+3
source

You can edit the php.ini file (if you have access) and set smtp_port = 587 or in your ini_set('smtp_port', 587) code ini_set('smtp_port', 587) .

+1
source

If you can, try overriding the smtp_port parameter with ini_set (). There should be something like this:

 ini_set('smtp_port', 587); 
0
source

For those of you who use MAMP and cannot send mail from the php mail () function because port 25 is blocked by ISP (in my case), here is some information for you. since OSX uses postfix to send emails, and if you plan on using an external smtp server like smtp.gmail.com, which I used here, this is what you should do. you need to configure Postfix to use Gmail as a relay host

a) Open MAMP and in postfix change the outgoing mail domain to smtp.gmail.com

b) open a terminal and enter sudo vi /etc/postfix/main.cf , this will ask the administrator password to enter it and it will open main.cf in the vi editor

c) press ctrl + f and go to the end of the file and move the cursor down one line and press a , now the editor will switch to insert mode to edit the file.

in main.cf add these settings

 relayhost = [smtp.gmail.com]:587 smtp_tls_security_level = verify #smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous 

press : wq to exit vim. Go back to the sudo vi /etc/postfix/sasl_passwd shell type and enter the following (replace your gmail address and gmail password):

 [smtp.gmail.com]:587 user@gmail.com :mypassword 

press again : wq to save and exit the file and run the following command

 sudo postmap /etc/postfix/sasl_passwd sudo postfix reload 

Hope this helps someone with the same issue that I am facing.

0
source

All Articles