Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to test some web code and am running it on local host. How does one setup email for localhost so the code can use php message functions to send emails?

If I need to get some web hosted space somewhere and use that mail server for emailing from localhost, how do I set this up?

share|improve this question
1  
Would help to know what OS you are using... –  ck. Jun 9 '12 at 16:24
    
OSX, running mamp. –  Helium3 Jun 9 '12 at 16:27
1  
There have been eight major releases of OS X over more than a decade. Please be more specific. –  Daniel Beck Jun 9 '12 at 16:35
add comment

1 Answer

Mac OS X 10.5 and 10.6 come with a mail-sending program called postfix, but it is not turned on by default. This might work with 10.7, but I have not looked into that.

If you just want to send all of your outgoing mail to some relay server, like the SMTP server of your Internet service provider, you usually need to have a host name for the computer that is sending the mail. This configuration is for a server that is not being used to receive mail.

Open Terminal and enter the following commands, each on a single line. After the first command you will be prompted for your password. (Oh, you need to be logged on as a user with administrative privileges.)

First, you want to set postfix to run when your computer tries to send mail:

% sudo launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist
% sudo defaults write /System/Library/LaunchDaemons/org.postfix.master OnDemand -bool true
% sudo launchctl load /System/Library/LaunchDaemons/org.postfix.master.plist

Next, you want to tell postfix what the host name of the computer is:

% sudo postconf -e myhostname=<host-name-of-computer>

Next, tell postfix what SMTP server to use to send email:

% sudo postconf -e relayhost=<your-isp's-smtp-server>

This works for me because my ISP does not require authentication to use their SMTP server. They only require that the traffic be coming from their network.

If the SMTP server you are using requires authentication, there are a few extra steps:

% sudo echo <you-isp's-smtp-server> <username>:<password> >> /etc/postfix/sasl_passwd
% sudo postconf -e smtp_sasl_auth_enable=yes
% sudo postconf -e smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd

At this point, if postfix tries to send email to someone@<host-name-of-computer>, the email will be delivered locally. If your email for this host name is handled by some other server, tell postfix that this is not the final destination for email sent to that host name:

% sudo postconf -e mydestination=localhost

I used the following specifically for my environment:

% sudo postconf -e myhostname=subtlecoolness.com
% sudo postconf -e relayhost=smtp-server.austin.rr.com

There! You should now be running postfix and your web server will send emails!

(I wrote a blog post about this a long time ago.)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.