Mavericks, XAMPP and Sendmail Oh My!

I develop web applications on my MacBook Pro.  I’ve recently upgraded to Mavericks and changed over from MAMP to XAMPP.  One thing that we all have to do at some point is create email notifications.  Whether that takes the form of a forgot password link, a verify email address link, or some other activity notification, typically a local development server install like XAMPP (on Mac) does’t do email out of the box.

If you search around, you’ll find a lot of differing ways to get XAMPP to do this.  I messed around with this for quite sometime, and was able to get a configuration that worked for me.

One caveat – you need to have a real live SMPT server somewhere.  I happen to be located on a college campus, and all email leaving the campus must run through that, so I’ve set up my machine to use that host.  The problem with this is – if I’m off campus, I actually have to VPN in, to send email.  So, this still isn’t perfect but its working for me at this point in time.  I’ll post back, when I have an independent solution setup, or if you have one, please feel free to leave a link in the comments, or even better, spell it out in the comments.

I got my start on this quest here – http://stackoverflow.com/questions/15965376/how-to-configure-xampp-to-send-mail-from-localhost The kicker with this first solution is that XAMPP for OSX doesn’t come with sendmail, so the part about editing sendmail.ini was useless, which essentially makes the post mostly useless to me and other mac users.

After digging around I managed to set up something that was crazy simple.

First back up the file we’ll edit –

cp /etc/postfix/main.cf  /etc/postfix/main_orig.cf

then edit it –

sudo vi /etc/postfix/main.cf

and set

relayhost = [smtp.theserver.edu]

you may be tempted to edit myhostname, or mydomain but just leave them commented out.

save the file

Back up your php.ini file –

cp /Applications/XAMPP/etc/php.ini  /Applications/XAMPP/etc/php_orig.ini

then edit it –

sudo vi /Applications/XAMPP/etc/php.ini

search for SMTP, it may be commented out, but change it to this –

SMTP=localhost

uncomment

smtp_port=25

then change

sendmail_path = /usr/sbin/sendmail -t -i

save the file

restart apache

and you should be able to send email.

I realized as I typed this that if the smtp server you’re using requires you to authenticate, you’ll need to do more postfix configuration.  Here is a link that walks you through setting up sendmail / postfix using Google’s smtp servers and authenticating with your gmail credentials

http://slashusr.wordpress.com/2012/02/14/enabling-postfix-for-outbound-relay-via-gmail-on-os-x-lion-11/

This would allow me to run my webapps locally and not have to VPN in to send email, which is preferable, so if I know me, and I do, I’ll probably go through this when I have some more time.

Whatever you decide, good luck.

 

Code it right
theCodeDog
theCodeDog

posted in PHP by Jonathan

Follow comments via the RSS Feed | Leave a comment | Trackback URL

Leave Your Comment

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org