Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test emails locally with mamp

First thing first, i'm totally new to this kind of localhost server setup and i've been spending the last couple of days trying to figure this out, but with no luck.

I'm developing a php website with an email form.

I'm on a MAC using codekit and MAMP FREE and everything works fine. Now my question is, is it possible to test the email that should be sent from the form locally?

I've tried a lot of examples, like uncommenting the [mail function] bit in php.ini file, installing 3rd parties app like fakeSMTP and MockSMTP but absolutely nothing worked. The mailto() code should work, as when i debug it no error are thrown

Is it possible to do that or not? anyone who knows how to properly set this up or that can point me to a dumb-proof guide?

like image 446
Nick Avatar asked Jun 03 '15 09:06

Nick


1 Answers

Ok, if someone is interested in this, i finally found a way to make it work.

I'm gonna explain it here in a detailed step-to-step tutorial.

Requirements

  • MAMP pro
  • working gmail account cause you actually need to login to the email account inbox (I made it work using gmail, not sure about others)

Step-by-step tutorial

  • First thing first, you need to install mamp pro. In the postfix tab, add gmail.com as domain for outgoing emails and then click the button "Use this data"
  • After this is done, you want to open the terminal and type in sudo nano /System/Library/LaunchDaemons/org.postfix.master.plist (this will allow you to edit the org.postfix.master.plist file otherwise not editable.

  • The only edit that you want to do is adding at the top, right after <dict>, this line <key>Disabled</key>

  • Now close the terminal and restart your mac.

  • After the restart, open MAMP and go to the website you want to test the emails and submit the email.

NB: It is important that you use a working account for the to section of the mail() function, otherwise you won't be able to test the emails!

  • Nothing happens in the front end, but if you now open MAMP -> postFix tab, at the botto you can see the path of the log file and an arrow, click on the arrow and it will display a log message.
  • Scroll down till the last line, where you should find something saying status:sent. This status sent means that the email has been sent and that the local test worked as expected

What's next?

  • Ok, now login to your gmail account (the one you used for the to section in your mail() function
  • Go to spam and you should see the email that you just sent from your local machine.

I'm using it, and it is actually working nicely.

Quick tip

After this, I made a couple of adjustment in my gmail inbox, adding an alias and a filter. I'm gonna explain this as well as it may be useful for a beginner

  • Login to you gmail account from your pc
  • go to the top right cog icon and then go to settings
  • In accounts and import, add another account to use as alias (in my case is [myemailaddress][email protected])
  • Once this is done, go to filters tab
  • Add a new filter and set it up to affect all the emails to [myemailaddress][email protected]
  • Click continue to go to the next screen
  • Now, here you can actually tweak it as you prefer, but the important thing is to check never send it to spam so that you will always be able to see the emails that you'd like to test. (my personal setup is to skip the inbox (archive) and add a specific label)

That's it! hope this is clear enough and that it will help some of you.

like image 75
Nick Avatar answered Nov 08 '22 12:11

Nick