My ISP have blocked port 25 for sending mails from PHP, and instead have allowed port 587 or 465 to be used. how do i force php mail function to use port 587 instead of defa
For those of you using MAMP and not able to send the mail from php mail() function because of port 25 being blocked by ISP (in my case) here is some information for you to solve it. as OSX uses postfix to send mails and if you plan to use external smtp server like smtp.gmail.com which i used here is what you should be doing. you need to configure Postfix to use Gmail as a relay host
a) Open MAMP and in postfix change the domain of outgoing mail to smtp.gmail.com
b) open terminal and type
sudo vi /etc/postfix/main.cfthis will ask for your admin password enter it and it will open main.cf in vi editorc) press ctrl+f and come to the end of the file and bring the cursor one line down from the end and press a , the editor will now switch to insert mode to edit the file.
in main.cf append this 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. Back in the shell type sudo vi /etc/postfix/sasl_passwd and enter the following (substitute your gmail address and gmail password):
[smtp.gmail.com]:587 user@gmail.com:mypassword
again press :wq to save and quit the file, and run the following command
sudo postmap /etc/postfix/sasl_passwd
sudo postfix reload
hope this helps someone with the same problem which i faced.